The OpenGL 4 renderer for Leadwerks 3.1 is well underway. I began implementing deferred lighting in earnest last Friday. Previous work included setting up MSAA on deferred buffers, as well as implementation of the Leadwerks Buffer class, which functions as a thin wrapper around OpenGL FBOs (frame buffer objects). The engine already tracks relationships between objects and lights, and this system was able to be used to provide a list of shadow-casting objects for each point and spot light.
Because I've been working with deferred rendering since 2008, I've had time to study the bottlenecks and invented my own optimizations to improve performance with this type of renderer. Leadwerks uses special proprietary techniques to make shadow map rendering extremely fast.
I began with the simplest light type, a spot light. These use a perspective projection onto a single shadowmap. This took about two days to implement.
Point lights work by projecting six images onto a cubemap shadowmap. This was a little trickier but I got it done after another two days:
The hardest to implement was directional light shadows. We began using cascaded shadowmaps back in 2008, and the industry has since concluded they are in fact the best choice for performance and quality. It took a few extra days to get this one working, but now it's done:
This video is a very nice illustration of the technique:
And here is my implementation in action. With just a little more adjustment, it will be perfect:
The Leadwerks 3.1 deferred renderer has a number of advantages over the Leadwerks 2 renderer:
- Deferred renderer can now use 32x hardware MSAA instead of "fake" antialias techniques.
- Shadow edge filtering is much softer, less "grainy".
- Cubemap shadow maps are used to render point lights in a single pass.
- Higher default resolutions and settings to take advantage of modern hardware.
These factors combine to provide an extremely clean and beautiful rendered image. When I'm done, I think the Leadwerks 3.1 renderer will look more like high-quality cg than what we think of as real-time renders.