Deferred Shading

Here’s another neat rendering technique. This one is called Deferred shading. The idea with this one is that instead of rendering and calculating lights while you rendering your geometry; instead, you render out relevant spacial information about the geometry to the Render TOP. For example you output the position, the normal, the UV, the shininess of the material, the diffuse color of the material to the Render TOP instead. You do this using floating point color buffers, and multiple render targets. (since a single color buffer can’t hold all of this information)

Then using this information you can apply a light to the scene as a post process. The benefits of this are:

  1. There is no limitation (except for speed) of the number of lights you can use. In a normal render you’d be limited to 3-7 lights (depending if they are point or spot lights).
  2. Greatly increasing the geometry in the scene will still result in the exact same lighting cost as simple geometry. This is because the light cost is calculated by ((widthheightcomplexity of light shader) in this technique. Adding more geometry to the scene doesn’t change any of those values. The technique is particularly useful in scenes with a large amount of overdraw (look into the wiki for an article on overdraw).
    It’s use is of course situational, but a useful idea to have in your pocket in case the need arises.
    DeferredShading.toe (6.15 KB)

thanks a lot for that example Malcolm. very useful

Instead of having a separate TOP for each light, is it also possible to add all the lights in a single TOP? If yes, will it be slower/faster?
This does not work well with transparent objects, does it?

Also, it would be nice if everybody could post the FPS they get with this file
I get 21fps with a 7800GT
So I’m gonna need a new card soon

Ya this technique is poor with transparent objects, but there are some workarounds.
You could definitely merge the GLSL TOP shaders together so you do multiple lights per pass, and yes it’d be faster. I just left them split out to make it easier to see whats happening.

Thanks Malcolm,
it’s definitely easier to follow with each light split to a separate TOP. Having an example which does it in one TOP would be great one day.

If you find some time, could you also please elaborate on the transparency workarounds?

I’ve never actually tried to implement the workarounds, just seen them mentioned in a few articles. Your best bet is to google deferred shading and find papers on it for the workarounds.

will do. thx

Is these techniques also ussefal ive you would like to project a Gobo ore picture? There is no shadow techniques?

These is a Example about the idea that I have to create. A lot off light fixtures that creates a volumetric light beam and the possibility to project lights on the 3d model. Whit ore whiteout a gobo.
IMG_0116.JPG

Hey there!

I’ve been playing around with this a bit. I have a question though about how to deal with anti-aliasing. It seems to me that using this method makes anti-aliasing difficult, but I also don’t fully understand how anti-aliasing works on renders. Is there a way to get it back and still use deferred shading? You can see in my example that anti-aliasing the initial render yields artifacts because of the way the different buffers need to be used in the lighting pass.

I’m attaching a file that is a sort of hybrid that uses the deferred technique but is actually still using light COMPs in a post render ( of a flat tile using a GLSL mat) to take advantage of the built in lighting functions. This doesn’t get around the lighting limit though since its still specifying light COMPs in a render, but I think it is faster still.
deferredTests.2.toe (15.1 KB)

The best way now would be to not antialias in your main render, do all your deferred rendering work and then use the Anti-Alias TOP at the end to apply anti-aliasing.

Hey guys!

I was trying to run that last example in a non-commercial version of TD 099, but it doesn’t work. What do you think might be the case? I’ve found no errors in the network apart from the textures being limited by non-commercial resolution.
http://i.imgur.com/Lx1kAbI

That last example "deferredTests.2.toe "works fine here. Using 099 2016.1360
deferred-099.jpg
What are your system specs?

Not working on macOS because of a few things. First the GLSL version of the shader, I changed that to 3.30 and then a few declarations must be changed. After that the Render TOP still doesn’t render the scene correctly (unless you switch to Cube Map rendering for some reason) so I’ll submit this part as a bug.

Thanks

I’ve been playing with this and had help from Mike Walczyk to iron out another example of this technique. Figured I’d share with this crowd as it’s pretty nifty.

github.com/raganmd/learningGLSL … d_lighting

The Practice tox has a flattend look at the process with comments - left to right.

Oh yes! this is very cool, thx mat