Search Unity

Feature Request Shader Graph design oversight? ( blend modes )

Discussion in 'Shader Graph' started by brn, Aug 27, 2021.

  1. brn

    brn

    Joined:
    Feb 8, 2011
    Posts:
    320
    Opening up for discussion and wanted to highlight a possible oversight about the blend mode functionality in Shader Graph.

    When certain blend modes are specified SG sets defines that I can see would be helpful for 90% of developers to mask the complexity of the blend mode functionality and force a result that would be "expected" by the majority.

    Unfortunately this means when you want to use the underlying properties of the blend type its becomes convoluted. Resulting in having to hand edit generated SG shaders with all the knock on effects of doing so.

    As an example here are some snippets from a shader that uses the Pre-Multiply blend mode.

    From a generated SG shader
    Code (CSharp):
    1.   // Defines
    2.             #define _SURFACE_TYPE_TRANSPARENT 1
    3.             #define _ALPHAPREMULTIPLY_ON 1
    4.             #define ATTRIBUTES_NEED_NORMAL
    5.             #define ATTRIBUTES_NEED_TANGENT
    6.             #define FEATURES_GRAPH_VERTEX
    7.             /* WARNING: $splice Could not find named fragment 'PassInstancing' */
    8.             #define SHADERPASS SHADERPASS_UNLIT
    9.             /* WARNING: $splice Could not find named fragment 'DotsInstancingVars' */
    From Lighting.hlsl
    Code (CSharp):
    1. #ifdef _ALPHAPREMULTIPLY_ON
    2.     outBRDFData.diffuse *= alpha;
    3.     alpha = alpha * oneMinusReflectivity + reflectivity; // NOTE: alpha modified and propagated up.
    4. #endif
    From this example you can see how this blend mode is forces the multiply of the RGB in a black box fashion.
    Looking at the SG and SRP library's its littered with these defines trying to catch every permutation.

    From my current perspective this could be avoided by enabling us to either set defines from SG with key points for insertion. eg Pre or Post SG generated defines.

    A better option would be to removing the majority of the places that the defines are utilized (except where lighting factors are important ) and provide a node to do the exact same code for the "90%" just before the Master Stack. This would be visible to the developer and enable others that wish to get the most out of the blend modes to do so.
     
    arkano22 likes this.