PDA

View Full Version : MRT for Texture2DArray



DmitryM
09-21-2009, 04:52 PM
I'm trying to integrate deferred renders into the engine.
I want to write the following values: diffuse color, specular color, normal & tangent space quaternion.
I created a Texture2DArray with 4 slices of standard RGBA8 format. Then I assigned each slice to a different color attachment (0 to 3) of the FBO and set up DrawBuffers to draw to all these attachments.

However, I see the result only in the first layer when drawing them to the screen (for debug). There is garbage in other elayers...
Is there something not allowing to use MRT with texture arrays? Or it's just my logical error somewhere?

Dark Photon
09-21-2009, 06:29 PM
Is there something not allowing to use MRT with texture arrays?
I doubt it. NVidia specifically recommends you do this for PSSM in GPUGems3 (albeit in D3D). Though they used a geometry shader (translate: gl_Layer) to select which layer of the 2D array texture to write to.

Also, I believe that's precisely the purpose of the glFramebufferTextureLayer API, which adds a "layer" parameter. Mentioned in EXT_texture_array (http://www.opengl.org/registry/specs/EXT/texture_array.txt).

DmitryM
09-21-2009, 07:40 PM
AFAIS, Nvidia used not MRT but Layered Rendering. The latter designed to work in layers but it's different from what I want to use. MRT seems to be faster (by not using Geometry Shader and transforming vertices twice) and better supported by older HW.

And yes, of course I'm using glFramebufferTextureLayer to select the layer for each color attachment. But in my case all layers belong to a single texture, so It *might* be a problem.

Alfonse Reinheart
09-21-2009, 08:12 PM
You could try it with 4 different textures rather than a single array texture.

BTW, did you query GL_MAX_DRAW_BUFFERS? You should not use more than that many buffers in a single draw call.

DmitryM
09-22-2009, 06:25 AM
Yes, I could use 4 different textures.... But... I'll try to get it work straight with layers a little bit more.

I work with Radeon 2400 HD, my MaxDrawBuffers is 8.

Dark Photon
09-22-2009, 07:18 AM
AFAIS, Nvidia used not MRT but Layered Rendering. The latter designed to work in layers but it's different from what I want to use.
Sorry, I didn't realize there was a distinction in naming.

When reading D3D-centric articles like that, I tend to just ignore what they call things (because everything's named differently or flipped backwards/upside down -- just for the heck of it), and look at what they're doing.

DmitryM
09-22-2009, 07:28 AM
Actually, I read articles in the same manner as you, Dark Photon:)
However, it's often required to know true names of things in order to communicate correctly.

Back to the topic: the problem is solved. I just failed to render the results correctly...
So there's nothing blocking from using MRT for different layers of a single texture.

One more step - and I'll have deferred renders :)

skynet
09-22-2009, 07:57 AM
Using an array texture for your gbuffer will prevent you from using different formats for different attachments. For instance, I like to store the normals as RGB10_A2 while albedo is stored as RGBA8.