Search Unity

Hot to get multiple lights info in one shader?

Discussion in 'General Graphics' started by yu-wan, Apr 22, 2017.

  1. yu-wan

    yu-wan

    Joined:
    Jan 4, 2016
    Posts:
    18
    I'm currently doing a hair rendering component, splitting the rendering process into opaque and transparent.
    When doing the transparent part, I'm trying to use forward lighting to render with multiple lights.

    In first pass, LightMode = ForwardBase, Blend Mode:[One, OneMinusAlpha] (pre-multiply alpha), the second pass: LightMode = ForwardAdd, Blend Mode:[One, OneMinusAlpha].

    The problem is: the result will be too dark compared with opaque part of hair because the ForwardAdd pass is [One, OneMinusAlpha]. The delta light is not actually 'add' to the last rendering result.

    When switch the blend mode into [One, One], it become too bright in the part where multiple hair patches overlap since although the delta light result 'add' to the last pass's result, but it's not correct to blend with the pixel of this pass itself.

    Now I think the only approximately correct way is: just using a single pass with [One, OneMinusAlpha] (pre-multiply alpha) with all lights' calculations.

    In UNITY, we know the engine sort all lights info per object when rendering by importance and intensity.
    In LightMode = ForwardBase and ForwardAdd, you are not able to get all lights info as it's restricted by UNITY.
    In LightMode = Vertex, unity_LightPosition[] can get but the lightMode does not support most per-pixel effects: shadows, normal mapping, light cookies, and highly detailed specular highlights are not supported.

    Is it possible for me to get multiple lights info in one shader?
    Or any workaround for my hair patch transparent rendering? Many thanks.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    Yes, it is possible, by completely replacing Unity's lighting system and shaders with you own. See Valve's The Lab Renderer, or check out the work Unity is doing with Scriptable Render Loops using Unity 5.6 or the 2017 beta which may replace Unity's existing renderers someday.
     
    Misnomer likes this.