ShadowMapping Projection

Hi,

I’m trying to do shadows using shadowmaps in GLSL.
At the moment I have this:

  1. the depth from the light position.
  2. the depth from the camera position.

Now, if I’m correct, I need to project the depth map from the light position into the camera one. And then compare the depth values using an IF.

The problem I have is: I don’t know how to project the light depth into the camera depth.
Any idea how to do this?

Thanks. :wink:

This is not related to shaders at all. What you need is a good tutorial on shadow mapping and there are plenty on the net, just google.

What you need at this point, as far as I can remember is to compare the two textures, use the ARB_shadow extension (and surely another one) for that purpose. Just check the extension registry if the tutorial you’ll find doesn’t talk about that.

Also, I advice you first do the shadow mapping without using shaders at all. Then, when they’ll work, try the shader.

Originally posted by jide:
[b]This is not related to shaders at all. What you need is a good tutorial on shadow mapping and there are plenty on the net, just google.

What you need at this point, as far as I can remember is to compare the two textures, use the ARB_shadow extension (and surely another one) for that purpose. Just check the extension registry if the tutorial you’ll find doesn’t talk about that.

Also, I advice you first do the shadow mapping without using shaders at all. Then, when they’ll work, try the shader.[/b]
I prefer using shaders. Plus it would be a good exercise to do :slight_smile:

To my knowledge I need to do:
lightProjection * LightView * InvCamView
to project the texture. But I’m not 100% sure about this. Is this correct?

Now in GLSL, I know there is the function:
Texture2dProj or textureRectProj,
which should project the texture but how do I use this functions?

Thanks for your answer.

Ps. If anyone knows a tutorial of shadow mapping using glsl let me know. the only one I can google is:

http://www.ampoff.org/modules.php?name=Forums&file=viewtopic&t=15

Thanks.

Hi,

what you need is a manipulated Texture Matrix. So you have to apply a perspective projection from your light position. means something like:

glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5, 0.5, 0.0);
glScalef(0.5, 0.5, 1.0);
gluPerspective(<lightintrinsic>);
gluLookAt(<lightextrinsic>);

the Scale/Translation has to be done to map from NDC [-1,1] into your texture UV space [0,1].

You can use this Matrix then to do the correct texture2Dproj lookup in your GLSL fragment shader.
It should return 0 if the fragment is in shadow and 1 if it´s lit.

Originally posted by AnselmG:
[b]Hi,

what you need is a manipulated Texture Matrix. So you have to apply a perspective projection from your light position. means something like:

glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5, 0.5, 0.0);
glScalef(0.5, 0.5, 1.0);
gluPerspective(<lightintrinsic>);
gluLookAt(<lightextrinsic>);

the Scale/Translation has to be done to map from NDC [-1,1] into your texture UV space [0,1].

You can use this Matrix then to do the correct texture2Dproj lookup in your GLSL fragment shader.
It should return 0 if the fragment is in shadow and 1 if it´s lit.[/b]
Thanks but…

What do you mean by lightintrinsic and lightextrinsic?

hi,

the <lightintrinsic> means the gluPerspective(fov, aspect, near, far) [or the according glFrustum()]values. You have to use the same ones you used when you captured the shadowmap.

the <lightextrinsic> are the 9 gluLookAt values which describes your light source pos,dir and upvector.

if you don´t use gluLookAt() you have to use the view transformation you used for your shadowmap generation…

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.