Hi Kai,

Disclaimer: I have not done anything like this. I did think about implementing such technique, though. And I am deeply interested in the results You could get. So I will try to provide few unproven suggestions in hope you will share them later ;-)

1. The way you attach texture layers will not work. This way you will have only one buffer active. Camera::atach in your usage scenario cause OSG to set up FBO using glFramebufferTextureLayer( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT, your_tex_array_gl_id, 0, layer ). Layer in this context does not define FRAMEBUFFER layer but layer of texture 2D array. Effectively you call attach 3 times but two first calls are overriden with third so finally your three calls:

   shadowCamera->attach(osg::Camera::COLOR_BUFFER, ta, 0, 0);  //
   shadowCamera->attach(osg::Camera::COLOR_BUFFER, ta, 0, 1);
   shadowCamera->attach(osg::Camera::COLOR_BUFFER, ta, 0, 2);

are effectively equal to last one:

   shadowCamera->attach(osg::Camera::COLOR_BUFFER, ta, 0, 2);

I guess you may want to replace it with following three calls:

   shadowCamera->attach(osg::Camera::COLOR_BUFFER0, ta, 0, 0);
   shadowCamera->attach(osg::Camera::COLOR_BUFFER1, ta, 0, 1);
   shadowCamera->attach(osg::Camera::COLOR_BUFFER2, ta, 0, 2);

this will set up multiple render targets with 3 independent color buffers. However, I am not sure if this will propely work with gl_Layer produced in Geometry shader. These OpenGL examples I saw usually set up layered framebuffer rendering with one glFramebufferTexture call. For example see this link (its sample code to render 6 faces of cubemap simultaneously) http://pastie.org/796448: However, this brings another problem: glFramebufferTexture functinality is not used by OSG yet.

2. Even assuming that you may set each layer as multiple render targets using above suggestion I see another problem: Shadow maps are generated into depth maps and hence you should rather set up DEPTH_BUFFERS insted of COLOR_BUFFERS . I am not sure if support for multiple depth buffer targets is already available for OpenGL (I know its present in recent Direct3D). You will have to check it. But even if its available in OpenGL its not yet supported by OSG.

3. On few forums I saw that people trying to set similar up rendering were able to get it to work on COLOR_BUFFERS but even then only one DEPTH_BUFFER layer was used. It looked like bugs in the drivers.

So the prospects are not too bright. I looks like you need to modify OSG FBO code to get what your are after. I have no idea, how deep these modifications should be....

In one of my concepts, instead of depth buffers I was considering using one 32 floating point color buffer (each channel would represent one depth layer) with BlendEquation set to RGBA_MIN. This way one could effectively replicate depth buffer behaviour with color buffer. Early Z -test is gone though....

Dont forget to post your results ;-)

Cheers,
Wojtek Lewandowski

----- Original Message ----- From: "Kai Xia" <[email protected]>
To: <[email protected]>
Sent: Monday, March 08, 2010 9:01 AM
Subject: [osg-users] problems about layer rendering


Hi,

I have some problems while using geometry shader and TextureArray to optimize PSSM shadow, the test code is like following:
C++ code:
osg::TextureArray *ta = new osg::TextureArray;
ta->setTextureSize(1024, 1024, 3);     //3 layer texture
...
shadowCamera->attach(osg::Camera::COLOR_BUFFER, ta, 0, 0);  //
shadowCamera->attach(osg::Camera::COLOR_BUFFER, ta, 0, 1);
shadowCamera->attach(osg::Camera::COLOR_BUFFER, ta, 0, 2);

Geometry shader code:

#extension GL_EXT_geometry_shader4 : require

varying vec4 color;

void main()
{
   //Route to Layer 0
   for (int i = 0; i < 3; i++)
   {
// You will recieve 3 positions since we set the input type to Triangles
       gl_Position = 0.5*gl_PositionIn[i] - vec4(0.5, 0.0, 0.0, 1.0);
       gl_FrontColor = vec4(1.0, 0.0, 0.0,1.0);
       gl_Layer = 0;
       EmitVertex();
   }
   EndPrimitive();

   //Route to Layer 1
   for (int i = 0; i < 3; i++)
   {
       gl_Position = 0.5*gl_PositionIn[i];
       //Just to see a difference in Layer 1
       gl_FrontColor = vec4(0.0, 1.0, 0.0,1.0);
       gl_Layer = 1;
       EmitVertex();
   }
   EndPrimitive();
   //Route to Layer 2
   for (int i = 0; i < 3; i++)
   {
       gl_Position = 0.5*gl_PositionIn[i] + vec4(0.5, 0.0, 0.0, 1.0);
       //Just to see a difference in Layer 1
       gl_FrontColor = vec4(0.0, 1.0, 0.0,1.0);
       gl_Layer = 2;
       EmitVertex();
   }
   EndPrimitive();
}

during the testing , only the 1st layer of texture have avaliable context(scene with red color), other 2 layers are undefined. Has some one sucessed in layer rendering? please give some advise, thanks a lot!


Cheers,
xiakai

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=25314#25314





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to