Deferred Shading + Surface shader finalcolor

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?

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

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:

:slight_smile:

1 Like

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?

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.