   Shadow mapping for directional lights (far plane issue)
  I'm trying to learn how to do shadow mapping following this article:http://www.gamedev.net/reference/articles/article2193.aspI'm skipping the filtering / blurring for now, I only want standard shadow mapping.I created a depth texture for the light that is projecting shadows.This was slightly problematic since it's a directional light, and I had to figure out a good spot to render the depth from, but it ended up working fine.I'm passing this texture,a worldViewMatrix,a lightViewMatrix (world * light view matrix * light projection matrix)and the mentionned matTexture to my shader:float4x4 worldViewProjection;float4x4 lightViewProjection;float4x4 matTexture;texture2D shadowDepth;sampler shadowSampler = sampler_state{    Texture = (shadowDepth);Filter = MIN_MAG_MIP_LINEAR;    AddressU = CLAMP;    AddressV = CLAMP;};struct VS_IN{float4 pos : POSITION0;};struct PS_IN{float4 pos : SV_POSITION;float4 vTexCoord : TEXCOORD0;float Depth : TEXCOORD1;};PS_IN VS( VS_IN input ){PS_IN output = (PS_IN)0;output.pos = mul(input.pos, worldViewProjection);output.vTexCoord = mul(input.pos, matTexture);output.Depth = mul(input.pos, lightViewProjection).z;return output;}float4 PS( PS_IN input ) : SV_Target{    float A = shadowDepth.Sample( shadowSampler, input.vTexCoord.xy / input.vTexCoord.w ).r;    float B = (input.Depth - 0.1f); //<-- ??    // Texel is shadowed    float fShadowTerm = A < B ? 0.0f : 1.0f;return float4(fShadowTerm, fShadowTerm, fShadowTerm, 1);}technique10 test{pass P0{SetVertexShader( CompileShader( vs_4_0, VS() ) );SetGeometryShader( 0 );SetPixelShader( CompileShader( ps_4_0, PS() ) );}}This actually works... however the shadowing is quite pessimistic:(It's a sphere resting on a plane, the light comes from top right corner)I analyzed the code again, and this line seems quite suspicious:float B = (input.Depth - 0.1f);Do we substract 0.1 here, because it is impossible to compare 2 float values when they are very close to eachother?Lowering it to 0.01 resulted in this:This is much better, except for the artifacts on the sphere.However fiddling with this value isn't the solution to my problem.The issue is actually related to the far plane of my directional light.Since it's a directional light I used Orthogonal projection:light.Projection = Matrix.OrthoRH(20, 20, 1, 100);If I increase the far plane, the shadows get smaller.A smaller far plane results in bigger shadows.First of all, is this a standard issue with shadow mapping for directional lights, or am I doing something wrong?If it is a standard issue, is doing this a good idea?:float B = (input.Depth - 1.0f / lightFarPlane);This will result in the following image, regardless of the value of the far plane:Looks correct to me.The question is, is a mistake causing this behaviour, and have I just written something to compensate my mistake, or is this an actual problem with directional shadow maps (or even shadow maps in general)?Since this is the first time I'm doing shadow mapping I really want to get it right.   
Quote:Original post by Hyunkel...I created a depth texture for the light that is projecting shadows.This was slightly problematic since it's a directional light, and I had to figure out a good spot to render the depth from, but it ended up working fine.We keep meeting like this, I think you need to get a better book. :)I think the problem you might have is that you should be using an isometric projection. All the depth related problems go away then as there is no perspective to worry about. Directional lights shouldn't look like they have an origin so this isn't a hack - it's the right thing to do.   ;  Could you elaborate a bit on isometric projection?I'm using orthogonal projection to render the depth for my directional light, so I don't have a perspective or a point of origin.This is my light's depth map:It's a bit hard to tell, but there really isn't any perspective.When I said figure out a good spot, I was referring to setting the view matrix in a way that I capture all the relevant parts of my scene.And yes, I agree, I really do need to get a proper book for these things :)   