In forward rendering, why Unity use multipass, instead of looping lights in shader?

In forward rendering, when there are multiple lights, Unity uses multiple passes.

“Base pass renders object with one per-pixel directional light and all SH/vertex lights. Additional passes are rendered for each additional per-pixel light that affect this object.” - from Unity documentation

I understand if lights are all done in a single pass, this pass will become super long and complicated, but other than that, is there any particular reason why Unity use multiple passes, instead of looping lights in a single shader pass?

Especially for per-pixel light, I feel one pass for each per-pixel light will cost lots of performance. For example. if there are eight per-pixel lights in the scene, that means eight draw calls.

I found this page is also talking about this:

https://computergraphics.stackexchange.com/questions/286/multiple-lights-shading-one-pass-vs-multiple-passes

It seems like it has something to do with the culling and shadow mapping, but I don’t quite understand what they are talking about.

Because Unity’s forward renderer was written over 7 years ago, not modern for desktop computers. Even the general thought in the industry the year or two Unity 5.0 came out was that deferred would be the dominant method of rendering for desktop and console, and forward rendering still needed to support OpenGL ES 2.0 devices for which a single pass lighting system doesn’t make as much sense for.

Going forward, especially with the popularity of >1080p resolutions and VR, single pass is making much more sense. Unity is currently working on a new rendering system that will plausibly completely replace the existing rendering paths with several new ones optimized for different platforms.

https://github.com/Unity-Technologies/ScriptableRenderLoop

2 Likes

That makes much more sense! Thank you!

In that case if the target is VR and I want to use forward rendering, I guess it would be better to write my own single pass shader.

There’s The Lab Renderer that Valve released which you can try using, or build off of.

1 Like

You can also try daydream renderer:
https://github.com/googlevr/daydream-renderer-for-unity

“Daydream Renderer doesn’t redraw objects for every light influence, which significantly reduces the total number of draw calls used.”

1 Like