- Home /
Mixing Deferred Lighting and Forward rendering paths
Unsatisfied with both Deferred Lighting (since it has no anti-aliasing) and Forward rendering (which can only support a limited number of lights), I am trying to use two cameras: one for the bulk of my many-light-lit background scenery (Deferred Lighting), and then a second camera for my lots-of-sharp-edges foreground items (Forward rendering, anti-aliased).
This works as-expected if the second (Forward) camera has Clear Flags of Depth Only, but of course the foreground objects do not go behind anything in the scenery.
But if I set the second (Forward) camera Clear Flags to Don't Clear, it's as if the depth buffer is never cleared. i.e. as if Deferred Rendering does not clear the depth buffer, or is using a different depth buffer.
To "solve" this, I added a third camera, rendered before the other two that just paints to the depth buffer. This works, but seems rather overkill (I'll only be enabling this at quality levels Beautiful and Fantastic).
Has anyone had any better luck mixing the two rendering paths to get the best of both worlds?
I'm pretty sure the deferred rendering pass needs the depth buffer information for some effects. So you think the deferred rendering pass should clear the buffer once it is done? I'm not sure I'm following your assumptions.
No, it should leave the depth buffer correct for the next camera. The Clear Flags should dictate what happens before the render. I strongly suspect that DR doesn't use the same depth buffer at all, since my "fix" has no effect on DR (my #2 DR camera even has a solid color Clear Flag, yet the camera #1 depth buffer is still there once the Forward #3 camera renders).
Answer by Waz · Jul 26, 2011 at 11:45 PM
While not really an "answer", I have found that the performance loss and the loss of shadows by using two cameras (three, thanks to the depth buffer problem) is not worth it just to get AA.
Instead, I am using, and recommend, using FXAA in Unity to get AA in Deferred Rendering.
Answer by Admiral_Face · May 30, 2014 at 12:30 AM
You have discovered an excellent solution, but it does lack shadows. If only Unity supported deffered lighting rendering, rather than just deffered rendering, then you could add all the MSAA you wanted. I do hear there are some Anti Aliasing compatibility bits you could use to force SGSSAA to take care of vegetation jaggies, this combined with SSAA image effect would eliminate most Jaggies, but would still not look as good as traditional 8xMSAA.