PDA

View Full Version : [cg/hlsl] depth texture different depths in comparison



supagu
01-21-2006, 12:07 AM
i'm writting a shadow map shader in cg. Firstly i render the scene from the lights view.
I grab the depth texture and pass it off to the shader when rendering the scene from the main camera.

Now in this shader, i transform the vertices the same they are transformed when rendered from the lights camera this is so i know the distance from the light and should *in theory* be able to do a strait comparison between the depth to the light and the depth texture.

Problem is, that there is some difference between the texture and the transformed verts.

in my vertex shader:


float4 sceneDepth = mul(projection, float4(IN.position, 1.0));
OUT.zDepth = sceneDepth;
projection marix is light view * light projection (the mesh is using an identity matrix)

then in pixel shader:


float4 depth = tex2Dproj(shadow, IN.uvCoord);
OUT.colour = depth.r < (IN.zDepth.z/IN.zDepth.w) ? float4(1.0, 0.0, 0.0, 1.0) : float4(0.0, 0.0, 0.0, 1.0);
this is what i get: http://www.users.on.net/~firefox/fab/shadow_close.JPG
http://www.users.on.net/~firefox/fab/shadow_far.JPG

the light in both screenshots are at different distances, its like the texture depth map isnt in the same space as the space i transform the mesh to in my vertex shader.

Not that the camera transform and the light camera transform have the same perspective, aspect ratio's and close/far clip planes.

any ideas on how to fix this?