I’ve been admiring and tweaking my new SSAO effect. Doing SSAO at half resolution and having high quality grass straws covering half the screen lead to the SSAO becoming an aliased, shimmering mess, AKA eye cancer. After working over the weekend on it, I finally got all 3 passes of the shader fast enough to be possible to do at full resolution, and the difference is HUGE. My goal was to get it down to 1-2ms at full resolution 1920x1080, and I managed to get it down to around 1.3ms, while at 2560x1440 I ended up at 2.1 ms… The best part is that the new shader has a million times better texture cache coherency. The old one would choke once it started sampling random pixels in a 25+ pixel radius around each pixel due to texture cache thrashing, but the new algorithm does some clever precomputation to the depth buffer to improve performance. Along with ALU optimizations to the shader as well, the new shader is over 2x faster compared to the old shader’s absolute best case, and 20-30x faster than its worst case. The bilateral blur shader also got a ~2x speed up thanks to simplifications of the algorithm and that I packed the SSAO value and the depth value it needed into a single texture to halve the number of texture samples. All in all, it works, and it looks gorgeous now that I don’t have a radius limit. But now to the pictures!
This is with SSAO off. When in the shadow of the sun, it gets extremely hard to see where things are and what shape they have. We can’t really see if the building is floating in the air or if it actually touches the ground. The corner right behind MORS (the character) is almost invisible due to the flat colors, and the only reason you guys even know there’s a corner there is thanks to the blue stripe following the wall. MORS himself also looks flat and boring. His legs are essentially just two shades of gray, and his arms also look extremely flat. The detail simply isn’t there when there’s no direct lighting to bring it out.
With SSAO, the scene gets a whole new level of depth. Not only is the vertical corner behind MORS clearly visible, we suddenly see an additional little horizontal crease to the bottom left of the building that was completely invisible before. The grass where the building stands is slightly darker too, showing that the building is indeed standing on the ground. MORS also looks significantly better. The area under his arms and around his neck and feet are significantly darker due to being occluded, bringing out a lot more detail in the lighting.
Of course, this effect is completely dynamic and isn’t precomputed in any way. It does have some limitations as it works on screen space information, e.g. the depth buffer. For example, the background as seen between his legs is too bright. His legs are simply blocking the information for the background occlusion to be detected, so there is no way to know if the background should be occluded or not. Still, the overall quality of the sceen is massively improved.