SunLamp Buffer Shadows

Hi folks,

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.

Attachments

BSMOC.blend (114 KB)

The math wasn’t that good after all. It made some stupid mistakes. So I changed the code.


...
    if not (tranZx and tranZy):
        tranZ = sunSize
    elif not tranZx:
        tranZ = sunSize/tranZy
    elif not tranZy:
        tranZ = sunSize/tranZx
    else:
        tranZ = sunSize/math.sqrt(abs(tranZx*tranZy))
...

This doesn’t change the fact that the code to “get the map deformation” is faulty. Only a sun rotation of [20,20,0] or [-20,-20,0] seems to work. What am I missing here? :spin:

Attachments

BSMOC2.blend (114 KB)

Okay, so it seems that I have a better computer performance than I thought. My laptop has two graphics cards, one internal, the other is a nvidia Geforce GT 840M, which is supposed to be one of the better ones on the market. But I didn’t found out until today that I had to manually enable this card for programs such as Blender. I feel stupid. No I’m able to set the Buffer Shadow Map Size way up to 10240 and with a Frustum Size of 100 I don’t have to worry. The script I’ve been trying to write seems totally redundant now, if you’re having a better graphics card, that is. So, I’m very sorry for wasting your time reading this thread. I’m totally embarrassed. I’ve checked this to be SOLVED.

B.T.W. I came to notice this after reading an article of Moguri. Quite interesting blog.

Yeah, I got a new graphics card myself a while ago. Took a bit of messing about to get it to work correctly - the difference between an integrated graphics chip and a true graphics card is extreme. Anyway, glad to see the issue solved.