Page 1 of 2

Deferred Shading

PostPosted: Wed Jun 18, 2008 6:36 pm
by malcolm
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 ((width*height*complexity 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.

Re: Deferred Shading

PostPosted: Thu Jun 19, 2008 2:54 am
by Achim
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

Re: Deferred Shading

PostPosted: Thu Jun 19, 2008 12:26 pm
by malcolm
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.

Re: Deferred Shading

PostPosted: Thu Jun 19, 2008 1:47 pm
by Achim
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?

Re: Deferred Shading

PostPosted: Thu Jun 19, 2008 1:58 pm
by malcolm
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.

Re: Deferred Shading

PostPosted: Thu Jun 19, 2008 2:10 pm
by Achim
will do. thx

Re: Deferred Shading

PostPosted: Tue Feb 18, 2014 6:35 am
by OMD
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.

Re: Deferred Shading

PostPosted: Thu Sep 10, 2015 10:18 pm
by archo-p
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.

Re: Deferred Shading

PostPosted: Fri Sep 11, 2015 11:09 am
by malcolm
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.

Re: Deferred Shading

PostPosted: Fri Feb 03, 2017 8:27 am
by yeswecan
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
Image