Hi,

After tinkering with this for a while, it turns out that it is more of a 
shader problem than an OSG problem.  Setting up a texture with a 
GL_DEPTH_COMPONENT internal and source format and attaching it to a camera 
node as osg::CameraNode::DEPTH_BUFFER works fine.

The original fragment shader source that I was using was basically:

  uniform sampler2D texDepth;

  void main()
  {
    vec4 depth = texture2D(texDepth, gl_TexCoord[1].st);
    gl_FragColor = vec4(vec3(depth.r), 1);
  }

This produced my "white" rendering.  My coworker discovered that by taking 
the resultant depth value and performing some simple math on it, we could 
begin to see the varying degrees of gray that we expected to see.

So, by changing the fragment shader to...

  uniform sampler2D texDepth;

  void main()
  {
    float depth = texture2D(texDepth, gl_TexCoord[1].st).x;
    depth = (depth - 0.996) * 256.0;
    gl_FragColor = vec4(vec3(depth), 1);
  }

... we could finally see the detail that we thought we should be seeing.

Hope this helps anyone else who might be experimenting with this.  If the 
above calculation is wrong, please feel free to correct it.  

Also, I'm not quite sure why it works like it does.  I'd be interested to 
hear some thoughts about what the calculation is actually doing.

Thanks,
Brian



> Hi,
> 
> In my quest for food (i.e. lunch), I failed to mention what I have 
tried.  I 
> create a 2D texture like:
> 
>   m_DepthTexture = new osg::Texture2D();
>   m_DepthTexture->setInternalFormat(GL_DEPTH_COMPONENT);
>   m_DepthTexture->setShadowComparison(true);
>   m_DepthTexture->setShadowTextureMode(osg::Texture::LUMINANCE);
>   m_DepthTexture->setFilter(osg::Texture2D::MIN_FILTER,
>     osg::Texture2D::LINEAR);
>   m_DepthTexture->setFilter(osg::Texture2D::MAG_FILTER,
>     osg::Texture2D::LINEAR);
>   m_DepthTexture->setTextureSize(width, height);
> 
>   m_CameraNode->attach(osg::CameraNode::DEPTH_BUFFER, m_DepthTexture);
> 
> Then I associate a texture environment with my geometry that I'll be 
> applying the shader to:
> 
>   osg::ref_ptr<osg::TexEnv> texenv = new osg::TexEnv;
>   texenv->setMode(osg::TexEnv::DECAL);
>   m_Geometry->getOrCreateStateSet()->setTextureAttribute(1,texenv.get());
> 
> I set up my shader uniform as a osg::Uniform::SAMPLER_2D_SHADOW and 
assign 
> it the appropriate texture unit.
> 
> I am also attaching a osg::CameraNode::COLOR_BUFFER to the same camera 
node 
> with an appropriate texture.
> 
> 
> Finally, I've got a simple shader program that I'm trying to use.
> 
> uniform sampler2DShadow texDepth;
> 
> void main()
> {
>   vec4 shadow = shadow2D(texDepth, gl_TexCoord[1]);
>   gl_FragColor = shadow;
> }
> 
> 
> Regardless as to what my scene contains, the shader output is always pure 
> white.  However, if I remove the shader portion, the scene renders fine. 
> There are no debug output errors that I have seen.  The FBO is created 
fine.
> 
> If anyone has any insight into this problem, I'd really appreciate it.
> 
> Thanks,
> Brian
> 
> 
> ----- Original Message ----- 
> From: <[EMAIL PROTECTED]>
> To: <[email protected]>
> Sent: Monday, February 12, 2007 11:12 AM
> Subject: [osg-users] Question about osgdepthshadow example.
> 
> 
> > Hi,
> >
> > I'm trying to modify this example slightly so that only the depth buffer
> > portion is rendered.  The shadow is cool, but is there a way to just 
> > render
> > the depth buffer?
> >
> > Thanks,
> > Brian
> >
> > _______________________________________________
> > osg-users mailing list
> > [email protected]
> > http://openscenegraph.net/mailman/listinfo/osg-users
> > http://www.openscenegraph.org/
> > 
> 
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://openscenegraph.net/mailman/listinfo/osg-users
> http://www.openscenegraph.org/
> 
> 
> 
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to