I’m trying to store the depth information of model in XNA from the lights point of view. The model renders fine using a normal shader.
This is the shader code
float4x4 xShadowMapLight;
///DEPTH MAP
float4 RenderShadowMapPS( VS_SHADOW_OUTPUT In ) : COLOR
{
return float4(1,0,0,0); //In.Depth.x,In.Depth.x,In.Depth.x,0);
}
VS_SHADOW_OUTPUT RenderShadowMapVS(float4 vPos: POSITION)
{
VS_SHADOW_OUTPUT Out;
Out.Position = mul(vPos, xShadowMapLight);
Out.Depth.x = 1-(Out.Position.z/Out.Position.w);
return Out;
}
technique ToonShaderDepthMap{
pass P0{
VertexShader = compile vs_2_0 RenderShadowMapVS();
PixelShader = compile ps_2_0 RenderShadowMapPS();
}
}
And this is the way I generate the light matrix that is passed to the shader.
Matrix view = Matrix.CreateLookAt(modelTransform.Translation, new Vector3(0, 500, 75), Vector3.Up);
Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, 1.0f, (float)globals.NEAR_PLANE, (float)globals.FAR_PLANE);
Matrix ShadowMapLight = modelTransform * view * projection;
But apparently I’m not always getting to the pixel shader and it stops in the vertex for some reason. (I have modified the pixel shader to output always a red pixel, so I know when it goes through).
xShadowMapLight is the Matrix containing all the transformations from the lights point of view. Apparently the problem is in mul(vPos, xShadowMapLight); cause if I change the matrix for anIdentity one the shader gets to the pixel one.
Any idea why this might happen?
Thanks in advance!