We’re on the final home straight for Ogre 1.6 (aka Shoggoth), which should hit RC1 next week. One of the final features I wanted to squeeze in was support for Parallel-split Shadow Maps (PSSM), which uses multiple shadow maps per light in a hierarchical fashion to improve the quality while keeping the size down, particularly in outdoor scenes using global directional light. If you’ve played Assassin’s Creed, you will have seen this technique in action already.
For example, the screenshot on the right there is using 3 shadow maps for the single directional light, the closest one being 1024×1024, and the other two being 512×512 – together they are 38% of the size of a single 2048×2048 shadow map and yet provide greater detail. The 3 shadow textures are displayed for debug purposes on the right – notice that all 3 are using LiSPSM projection to bias the texture precision toward the camera which also helps. If you look really closely on the full resolution shot, you can see the transition from the highest resolution shadow map to the second shadow map about halfway up the screen, it changes near the top of the closest tree shadow. It’s quite hard to see though, which is kinda the point
One of the challenges with supporting PSSM is that Ogre had previously assumed that there is a 1:1 mapping between lights and shadow maps, which clearly had to be overcome – this limitation also prevented easy use of dual parabaloid and full cubic shadow maps for point lights of course. It was one of those things that had been languishing on my TODO for a while, begging me to find some time for it, and that’s where it still was until Pang Lih-Hern (aka lf3thn4d) from Malaysia came along and did it for me What a star! His initial patch allowed multiple shadow textures per light in a very sensible way, and he then implemented a PSSM facility on top of that, via our pluggable ShadowCameraSetup system (which he also extended in the patch to be aware of shadow map iteration). I adapted the PSSM code from his demo to be a little more flexible (it now handles any number of splits, and a more flexible split configuration) , so that setting it up goes something like this (simple projected shadows here, depth shadowmaps are also possible of course but let’s not overcomplicate it):
float shadowFarDistance = 3000;
mSceneMgr->setShadowTextureConfig(0, 1024, 1024, PF_X8R8G8B8);
mSceneMgr->setShadowTextureConfig(1, 512, 512, PF_X8R8G8B8);
mSceneMgr->setShadowTextureConfig(2, 512, 512, PF_X8R8G8B8);
PSSMShadowCameraSetup* pssm = new PSSMShadowCameraSetup();
pssm->calculateSplitPoints(3, mCamera->getNearClipDistance(), shadowFarDistance);
Notice that I used Integrated Shadows, this is a requirement of PSSM since only shaders with integrated shadow support can decide on the fly which shadowmap to sample from.
My sincere thanks to lf3thn4d for helping us get this feature in to Ogre 1.6 (and to all those who send us patches in fact). If you want to see it and OgreSpeedTree in motion, there is a video available; that’s the low-quality streamed version but you can also download the higher resolution version if you want.