What's The Difference?
Forward Rendering: Every object is drawn with a lighting shader of some sort, where the lights are passed in to the shader via uniforms.
- Easy to set up
- Each object can have its own shader
- Limited by hardware
Deferred Rendering: Every object is drawn to multiple surfaces that store the diffuse, normal, depth, specular, etc. of the objects, then the lights are drawn as ellipsoids, using the surfaces to correctly light the scene.
- Fast, 100s of lights
- Not limited by hardware
- Can't handle transparent objects
- Every object has to use the same shader
Here's a demo with 100 point lights, which are drawn as ellipsoids and use texture look-ups to reconstruct the scene. Commented-out code is included for axis-aligned normal mapping, specular mapping, and (currently broken) screen-space ambient occlusion.
Update 1.1: Added an extra pass for ambient lighting, so separate ambient values can be set for each model. This could be included in the specular pass as one of the channels, but the demo is designed for flexibility over performance.
Update 1.2: Fixed some variable names and cleaned up some code.
Here's a demo with 4 point lights, passed in using arrays. You can have as many lights as you want, depending on hardware, but the problem is, forward rendering is fairly slow.
Edited by jsorgeagames, 15 August 2013 - 07:11 AM.