Search Unity

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

Discussion in 'General Graphics' started by bobozzz, May 15, 2017.

  1. bobozzz

    bobozzz

    Joined:
    May 27, 2015
    Posts:
    38
    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.stackexcha...le-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.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    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
     
    bobozzz and neoshaman like this.
  3. bobozzz

    bobozzz

    Joined:
    May 27, 2015
    Posts:
    38
    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.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    There's The Lab Renderer that Valve released which you can try using, or build off of.
     
    bobozzz likes this.
  5. pancymon2

    pancymon2

    Joined:
    Nov 15, 2016
    Posts:
    1
    Last edited: Aug 31, 2017
    fffMalzbier likes this.