Hi, shadow mapping is a projective texturing approach. A good methaphor to explain it is that from the light source a slide projector is casting the depth buffer on your scene. For this to work you need to do two things: 1. create your depth buffer with screenspace coordinates(the screenspace of the shadow camera) 2. Pass the view projection matrix of your shadow pass to the main pass and use it to project the world coordinates of your scene into screenspace coordinates of the shadow camera. The projected coordinates can then be used as texture coordinates for your depth buffer. I have written a very basic shadow mapping example: https://github.com/MPursche/3dcgtutorials/tree/master/03_ShadowMapping It uses a GL_R32F depth buffer(I wanted to evaluate the performance against a regular depth buffer). It uses forward shading but I hope you can apply the principle on your deferred shading renderer.
Here is the part where I calculate the shadow matrix for the main pass: Code: osg::Matrixd shadowMatrix = viewMatrix * projectionMatrix * osg::Matrixd::translate(1.0, 1.0, 1.0) * osg::Matrixd::scale(0.5, 0.5, 0.5); The translation and scale at the end is to come from [-1,1] coordinates to [0,1] coordinates. You just need to do the following, to compute the texture coordinates for your depth texture: Code: gl_TexCoord[0] = shadowMatrix * gl_Vertex; // insert modelMatrix here if necessary -> shadowMatrix * modelMatrix * gl_Vertex This is how my fetch in the shader looks like: Code: float depth = texture2D(depthTexture, gl_TexCoord[0].st).x; float visibility = (shadowDepth <= (depth + 0.1)) ? 1.0 : 0.0; Thank you! Cheers, Marcel ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=56749#56749 _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

