// Sample the shadow map depth value from the depth texture using the sampler at the projected texture coordinate location.
depthValue = shaderTextures[6 + i].Sample(SampleTypeClamp, projectTexCoord).r;
// Calculate the depth of the light.
lightDepthValue = input.lightViewPositions[i].z / input.lightViewPositions[i].w;
// Subtract the bias from the lightDepthValue.
lightDepthValue = lightDepthValue - bias;
// Compare the depth of the shadow map value and the depth of the light to determine whether to shadow or to light this pixel.
// If the light is in front of the object then light the pixel, if not then shadow this pixel since an object (occluder) is casting a shadow on it.
if(lightDepthValue < depthValue)
{
// Calculate the amount of light on this pixel.
//lightIntensity = saturate(dot(input.normal, input.lightPositions));
lightIntensity = saturate(dot(input.normal, normalize(input.lightPositions[i])));
if(lightIntensity > 0.0f)
{
// Determine the final diffuse color based on the diffuse color and the amount of light intensity.
color += (diffuseCols[i] * lightIntensity * 0.25f);
}
}
else // shadow falloff here
{
float4 shadowcol = (1,1,1,1);
float shadowintensity = saturate(length(input.lightpositions[i])*0.038);
color += shadowcol * shadowintensity*shadowintensity*shadowintensity;
}
}
}
// Saturate the final light color.
color = saturate(color);
Hi, I want to add a fall off to the shadows in this pixel shader. This should be really straightforward - just get the distance between the light position and the vertex position, and multiply it by the light intensity at the pixel being shadowed, so the light intensity will increase and the shadow will fade away towards the edges. As you can see, I get the "lightPosition" from the input (which comes from the vertex shader, and was calculated by worldLightPosition - worldVertexPosition inside the vertex shader, so taking its length should give you the distance between the light and the pixel.)
I multiplied it by 0.038, an arbitrary number, to scale it down, because it needs to be between 0 and 1 before multiplying it by shadow color (1,1,1,1) to give a gradient. However, this does absolutely nothing, and I cant tell where its failing.
Please look at the attached files to see the full code of the vertex and pixel shaders. Any advice would be very welcome, thanks!