PDA

View Full Version : how to render to 3d texture or 2d texture array



shapeare
06-12-2011, 03:13 AM
I want to save the rendering results to a 2D texture array, but it seems that I cannot use index to specify which slice I render into. How can I achieve that?

In addition, how to render multiple results to a 3D texture?

Alfonse Reinheart
06-12-2011, 03:26 AM
I want to save the rendering results to a 2D texture array, but it seems that I cannot use index to specify which slice I render into. How can I achieve that?

What exactly do you mean?

Fragment shaders have a specific number of per-fragment outputs, each of which is farmed to a specific bound render target by the glDrawBuffers table. Are you trying to use those outputs to render to multiple layers in an array?

Otherwise, your choice (besides rendering to each array layer in turn) is using layered rendering. This requires using a Geometry shader to specify which layer each primitive that it outputs gets rendered to. This naturally requires writing a lot of primitives.

shapeare
06-12-2011, 08:25 PM
I want to save the rendering results to a 2D texture array, but it seems that I cannot use index to specify which slice I render into. How can I achieve that?

What exactly do you mean?

Fragment shaders have a specific number of per-fragment outputs, each of which is farmed to a specific bound render target by the glDrawBuffers table. Are you trying to use those outputs to render to multiple layers in an array?

Otherwise, your choice (besides rendering to each array layer in turn) is using layered rendering. This requires using a Geometry shader to specify which layer each primitive that it outputs gets rendered to. This naturally requires writing a lot of primitives.

I want to use the uniform sampler3D in Nvidia Cg' vertex shader, so I have to send either a 3d texture or a 2d texture array to the vertex shader.

And I rendered to the framebuffer 64 times before that, but I have difficulty in saving the 64 separately rendered results to a 2d texture array or a 3d texture.

Alfonse Reinheart
06-12-2011, 10:58 PM
And I rendered to the framebuffer 64 times before that, but I have difficulty in saving the 64 separately rendered results to a 2d texture array or a 3d texture.

OK. So... what are those problems? What exactly are you doing? Are you doing layered rendering with a geometry shader? Are you binding each layer to the framebuffer and doing a separate rendering with each?

shapeare
06-12-2011, 11:17 PM
And I rendered to the framebuffer 64 times before that, but I have difficulty in saving the 64 separately rendered results to a 2d texture array or a 3d texture.

OK. So... what are those problems? What exactly are you doing? Are you doing layered rendering with a geometry shader? Are you binding each layer to the framebuffer and doing a separate rendering with each?

I am trying to implement a hair rendering algorithm. I rendered 64 opacity maps in 64 light sources' view space, and saved them into 64 2D textures respectively. In the following rendering pass, I want to fetch the opacity value from these textures, but it is excruciating to write "uniform sampler2D" in the vertex shader 64 times, so I am wondering if I can save the opacity maps as a 2d texture array, then use as a uniform sampler3D in the shader, or directly save as a 3d texture. My question is how to save the 64 opacity maps into a texture array rather than different 2d textures.

Thank you very much.

Alfonse Reinheart
06-12-2011, 11:45 PM
it is excruciating to write "uniform sampler2D" in the vertex shader 64 times

To be fair, it wouldn't work anyway, since the number of textures you can get in any single shader stage maxes out at 16.


I am wondering if I can save the opacity maps as a 2d texture array, then use as a uniform sampler3D in the shader, or directly save as a 3d texture.

Yes you can.

You create a 2D array texture of the appropriate size. For each rendering, you bind a particular layer of that texture with glFramebufferTextureLayer (http://www.opengl.org/wiki/Framebuffer_Object#Attaching_Images), specifying the particular array index as the layer parameter.