PDA

View Full Version : ShadowMapping Projection.



BlackBox
10-25-2005, 05:02 AM
Hi,

I'm trying to do shadows using shadowmaps in GLSL.
At the moment I have this:
1) the depth from the light position.
http://www.macs.hw.ac.uk/~ceesmp/lD.JPG
2) the depth from the camera position.
http://www.macs.hw.ac.uk/~ceesmp/cD.JPG

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. ;)

jide
10-25-2005, 06:20 AM
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.

BlackBox
10-25-2005, 07:29 AM
Originally posted by jide:
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.I prefer using shaders. Plus it would be a good exercise to do :)

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.

AnselmG
10-26-2005, 10:01 PM
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.

BlackBox
10-27-2005, 06:04 AM
Originally posted by AnselmG:
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.Thanks but...

What do you mean by lightintrinsic and lightextrinsic?

AnselmG
10-27-2005, 07:23 AM
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...