It’s been a while, hasn’t it? I’ve been pretty busy trying to look for a job, then maintaining my freelance work on top of other things, but I still try to keep my programming skills sharp. This past week I opened up my XNA projects again and they are still fresh in my mind.
Removal of shadow flickering and swimming
In fact, with my mind so cleared up I finally resolved two problems that have plagued my shadow mapping code for so long. The first problem I resolved in an hour- it had to do with the shadow maps “tearing” between the cascade splits. Those portions would either be completely dark or filled with parallel lines. In other words, a glitchy mess. Originally, I went with using different near-far distances to generate each map, but they were misaligned if viewed from certain angles. Such was the case for parallel-split maps. So I decided to just go with traditional cascaded shadow mapping by making the near distance the same for all the splits.
This means that while some pixels are wasted for the farther cascades, it guarantees that there will always be overlap between them. The tearing is now gone! The next problem is a little less distracting but still something I always wanted to fix, and it’s the “swimming” of the texture shadows when the camera moves. The texels always move quickly and noticeably. Fortunately J. Coluna had the solution in his LPP demos, which he in turn took from a website he couldn’t remember. Fair is fair, so I used the code as well.
After a surprisingly few changes to the code, I removed the swimming effect. The camera for each light is set to move in texel increments, so movements stay “snapped” to an invisible grid. Shadows suddenly look a lot cleaner despite still using the same filtering technique.
Cascade shadow blending
One more trick was added to make the shadows look nicer in motion. CSM usually shows visible seams that divide each cascade, and they also pop in and out noticeably when moving the camera farther away. With the shadow maps now overlapping each other, it is possible to remove the seams that occur from changing different levels of shadow detail for each distance. I decided to start the blending at 85% of the distance between the near and far points of each split. This creates a smooth linear transition between the maps. The below image shows the effect of blending the cascades together, each color representing a different shadow map.
I have uploaded these changes in the latest build of the Meteor engine, available on CodePlex. There may be some more updates on it, but I don’t foresee doing any more notable changes to the shadows for directional lights.
Between this and Bubble Tower, I’m slowly converging the two projects together in a way that makes them more practical. It’s also a great way to test the Meteor Engine in a real project. As you may know, the game uses a screen management system and I wish to keep this engine self-contained in one of the screens. I have been finding more limitations to the engine that are going to be resolved in order to make it work in a more flexible manner with the game code. More on that later.