Page 1 of 1

Demo: Deferred Lighting in OpenGL

Posted: Sun Oct 04, 2009 1:17 pm
by qpHalcy0n
This one is a quick & dirty demo of a typical fat-gbuffer approach to deferred lighting using OpenGL and GLSL.

By deferring the lighting until after the primary geometry passes, we are allowed the headroom to calculate a lambertian lighting equation many hundreds of times in screen space per frame. The practical limit for light count in this demo is about 2056. So you can have up to 2056 visible dynamic lights in the scene at any one time.

So we make a primary pass of scene geometry to the gbuffer. We render to two buffers at one time currently. We render the viewspace normal and surface depth to one target, and the diffuse color to the other. In a second pass we sort the lights based on visibility and whether the camera is inside the light or not, then we stream the lights in as simple boxes which are the size of the light radius. With this vertex format we also pass camera position, light position, light color, light radius, and attenuation parameters. As the lights are streamed in, the world in view space is reconstructed and the result is passed per pixel to the back buffer.

Because this is a pre-cursor to a proof of concept demo, this obviously does not make use of MSAA.


The source code and executable can be found at:
http://www.moogenstudios.com/wp-content ... ferred.rar


Single Point Light:
Image


Several hundred point lights:
Image

Re: Demo: Deferred Lighting in OpenGL

Posted: Sun Oct 04, 2009 4:31 pm
by Falco Girgis
Goddamn. You win, sir. I hope to screw around with it (try to learn some of it) when I get home.

Re: Demo: Deferred Lighting in OpenGL

Posted: Tue Oct 06, 2009 11:06 am
by MarauderIIC
On a general related note, you might be interested in http://www.bungie.net/Inside/publications.aspx#pub23083
Lighting Research at Bungie

Author: Hao Chen, Natalya Tatarchuk

Straight out of Siggraph '09, Hao Chen and Natalya Tartartuk talk shop on lighting research at Bungie. Their presentation focuses on high-quality real time lighting with advanced atmospheric rendering and continuous time of day, as well as efficient prefilterable soft shadows. It also takes a look at fast methods for generation of pre-computed global illumination using modern GPUs.

Re: Demo: Deferred Lighting in OpenGL

Posted: Tue Oct 06, 2009 12:01 pm
by qpHalcy0n
I've actually read that one. There's quite a massive number of indirect illumination papers out there. Instant radiosity proves to be the only real efficient method of doing indirect illumination in real time since it's very low frequency. That's actually where this next demo is going, there's actually code in there now that reads to and from flux buffers which will be used to generate the VPL's which will ultimately contribute to all of the indirect term.