Hi Brad -- Is your texture a depth format texture? That is, on the host side, do you have something like this:

    _depthTex = new osg::Texture2D;
    _depthTex->setInternalFormat( GL_DEPTH_COMPONENT );

According to the GLSL spec, results from shadow2D and friends is undefined if the texture is not a depth format.

You'll probably also want to configure shadow comparison, func, and mode, if you're not already doing that.
   -Paul


On 7/7/2011 3:32 AM, Christiansen, Brad wrote:
Hi,

I am implementing some shadows at the moment and have come unstuck with my
understanding of how to sample a shadow texture.

To test my understanding, I implemented what I though shadow2D() would do using
'standard' sampling and a few calculations. This lead to the following code
which works as expected:

varying vec4 projShadow;

uniform sampler2D depthTex;

float val = texture2D(depthTex, projShadow.xy / projShadow.w).r;

float fragDepth = projShadow.z / projShadow.w;

if(val <= fragDepth) {

col = mix(col, vec4(1,0,0,1), 0.3); //shadow

} else {

col = mix(col, vec4(0,1,0,1), 0.3); //lit

}

 From my understanding I should be able to replace all this with:

varying vec4 projShadow;

uniform sampler2DShadow depthTex;

float val = shadow2D(depthTex, projShadow.xyz / projShadow.w).r;

or

float val = shadow2DProj(depthTex, projShadow).r;

When I do this I just get garbage.

Given I am getting the correct result with the first approach, and I think the
second should do exactly the same thing, I am stck as to why I cant get shadow
sampling to work correctly. Any suggestions would be greatly appreciated.

Cheers,

Brad

-------------------------------------------------------------------------
DISCLAIMER: This e-mail transmission and any documents, files and previous
e-mail messages attached to it are private and confidential. They may contain
proprietary or copyright material or information that is subject to legal
professional privilege. They are for the use of the intended recipient only. Any
unauthorised viewing, use, disclosure, copying, alteration, storage or
distribution of, or reliance on, this message is strictly prohibited. No part
may be reproduced, adapted or transmitted without the written permission of the
owner. If you have received this transmission in error, or are not an authorised
recipient, please immediately notify the sender by return email, delete this
message and all copies from your e-mail system, and destroy any printed copies.
Receipt by anyone other than the intended recipient should not be deemed a
waiver of any privilege or protection. Thales Australia does not warrant or
represent that this e-mail or any documents, files and previous e-mail messages
attached are error or virus free.
-------------------------------------------------------------------------



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


--
  -Paul Martz      Skew Matrix Software
                   http://www.skew-matrix.com/
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to