4

If it's forward rendering, then the number of times FS executes is the (numberOfAllPixels * numberOfLights), and if it's deferred rendering, then the number of times FS executes is the (numberOfVisiblePixels * numberOfLights).

So if I add early-z to the forward rendering, then the number of times FS executes also becomes the (numberOfVisiblePixels * numberOfLights), so isn't there any advantage to deferred rendering?

  • What you mean by "numberOfAllPixels" is actually the number of fragments generated during the render pass, and "numberOfVisiblePixels" is just the number of pixels of your framebuffer. But the "if it's deferred rendering, then the number of times FS executes is the (numberOfVisiblePixels * numberOfLights)." is a wrong assumption. One main point of deferred is to be using some light volume geometries to render the light only where it can have any effect. If you have many lights which all affect the whole screen, deferred will kill you by bandwidth usage much more than overdraw will in forward. – derhass Sep 25 '20 at 16:41

1 Answers1

4

In forward rendering, you have to re-render the entire scene a bunch of times. In deferred rendering, you render the scene once and that's that.

Re-rendering the entire scene means re-doing a bunch of work, including but not limited to:

  • CPU processing of the scene. That is, walking the scene graph and issuing rendering commands.
  • GPU processing of state changes between drawing commands..
  • GPU reading vertex arrays for meshes.
  • Vertex shader execution.

All that only has to happen one time in deferred rendering.

And don't forget that "early-z" isn't free. Not only do those triangles have to be generated, but they have to be rasterized too. They have to get far enough into the processing pipeline that they can be culled. It's not a huge deal, but it's not nothing either.

So yes, a depth pre-pass in forward rendering means you're only running the FS when absolutely necessary. But you're still running a whole bunch of unnecessary stuff.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • Why do you have to re-render the entire scene a bunch of times? Do you mean once per light? If so you can pass an array of lights as a uniform, and iterate though the lights in the fragment shader. – tuket Sep 25 '20 at 12:03
  • @tuket: Yes, you can. But the premise of the question is: "the number of times FS executes is the (numberOfAllPixels * numberOfLights),*" If that's the case, then that means you're rendering the entire scene for each light, which is the common-yet-silly way of presenting forward rendering. – Nicol Bolas Sep 25 '20 at 13:26
  • If you were iterating the array of lights in the fragment shader, it would be `numberOfAllPixels * numberOfLights`. If rendering the whole scene for each light, you would be repeating the vertex transformation for each light too, so it would be `numberOfLights * (numberOfAllPixels + numberOfVertices)`. – tuket Sep 25 '20 at 14:57
  • @tuket: The premise of the question is "***the number of times FS executes***" Not "number of loops within an FS execution" or "number of vertex transformations" or whatever. The point of my answer is to draw the OP's attention away from "the number of times FS executes" and see how other things are affected. – Nicol Bolas Sep 25 '20 at 14:59
  • Ah, okay, that makes sense – tuket Sep 25 '20 at 15:03