Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to create a cubemap rendertarget #176

Open
X-skyer opened this issue Jan 18, 2021 · 2 comments
Open

how to create a cubemap rendertarget #176

X-skyer opened this issue Jan 18, 2021 · 2 comments

Comments

@X-skyer
Copy link

X-skyer commented Jan 18, 2021

Hi, I want to render to a cubemap, I use this attachments to create cube rendertarget but seems not working.

attachments = [ { internalFormat: Constants.RGBA, format: Constants.RGBA, type: type, min: this.minFilter, mag: this.maxFilter, wrap: Constants.CLAMP_TO_EDGE, target: Constants.TEXTURE_CUBE_MAP } ];

@greggman
Copy link
Owner

you can only render to one face of a cube map at a time so your target should be one of the faces which means you need to create the cubemap separately. Example

const width = 2;
const height = 2;

// make an empty cubemap
const tex = twgl.createTexture(gl, {
  target: gl.TEXTURE_CUBE_MAP,
  width,
  height,
  minMag: gl.LINEAR,
});

const faces = [
  gl.TEXTURE_CUBE_MAP_POSITIVE_X,
  gl.TEXTURE_CUBE_MAP_NEGATIVE_X,
  gl.TEXTURE_CUBE_MAP_POSITIVE_Y,
  gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,
  gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
  gl.TEXTURE_CUBE_MAP_NEGATIVE_Z,
];

// make a framebuffer info for each face
const fbis = faces.map(target => twgl.createFramebufferInfo(gl, [{ attachment: tex, target }], width, height));

Working example: https://jsgist.org/?src=58469d1247b4a347b60d6efd535b981f

@X-skyer
Copy link
Author

X-skyer commented Mar 26, 2021

thanks! but got one question: If I want to get the depth buffer texture of the cubemap rendertarget, these buffers will not be a cubetexture, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants