PDA

View Full Version : Question regarding cascaded shadow map



somboon
03-26-2010, 10:31 PM
1.can cascaded shadow map be implement with out using texture array ?

I try to run the sample code provide in NVIDIA OpenGL SDK 10 on my ATI 4670 video card with latest driver but the application report loaded of shader compilation error.

Look like the error are from the code using array texture.

If I dont using array texture in fragment code but just using hardcode declaration of multiple depth texture (I only plan to use 2 split anyway) will some thing like this work ?

uniform sampler2D shadow1;
uniform sampler2D shadow2;

if(//some selection logic based on z value){
//compare depth using texture 1
}
else{
//compare depth using texture 2
}

2.about how to set up view matrix for directional light source (for basic shadowmap and not related to above question) ?

I alway use perspective projection and treating my direction light source as a point in the air that shine to certain point (in this case origin) thus the look up code become




//view matrix
Matrix lightViewMatrix;
lightViewMatrix.createLookAtMatrix(position[0],position[1],position[2],
0,0,0,
0.0f,0.0f,1.0f);

//projection matrix

Matrix lightProjectionMatrix; lightProjectionMatrix.createPerSpectiveMatrix(45.0 f,(float)shadowWidth/(float)shadowHeight,nearPlane,farPlane);




the createLookAtMatrix and createPerspectiveMatrix above is just a emulation of glLookAt/gluPerSpective for use with my GL 3.2 code.

It give a somewhat correct result and easy to understand. but every where I read they suggest using orthogonal projection wide enough to capture the scene and glLookAt code that involed negative light direction,this is the part that I dont understand.

Please someone give me an idea for how to set up view/projection matrix for directional light source.

Mikkel Gjoel
03-29-2010, 10:34 AM
1. Yes, layout your cascades in a texture-atlas (often 2x2).

2. A directional light is an orthographic projection, you can't sensibly use a perspective projection instead. I don't know what you've read, but I suspect the "negative light direction" you mention arises from calculating the direction FROM the vertex TO the light, not the light-direction from the light.