Search Unity

Deferred Shading + Surface shader finalcolor

Discussion in 'Shaders' started by glitchers, Jun 24, 2015.

  1. glitchers

    glitchers

    Joined:
    Apr 29, 2014
    Posts:
    64
    Hi,

    I am trying to use the finalcolor modifier (source) with the Deferred Shading rendering path but it doesn't work. When I swap the rendering path to Forward it works as expected.

    Is there something else I have to do to get this working for Deferred or is this a bug?
     
  2. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    593
    Late answer but in case someone else stumble upon this issue: just tested in Unity 5.1.2, the finalcolor modifier function is only called in the Forward passes in the generated shader, so they will just not work in Deferred (presumably because Deferred has several outputs colors for each RT buffer instead of just one color).

    You can always make it work by forcing your shader to be in Forward while other assets in your scene use Deferred, if that's an option, using exclude_path:deferred in the #pragma surface line.

    A nice fix from Unity could be a final color modifier for deferred for each of the RT buffers, something like
    Code (shader):
    1. void endcolor(Input IN, SurfaceOutputStandard o, inout half4 outDiffuse, inout half4 outSpecSmoothness, inout half4 outNormal, inout half4 outEmission)
    EDIT: Just found this in Unity 5.2 release notes:
    :)
     
    Last edited: Sep 14, 2015
    glitchers likes this.
  3. Deleted User

    Deleted User

    Guest

    Sorry for necro, but I ran into this.

    Am I right in understanding this is purely related to Unity's provided function and when it is executed in relation to the pipeline, due to how a surface shader is generating the code? If I write my own simple vertex/fragment shader function, generally this wouldn't be an issue - outside of trying to do stuff that relies on deferred directly, yeah?
     
  4. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    593
    Yes, final color modifier is a surface shader thing (see Custom modifier functions on the surface shader help page), so if you write a vertex/fragment shader you don't need to worry about it, even if you're working with deferred.