Deferred Shading
Update:
Add normal mapping
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