///////depth map struct VS_OUT { float4 hPosition : POSITION; float4 Position : TEXCOORD0; }; VS_OUT DepthVS(float4 position : POSITION, uniform float4x4 worldViewProj) { VS_OUT OUT; OUT.hPosition = mul(worldViewProj, position); OUT.Position = mul(worldViewProj, position); return OUT; } //for directional light float4 DepthPS(VS_OUT IN ):COLOR { //return 1; float4 pos = (IN.Position / IN.Position.w); //pos = (pos +1.0 ) / 2.0; return float4(pos.z, pos.z * pos.z, 1, 1); } ///////////////Shadow struct VS_OUT_SHADOW { float4 hPosition : POSITION; float4 Position : TEXCOORD0; float4 lPosition : TEXCOORD1; }; VS_OUT_SHADOW depthShadowVS(float4 position : POSITION, uniform float4x4 worldViewProj, uniform float4x4 world, uniform float4x4 lightViewProj) { VS_OUT_SHADOW OUT; OUT.hPosition = mul(worldViewProj, position); float4 wPos = mul(world, position); OUT.lPosition = mul(lightViewProj, wPos); OUT.Position = position; return OUT; } /* float4 depthShadowPS(VS_OUT_SHADOW IN, uniform float4x4 lightViewProj, uniform sampler2D depthShadowMap : register(s0) ):COLOR { float bias = 0.0001; float4 light = float4(1,1,1,1); float4 shadow = float4(0.6,0.6,0.6,1); float4 pos = (IN.lPosition / IN.lPosition.w); pos.xy = (pos.xy +1.0 ) / 2.0; pos.y = 1.0 - pos.y; float4 storedDepth = tex2D(depthShadowMap, pos.xy); if(storedDepth.r + bias < pos.z) { float M1 = storedDepth.r; float M2 = storedDepth.g; float v2 = M2 - M1 * M1; float pmax = v2 / (v2 + pow(M1 - pos.z, 2)); light = shadow + (1 - shadow) * pmax; //light = shadow; } //return abs( pos.z - storedDepth.z ); return light; } */ float4 depthShadowPS(VS_OUT_SHADOW IN, uniform float4x4 lightViewProj, uniform sampler2D depthShadowMap : register(s0) ):COLOR { float bias = 0.0001; float4 light = float4(1,1,1,1); float4 shadow = float4(0.65,0.65,0.65,1); //float4 shadow = float4(0,0,0,1); if(IN.lPosition.z > 0.0) { float4 pos = (IN.lPosition / IN.lPosition.w); pos.xy = (pos.xy + 1.0) / 2.0; pos.y = 1.0 - pos.y; float4 storedDepth = tex2D(depthShadowMap, pos.xy); if(storedDepth.r + bias < pos.z) { light = shadow; } //if(length(pos.xy)>1) // light = shadow; } return light; }