Deferred Shading

Contents
Forward shading, while being easy to understand and implement, is quite heavy on performance. Consider scenarios below that depict limitations of forward shading:
- For a scene with a high depth complexity, forward shading tends to waste a lot of fragment shader runs as fragment outputs are overwritten.
- For a scene with multiple lights, lighting calculations are performed for every geometry in the scene for every light.
Deferred shading overcomes these issues with a different rendering technique.
I implemented this project for the CS-562: Advanced Real-Time Rendering Techniques coursework I took during my time at DigiPen Institute of Technology.
The renderer for the project was written using C++, OpenGL, and GLSL.
1 An overview of the technique
Deferred shading consists of two passes:
- Geometry Pass: In this pass, we render the scene once and store all kinds of geometric information from the scene into a collection of textures collectively known as the G-Buffer. These textures can store information such as vertex positions, color information, normal vectors, and more.

Contents of G Buffer at the end of Geometry Pass
- Lighting Pass: The geometric information stored in the G-Buffer is then retrieved later for use in lighting calculations in this second pass. In lighting pass, we render the scene with a FULL SCREEN QUAD, and perform lighting calculations for each fragment using the information stored in G-Buffer. At this point, it should be noted that by the time information is written into the G-Buffer, the depth test has already been performed. Therefore, any fragment that ends up in the G-Buffer is the actual fragment information that will be finally displayed for the screen pixel. Thus, for each screen pixel that is processed in the lighting pass, lighting calculations are performed only once.
2 Results
Deferred shading can provide significant optimizations for a scene with many lights. This allows us to render scenes with hundreds or even thousands of lights with an acceptable framerate, something which would not be possible with forward rendering.

Scene depicted with positions of 3578 point lights


