Recent Blender builds that can be downloaded from GraphicAll.org or BuildBot support Buffer Shadows for Sun Lamps. This feature allows to have just one lightsource to cast Buffer Shadows on a significant part of the scene while “following” the main character. The Sun’s parallel lightning insures that casted shadows are not morphing in relation to the distance from the lightsource.
To reserve performance a Shadow Map resolution of 1024 seems to be fine. But in order to cast shadows on objects that are from a reasonable distance to the main character, the Frustum Size has to be set higher. Setting the Buffer Type to Variance will even reduce the resolution to half its size. So this will result into some nasty edge flickering during gameplay.
If only it would be possible to move the Sun with the player with increments of exactly the size of one Shadow Map pixel. I’ve given it some thought and wrote BSMOC.py to try to solve this problem. The application of the final script can be tested in scene “TEST”.
I don’t know much about how the Blender Shadow Map itself is calculated, but I guess scene “BSMOC” almost represents what is happening with the Shadow Map when the Sun is facing the character on an angle. The higher the angle, the higher the Shadow Map Size becomes. So aside of the Sun’s Frustum Size, also the Sun’s Rotation will be a factor in the Buffer Shadow Map Offset Calculation.
To see the script in action you need a Blender build. I’m using “blender-2.63-r47000-win64” at the moment. When tested it seems not to be perfect yet. I expected no moving pixels whatsoever. I think the math is okay, but have some doubts about my interpretation of the process of the Blender’s Shadow Mapping. Also bear in mind that this script tries to fix the edge flickering of shadows casted from stationary objects to stationary objects. Moving objects, such as the player, will produce (even more) flickering. But the lather is not really an issue to me, since motion is envolved.
So anyone is welcome to make suggestions, corrections, remarks. Else, I hope someone found this a bit useful.
BSMOC.blend (114 KB)