Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Keywords and UsePass

Discussion in 'Shaders' started by herufeanor, May 7, 2015.

  1. herufeanor

    herufeanor

    Joined:
    May 28, 2010
    Posts:
    33
    So I'm trying to build a shader that extends the Standard shader a little bit, adding a simple color overlay. So I wrote this shader:

    Code (csharp):
    1. Shader "EncounterMapLayer" {
    2.     Properties {
    3.         _Color("Color", Color) = (1,1,1,1)
    4.         _MainTex("Albedo", 2D) = "white" {}
    5.      
    6.         _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
    7.  
    8.         _Glossiness("Smoothness", Range(0.0, 1.0)) = 0.5
    9.         [Gamma] _Metallic("Metallic", Range(0.0, 1.0)) = 0.0
    10.         _MetallicGlossMap("Metallic", 2D) = "white" {}
    11.  
    12.         _BumpScale("Scale", Float) = 1.0
    13.         _BumpMap("Normal Map", 2D) = "bump" {}
    14.  
    15.         _Parallax ("Height Scale", Range (0.005, 0.08)) = 0.02
    16.         _ParallaxMap ("Height Map", 2D) = "black" {}
    17.  
    18.         _OcclusionStrength("Strength", Range(0.0, 1.0)) = 1.0
    19.         _OcclusionMap("Occlusion", 2D) = "white" {}
    20.  
    21.         _EmissionColor("Color", Color) = (0,0,0)
    22.         _EmissionMap("Emission", 2D) = "white" {}
    23.      
    24.         _DetailMask("Detail Mask", 2D) = "white" {}
    25.  
    26.         _DetailAlbedoMap("Detail Albedo x2", 2D) = "grey" {}
    27.         _DetailNormalMapScale("Scale", Float) = 1.0
    28.         _DetailNormalMap("Normal Map", 2D) = "bump" {}
    29.  
    30.         [Enum(UV0,0,UV1,1)] _UVSec ("UV Set for secondary textures", Float) = 0
    31.  
    32.         // UI-only data
    33.         [HideInInspector] _EmissionScaleUI("Scale", Float) = 0.0
    34.         [HideInInspector] _EmissionColorUI("Color", Color) = (1,1,1)
    35.  
    36.         // Blending state
    37.         [HideInInspector] _Mode ("__mode", Float) = 0.0
    38.         [HideInInspector] _SrcBlend ("__src", Float) = 1.0
    39.         [HideInInspector] _DstBlend ("__dst", Float) = 0.0
    40.         [HideInInspector] _ZWrite ("__zw", Float) = 1.0
    41.  
    42.         // Extra color map
    43.         [HideInInspector] _TileColorMap("Tile Color", 2D) = "white" {}
    44.     }
    45.  
    46.     CGINCLUDE
    47.         #define UNITY_SETUP_BRDF_INPUT MetallicSetup
    48.     ENDCG
    49.  
    50.     SubShader {
    51.         Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
    52.         LOD 300
    53.  
    54.         UsePass "Standard/FORWARD"
    55.         UsePass "Standard/FORWARD_DELTA"
    56.         UsePass "Standard/ShadowCaster"
    57.         UsePass "Standard/DEFERRED"
    58.  
    59.         Pass {
    60.             Blend DstColor Zero
    61.             SetTexture [_TileColorMap] { combine texture }
    62.         }
    63.     }
    64.  
    65.     SubShader {
    66.         Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
    67.         LOD 150
    68.  
    69.         UsePass "Standard/FORWARD"
    70.         UsePass "Standard/FORWARD_DELTA"
    71.         UsePass "Standard/ShadowCaster"
    72.  
    73.         Pass {
    74.             Blend DstColor Zero
    75.             SetTexture [_TileColorMap] { combine texture }
    76.         }
    77.     }
    78.  
    79.     FallBack "VertexLit"
    80.     CustomEditor "StandardShaderGUI"
    81. }
    I use the UsePass to avoid duplicating any more of the Standard Shader than I have to. Unfortunately, when I do this, the normal mapping turns off. My best guess as to why is that the "_NORMALMAP" keyword somehow doesn't propagate through UsePass.

    If I copy all of the passes into my shader directly, instead of using UsePass, then the normal mapping starts working again. That'll work, but I'd rather not do that if I don't have to.
     
  2. Jick87

    Jick87

    Joined:
    Oct 21, 2015
    Posts:
    124
    This is an old post, but I came across something that may be relevant here and it seems to be the only post that I can find which is related to this issue, so I figured I would post here...

    So, it seems if you change "Standard/ShadowCaster" to "Standard/SHADOWCASTER" it suddenly starts to work the exact same as the Standard shader. So it seems it is an issue related to capitalization even though this is not documented anywhere (that I can find) and it is NOT even capitalized in the Standard shader code where it is defined.

    Anyway, that is just something I discovered. Hope it might help someone else.
     
    denisvefire likes this.
  3. warreneng

    warreneng

    Joined:
    Mar 13, 2017
    Posts:
    8
    UsePass requires you to use ALL CAPS when specifying the pass name, no matter the casing of the actual pass. This quirk is barely documented at the bottom of its manual page:
    https://docs.unity3d.com/Manual/SL-UsePass.html

    Note that internally all pass names are uppercased, so UsePass must refer to the name in uppercase.
     
    Jick87 likes this.