render to 3D texture

Hi,

Is it possible to render to a 3D texture using GLSL? I only found an example in CG, so I would be really glad if some one could tell me if i can also do so in GLSL.- if so I would be happy about some useful links or a simple example,

Thanks!

With the exception of layered rendering in Geometry Shaders, the shading language has no bearing on what the render target is.

An example that uses GLSL would look like the Cg version except with a different shader language. The FBO stuff is what makes rendering to 3D textures work, not the shading language.

so if I bind a FBO with a 3D texture as a rendertarget, it will automatically call the fragmentshader (and gl_FragColor/gl_FragData) for each value in the 3D texture?

The questions was actually pretty stupid now that I think about it again.- Still I am having a hard time to picture in my mind how that would work.

You can only bind one slice (or n slices, if you use n render targets) of a 3d texture as render target. It is not possible to have all pixels in a 3D texture as render target. Works in cg the same way.

It is not possible to have all pixels in a 3D texture as render target.

If you use ARB_geometry_shader, you can bind a 3D texture in its entirety. However, each primitive your geometry shader output goes to can only render to a specific slice of the 3D texture.

That is interesting. So you can choose per outgoing primitive in the geometry shader to which slice you want to render? (or does it work per incoming primitive?)

Such things might be great for calculating force fields for particles in a 3d texture. Using the geometry shader to splat particles on the appropriate slices.

You should probably write the layer to each vertex emitted in a GS, as the particular vertex used to pull the value from is undefined (according to page 69-70 of the spec).

Haven’t actually tried any layered rendering yet myself, but rtt cubemaps are on my list of things to try.

So you can choose per outgoing primitive in the geometry shader to which slice you want to render? (or does it work per incoming primitive?)

It’s per output primitive. I don’t know how it would make sense if it were per incoming primitive.