texture InputTexture; sampler inputSampler = sampler_state { Texture = ; MipFilter = Point; MinFilter = Point; MagFilter = Point; AddressU = Clamp; AddressV = Clamp; }; texture ShadowMapTexture; sampler shadowMapSampler = sampler_state { Texture = ; MipFilter = Point; MinFilter = Point; MagFilter = Point; AddressU = Clamp; AddressV = Clamp; }; float2 renderTargetSize; struct VS_OUTPUT { float4 Position : POSITION; float2 TexCoords : TEXCOORD0; }; VS_OUTPUT FullScreenVS( float3 InPos : POSITION, float2 InTex : TEXCOORD0) { VS_OUTPUT Out = (VS_OUTPUT)0; // Offset the position by half a pixel to correctly align texels to pixels Out.Position = float4(InPos,1) + 0.5f* float4(-1.0f/renderTargetSize.x, 1.0f/renderTargetSize.y, 0, 0); Out.TexCoords = InTex; return Out; } float4 ComputeDistancesPS(float2 TexCoord : TEXCOORD0) : COLOR0 { float4 color = tex2D(inputSampler, TexCoord); //compute distance from center float distance = color.a>0.3f?length(TexCoord - 0.5f):1.0f; //save it to the Red channel return float4(distance,0,0,1); } float4 DistortPS(float2 TexCoord : TEXCOORD0) : COLOR0 { //translate u and v into [-1 , 1] domain float u0 = TexCoord.x * 2 - 1; float v0 = TexCoord.y * 2 - 1; //then, as u0 approaches 0 (the center), v should also approach 0 v0 = v0 * abs(u0); //convert back from [-1,1] domain to [0,1] domain v0 = (v0 + 1) / 2; //we now have the coordinates for reading from the initial image float2 newCoords = float2(TexCoord.x, v0); //read for both horizontal and vertical direction and store them in separate channels float horizontal = tex2D(inputSampler, newCoords).r; float vertical = tex2D(inputSampler, newCoords.yx).r; return float4(horizontal,vertical ,0,1); } float GetShadowDistanceH(float2 TexCoord, float displacementV) { float u = TexCoord.x; float v = TexCoord.y; u = abs(u-0.5f) * 2; v = v * 2 - 1; float v0 = v/u; v0+=displacementV; v0 = (v0 + 1) / 2; float2 newCoords = float2(TexCoord.x,v0); //horizontal info was stored in the Red component return tex2D(shadowMapSampler, newCoords).r; } float GetShadowDistanceV(float2 TexCoord, float displacementV) { float u = TexCoord.y; float v = TexCoord.x; u = abs(u-0.5f) * 2; v = v * 2 - 1; float v0 = v/u; v0+=displacementV; v0 = (v0 + 1) / 2; float2 newCoords = float2(TexCoord.y,v0); //vertical info was stored in the Green component return tex2D(shadowMapSampler, newCoords).g; } float4 DrawShadowsPS(float2 TexCoord : TEXCOORD0) : COLOR0 { // distance of this pixel from the center float distance = length(TexCoord - 0.5f); //distance stored in the shadow map float shadowMapDistance; //coords in [-1,1] float nY = 2.0f*( TexCoord.y - 0.5f); float nX = 2.0f*( TexCoord.x - 0.5f); //we use these to determine which quadrant we are in if(abs(nY)