I've been implementing another shadow shader and am having some problems. This is my question. When you generate the depth map you use code like the following ...
Vertex Shader
float4 WPosP = mul(IN.Pos,World);
float4 Proj = mul(WPosP,LightProjMatrix);
OUT.OPos = Proj;
OUT.Depth = Proj.z;
Pixel Shader
return float4(smoothstep(0,75,IN.Depth),0,0,1)
Now you have your lovely depth image.
Then when you perform the lookup in the final render, you use something like the following:
Vertex Shader
OUT.wpos = mul(IN.pos,World);
float4 lPos = mul(OUT.wpos,LightProjMatrix);
OUT.lpos = mul(ViewMatrix,lPos);
Pixel Shader
float3 depthTex = tex2Dproj(texDepthmap,IN.lpos);
float depth = smoothstep(0,75,IN.lpos.z);
if (depth < depthTex.r){
}
The bit I've underlined (the view matrix multiplication) is the bit I don't get. In the shaders I've worked from (Evolved's examples) the ViewMatrix is hardcoded as the following:
matrix ViewMat={0.5,0,0,0.5,0,-0.5,0,0.5,0,0,0.5,0.5,0,0,0,1};
I want to know what this is and what it does. In my head, I can't see why that bit needs to be there. If the world multiplication and LightViewProj multiplicates are the same in the depth render and the final render, then to me that suggests that's all you need to do. My only guess is that additional ViewMatrix multiplication is something to do with the tex2DProj which happens later.
Futhermore, I've tried passing in the lights view matrix and the cameras view matrix instead of using the hard coded one, and neither of these generate the correct result, so it's obviously something different.
The reason why I'm asking is the shadow shading doesn't work when I start playing around with my light camera FOV and view range. I want a really tight FOV and narrow view range to achieve a directional light effect and a high precision depth map, but the tex2DProj lookup is wrong once I start playing with these values. Since I am passing in the LightViewProj matrix correctly for the light camera, I can only surmize it's something to do with this hardcoded ViewMatrix.
Any help appreciated!