Deferred Rendering – DirectX 11 (Updated w/ Shadows and Instancing)

Deferred Rendering means doing the rendering in multiple passes, generally doing the G-Buffer pass then the Lighting Pass.

In this implementation, I have done the Shadow Pass first then the G-Buffer and then the Lighting.
I decided to do it this way because the shadow implementation is only done for directional lights currently, and the resulting shadows are added to a shadow mask in the G-Buffer.
Another feature present is Instancing of the entities being rendered.

Shadow Pass
This is done by rendering the scene from the perspective of the light which is casting the shadow. Only the Depth Buffer is bound to the render target view. The output is rendered to a shader resource view which is used later while rendering the G-Buffer, where it is used to generate the Shadow Mask.

G-Buffer
Know as the Geometry Buffer, instead of rendering the output to the back buffer with all the lighting calculation done in forward rendering. The same procedure is followed but no lighting calculations are done and the output is rendered to an array of render targets which are attached to an array of shader resource views in addition to the depth/stencil buffer. The lighting calculation is left to the next stage.
The G-Buffer rendered here include Position Buffer, Normal Buffer, Diffuse Buffer, Shadow Mask Buffer(which is added to the alpha channel of the Diffuse Buffer) and the Depth Buffer.

Lighting Pass
The G-Buffer Textures are passed to Pixel Shader for the lighting calculations. The direct light calculations are done by rendering to a fullscreen quad and the point light calculation are done by rendering using a sphere mesh. All the lighting outputs are blended together to get the final frame.

Instance Rendering
Instancing means rendering multiple copies of the same mesh using the same material at once. This is helpful because it reduces the number of draw calls required to render all these copies to one draw call.
Here the 9 sphere entities are rendered using one draw call and the 3 quad entities are rendered with one call, so overall 12 draw calls are reduced to 2 draw calls.
This is used in both, Shadow Pass and G-Buffer Pass, so over the two passes, 24 draw calls are reduced to 4 draw calls.

1 thought on “Deferred Rendering – DirectX 11 (Updated w/ Shadows and Instancing)”

Leave a comment