Hi J-S,

All your math seems correct to me. I would use ( lightSpaceDepth * 0.5 + 0.5 ) to compare with shadow map. But you said you tried it. Using DEPTH_COMPONENT is also ok IMHO. Debuging shaders display these values so its possible to access them. So I think that maybe your uniforms or osg_ViewMatrixInverse should be checked. Long time ago we had an issue with osg_ViewMatrixInverse not being set for nested cameras. We had to set it ourselves in this case. I am not sure if this limitiation is still present, it was few years ago.

Do I correctly decipher PCSS as percentage closer soft shadows ? I was mixing SoftShadowMap shaders with MimimalShadowMap for some project in the past. It was actually possible without changing comparison mode because SSM also uses GL_COMPARE_R_TO_TEXTURE_ARB mode.

Cheers,
Wojtek


Hi all,

I want to do shadow mapping by doing the depth comparisons myself in
order to implement PCSS. In order to do this I modified the
osgShadow::DebugShadowMap and StandardShadowMap classes to not enable
shadow comparison modes (GL_COMPARE_R_TO_TEXTURE_ARB), and when sampling
the shadow map I get raw depth values, which is what I want.

However, to get the right main pass depth to compare to the shadow map
value, I need to transform the fragment position to light space. To do
this, I've added a uniform that stores the shadow camera's view and
projection matrices, which I set in
StandardShadowMap::aimShadowCastingCamera():

    _stateset->getOrCreateUniform("ShadowCameraTransform",
                                  osg::Uniform::FLOAT_MAT4)->set(
                                      view * projection);

Using that matrix, I would have thought in my shader I could do the
following:

uniform mat4 ShadowCameraTransform;
uniform mat4 osg_ViewMatrixInverse;

// ...

varying vec4 lightSpacePos;

void main()
{
    // ...

    mat4 modelMatrix = osg_ViewMatrixInverse * gl_ModelViewMatrix;
    vec4 worldPos = modelMatrix * gl_Vertex;
    lightSpacePos = ShadowCameraTransform * worldPos;

    // ...
}

And then use that to compare a light-space depth value in the fragment
shader which I could use to compare to the shadow map:

    float lightSpaceDepth = (lightSpacePos.xyz / lightSpacePos.w).z;
    float shadowMapDepth = texture2D( shadowTexture, uv ).r;

However the lightSpaceDepth value above doesn't seem to be in the right
coordinate space or something, as I get values in too small a range.
I've tried the classic transforms ( * 0.5 + 0.5 or * 2.0 - 1.0) but the
values are still not in the right range.

First of all, am I doing the math right?

Second of all, I left the texture internal format set to
GL_DEPTH_COMPONENT and attached to the DEPTH_BUFFER, assuming that it
was OK, but could that explain my problems? Should I change it to a
general purpose float format (say GL_LUMINANCE32F_ARB), attach it to the
COLOR_BUFFER and write to gl_FragData[0] in the shadow pass's fragment
shader?

Just trying to sanity check a bit :-)

Thanks in advance,

J-S
--
______________________________________________________
Jean-Sebastien Guay    jean-sebastien.g...@cm-labs.com
                               http://www.cm-labs.com/
                        http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to