Deferred Shading

Update:
Add normal mapping

///////////////////////////////////////////////////////////////// I used one direction light with direction (-1,-1,-1) and randomly generated 3000 point lights as lights. There are twenty spheres in this scene. Actually half of the spheres and the point lights are moving from bottom to top and repeat. Of course the shadow is here. I don’t implement sponza’s(the building) shadow because this so big that if it has a shadow you can’t clearly see the spheres’ shadow. Just the direction light produces shadow because of the performance of graphics card. I also implemented a movable camera to inspect my scene like this. In addition, I used PCF to smooth the shadow. The lighting calculation uses Bling-Phong formular.

There are four render passes: shadow pass, offline pass, lighting pass and deferred pass.

Shadow pass:

Render the depth buffer of the 20 balls.

Offline pass:

Render G-buffers, including position buffer (actually a z buffer), normal buffer, diffuse color buffer and
specular color buffer.

Lighting pass:

It’s a high-performance way to render 3000 lights and can render more. I rendered 3000 lights with about 200 fps in Debug Configuration. (my graphics card is GTX1070). The way is instead of rendering each pixel with each light, rendering points lights as sphere, and check if the pixel in same texture coordinate is in the sphere. If yes, do the lighting calculation, else pass. All lighting result will render at the same render target, that means opening color blending. I learned this from https://learnopengl.com/Advanced-Lighting/Deferred-Shading. It called the way ‘Light Volumes’.

Deferred pass:

Using the G-buffers to do the shadow calculation and direction lighting calculation, add an ambient color. Finally add the color to the render target that the lighting pass used. That’s all.

Normal Buffer

World Position Buffer

Depth Buffer

Limit position of point lights