Directional light is a subject that has been mentioned many times in this forum, but I haven't found a good solution yet.
These threads provide a couple of pointers:
viewtopic.php?f=1&t=1646viewtopic.php?f=1&t=368Using a spotlight far away from the scene doesn't work well; there is too much shadow acne or peter-paning. Tuning the shadow bias doesn't solve the issue.
The depth value used in the shader is always:
Code:
depth = d / r
with
d: the distance of the fragment to the spotlight position
r: radius of the spotlight
The shadow map is a 24-bit number and the precision suffers if the scene occupies a tiny range of spotlight radius. The solution would be to have the depth range in the shadow map adjusted with the bounding box of the scene. The current implementation uses the shadow caster's AABB's to optimise projection matrix to generate the shadow map (eg. the x,y values for the shadow map are optimised). However the bounding box is not used to adjust the near/far plane of the frustum (and the shader doesn't use this projection to compute the depth value, it just uses the light's radius).
Please let me know if anything in the description above is not true. Did anyone already tried to tackle this problem?
For real parallel light with orthographic projection, I found attila's version of Horde3D used for "Offroad Legends" (published in this thread:
viewtopic.php?f=1&t=1665). Unfortunately, the shaders used for this directional light hack have not been published.
Question to attila: How is the depth value for the shadow map computed?