Before we part, let’s talk about some issues and improvements related to deferred rendering.
Transparency
As we’ve seen before, transparent objects are a problem for a deferred renderer. The reason is obvious: since lighting is applied at the end, after everything is drawn, only the points closest to the camera will be lit. Thus, if we just let transparent objects be drawn, the objects behind them will be visible, but will not be lit correctly. The solution is to render all transparent objects after you apply the deferred lighting. They are drawn normally, using a forward renderer, and blended into the image resulted from the deferred render. The only inconvenience is that we need to use the depth buffer from the G-Buffer creation, so the occluded parts of transparent objects render correctly.
Post processing Effects
Deferred rendering goes along very well with post processing. The G-Buffer can be used for several post processing effect we all know and love, like Depth of Field, Glow / Bloom, Distortion, HDR lighting (for HDR, we can simply render the light map to a floating point texture instead of a Color texture, and use that as an input for HDR processing), Auto-Exposure, and others. Another category of effects that work well with deferred rendering are screen-space effect, like Screen Space Occlusion Mapping, Global Volumetric Fog, Fog Volumes, Soft Particles, Cloud Rendering, etc. These effect integrate well with the deferred renderer, and can take great advantage from the G-Buffer.
Shadows
For shadows, deferred rendering works very well with shadow maps. For directional and spot lights, these pose no problems. For point lights, we can use a cube-shadow map, or treat it as 6 spotlights. As optimizations, shadow maps do not need to be used for all lights. Some lights may not need to cast shadow. Many optimizations can be done here, but just remember that shadow maps are a good fit for deferred rendering.
Anti Aliasing
Anti aliasing is also a big problem of deferred rendering. But since HDR is not such a great friend with anti aliasing either (for now), this might not be such a big deal. If you do want AA in your renderer, there are some ways to do it. One way is to make an edge-detection pass, using the depth and normals from the G-Buffer. Then, as a post processing effect, blur the image based on the edges detected. This will remove somewhat the jagged lines which appear on the edges, and the whole image will have a smoother look. And when this is combined with some bloom, the result should be pleasing enough for the eyes.
Conclusions
In this article, we’ve covered the basics of implementing a deferred renderer in XNA. We saw how to add directional lights and point lights, and wrote a content processor to prepare models for the renderer. We’ve also discussed further improvements and possibilities for extension, like spot lights, shadows, a more complex material system, etc. From this point on, there are many things to experiment and to try, and the topic of deferred rendering is far from being exhausted, and I hope this article got some of you interested in it.
References:
1. Shawn Hargreaves, Deferred Shading
2. Shawn Hargreaves and Mark Harris, Deferred Shading
3. Michael Deering, Triangle Processor
5. GPU Gems 2 – Chapter 9 : Deferred Rendering in S.T.A.L.K.E.R.