PDA

View Full Version : Shadowmapping with parallel lights



AdrianPi
11-08-2010, 08:07 PM
Hi,

I'm having trouble with shadow-maps and parallel lights. I'm using OpenTK and GLSL 1.20. I'm just trying to use an ortho projection where I used a perspective projection for spotlights.

To render the scene from the light source I do:


GL.MatrixMode(MatrixMode.Projection);
GL.PushMatrix();
GL.LoadIdentity();
if (lightType == LightType.Spot)
GLX.Perspective(spotAngle * 2, 1, znear, zfar);
else if (lightType == LightType.Directional)
GL.Ortho(-500, 500, -500, 500, znear, zfar); // this is not working

GL.MatrixMode(MatrixMode.Modelview);
GL.PushMatrix();
GL.LoadIdentity();
Matrix4 m = new Matrix4();
GetWorldTransform(ref m);
m.Invert();
GL.MultMatrix(ref m);

Then, when rendering the scene I do:


GL.MatrixMode(MatrixMode.Texture);
GL.LoadIdentity();
if (light.LightType == LightType.Spot)
{
GL.Translate(.5f, .5f, .499f);
GL.Scale(.5f, .5f, .5f);
GLX.Perspective(light.SpotAngle * 2, 1, light.Near, light.Far);
}
else if (light.LightType == LightType.Directional)
{
GL.Ortho(-500, 500, -500, 500, light.Near, light.Far);
}
Matrix4 m = new Matrix4();
light.GetWorldTransform(ref m);
m.Invert();
GL.MultMatrix(ref m);

In the vertex shader I do:


gl_TexCoord[4] = gl_TextureMatrix[4] * gl_Vertex;
And finally in the fragment shader I do:


float light = shadow2DProj(texUnit8, gl_TexCoord[4]).r;
But I get all fragments in shadow. (light always 0)

What I'm missing?

Thanks in advance.

AdrianPi
11-08-2010, 09:10 PM
Disregard, got it working. I also needed to bias the shadow projection matrix.