Search Unity

Help with finalgbuffer (new finalcolor)

Discussion in 'Shaders' started by hausmaus, Apr 20, 2016.

  1. hausmaus

    hausmaus

    Joined:
    Dec 9, 2011
    Posts:
    105
    Does anyone have any working examples of how to use finalgbuffer with the source vert/frag version of the Standard Shader?

    I would like to be able to completely override the pipeline output to force a solid color with no emission-based side effects. Think of the effect in old-school top-down shooters when something gets hit and flashes white a couple times. I'd prefer not to resort to a shader swap since the PBR shader has the dynamic emission and such which would probably look weird popping in and out. I'll probably end up drawing the mesh again with special effects shaders, but I wanted to try this first.

    I did get the #pragma finalgbuffer to work in the surface shader version of the standard shader, but it doesn't override shadows (I guess it affects the pipeline earlier than finalcolor did back in the Forward Path days), and it is missing quite a lot of functionality from the full version of the shader and it seems awkward to replace all of that rather than just get the vert/frag version to work.

    What I tried doing was downloading the source of the vert/frag version, and modifying the main deferred block as follows:
    Code (CSharp):
    1. // ------------------------------------------------------------------
    2. //  Deferred pass
    3. Pass
    4. {
    5.     Name "DEFERRED"
    6.     Tags{ "LightMode" = "Deferred" }
    7.  
    8.     CGPROGRAM
    9.     #pragma target 3.0
    10.     // TEMPORARY: GLES2.0 temporarily disabled to prevent errors spam on devices without textureCubeLodEXT
    11.     #pragma exclude_renderers nomrt gles
    12.  
    13.     // -------------------------------------
    14.     #pragma shader_feature _NORMALMAP
    15.     #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
    16.     #pragma shader_feature _EMISSION
    17.     #pragma shader_feature _METALLICGLOSSMAP
    18.     #pragma shader_feature ___ _DETAIL_MULX2
    19.     #pragma shader_feature _PARALLAXMAP
    20.  
    21.     #pragma multi_compile ___ UNITY_HDR_ON
    22.     #pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
    23.     #pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
    24.     #pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON
    25.  
    26.     #pragma vertex vertDeferred
    27.     #pragma fragment fragDeferred
    28.  
    29.     #include "UnityStandardCore.cginc"
    30.  
    31.     // Adding finalgbuffer
    32.     #pragma finalcolor:finalGBuffer
    33.     void finalGBuffer(
    34.         VertexOutputForwardBase IN,
    35.         SurfaceOutputStandardSpecular o,
    36.         inout half4 outDiffuse : SV_Target0,            // RT0: diffuse color (rgb), occlusion (a)
    37.         inout half4 outSpecSmoothness : SV_Target1,    // RT1: spec color (rgb), smoothness (a)
    38.         inout half4 outNormal : SV_Target2,            // RT2: normal (rgb), --unused, very low precision-- (a)
    39.         inout half4 outEmission : SV_Target3            // RT3: emission (rgb), --unused-- (a)
    40.     ) {
    41.         outDiffuse = half4(0, 0, 0, 1);
    42.     }
    43.     ENDCG
    44. }
    Separately, I tried adding some shader properties and modifying the StandardShaderGUI to create a new Editor UI for the custom version of the shader, and then inlining UnityStandardCore.cginc and just verifying that everything works, and it does.

    It really just seems that #pragma finalcolor:<functionName> doesn't work in that setup. Is there another way to do that?

    I'd hate to give up and resort to a blit of some kind since I've poured a bit of time into this now and I really miss the finalcolor functionality!

    Thanks for any advice!
     
    Last edited: Apr 20, 2016
  2. David-Lindsay

    David-Lindsay

    Joined:
    May 20, 2009
    Posts:
    121
    I didn't want to necro this thread, but having exactly the same problem. Deferred render pipeline is overriding the finalcolor functionality. I wonder if Unity can provide a workaround with the new customizable rendering pipeline?
     
  3. David-Lindsay

    David-Lindsay

    Joined:
    May 20, 2009
    Posts:
    121
    I found a functionality called finalgbuffer, it seems to work as expected! Necro-ed thread solved