rendered paste bodyfloat4 Scene_PS (SCENE_VS_OUTPUT Input) : COLOR0
{
float2 ProjectedTexCoords;
ProjectedTexCoords[0] = Input.ShadowProjection.x / Input.ShadowProjection.w / 2.0f + 0.5f;
ProjectedTexCoords[1] = -Input.ShadowProjection.y / Input.ShadowProjection.w / 2.0f + 0.5f;
float color = 1.0f;
float4 moments = tex2D(shadowSampler, ProjectedTexCoords);
float len = length(LightPosition - Input.WorldPosition) / MaxLightDepth;
if (len >= moments.x)
{
float E_x2 = moments.y;
float Ex_2 = moments.x * moments.x;
float variance = min(max(E_x2 - Ex_2, 0.0) + 0.5, 1.0);
float m_d = (moments.x - len);
float p = variance / (variance + m_d * m_d);
color = clamp(p, 0, 1);
}
return color;
}