Search Unity

Changing material (Instance) properties has no effect [URP]

Discussion in 'Shaders' started by Cylau, Sep 22, 2021.

  1. Cylau

    Cylau

    Joined:
    Jun 5, 2019
    Posts:
    3
    I'm trying to change the priority of my custom shader based on a URP / Lit shader. I only changed Ztest in it to Always for overlay drawing. The shader works as I need it, but only if I change the priority manually in the editor. If I do this through code, then changing the priority has no effect until I expand the material settings in the editor (in other words, the priority that I set with the code applies to the material, but does not affect the rendering in any way). This applies to any other properties. The build also has this problem.

    This is how I change the priority:
    Code (CSharp):
    1. mat.SetFloat ("_QueueOffset", mat.GetFloat ("_QueueOffset") + 2);
    The shader I'm using:

    Code (CSharp):
    1. Shader "Universal Render Pipeline/Overlay Lit"
    2. {
    3.     Properties
    4.     {
    5.         // Specular vs Metallic workflow
    6.         [HideInInspector] _WorkflowMode("WorkflowMode", Float) = 1.0
    7.  
    8.         [MainTexture] _BaseMap("Albedo", 2D) = "white" {}
    9.         [MainColor] _BaseColor("Color", Color) = (1,1,1,1)
    10.  
    11.         _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
    12.  
    13.         _Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5
    14.         _GlossMapScale("Smoothness Scale", Range(0.0, 1.0)) = 1.0
    15.         _SmoothnessTextureChannel("Smoothness texture channel", Float) = 0
    16.  
    17.         _Metallic("Metallic", Range(0.0, 1.0)) = 0.0
    18.         _MetallicGlossMap("Metallic", 2D) = "white" {}
    19.  
    20.         _SpecColor("Specular", Color) = (0.2, 0.2, 0.2)
    21.         _SpecGlossMap("Specular", 2D) = "white" {}
    22.  
    23.         [ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0
    24.         [ToggleOff] _EnvironmentReflections("Environment Reflections", Float) = 1.0
    25.  
    26.         _BumpScale("Scale", Float) = 1.0
    27.         _BumpMap("Normal Map", 2D) = "bump" {}
    28.  
    29.         _Parallax("Scale", Range(0.005, 0.08)) = 0.005
    30.         _ParallaxMap("Height Map", 2D) = "black" {}
    31.  
    32.         _OcclusionStrength("Strength", Range(0.0, 1.0)) = 1.0
    33.         _OcclusionMap("Occlusion", 2D) = "white" {}
    34.  
    35.         [HDR] _EmissionColor("Color", Color) = (0,0,0)
    36.         _EmissionMap("Emission", 2D) = "white" {}
    37.  
    38.         _DetailMask("Detail Mask", 2D) = "white" {}
    39.         _DetailAlbedoMapScale("Scale", Range(0.0, 2.0)) = 1.0
    40.         _DetailAlbedoMap("Detail Albedo x2", 2D) = "linearGrey" {}
    41.         _DetailNormalMapScale("Scale", Range(0.0, 2.0)) = 1.0
    42.         [Normal] _DetailNormalMap("Normal Map", 2D) = "bump" {}
    43.  
    44.         // SRP batching compatibility for Clear Coat (Not used in Lit)
    45.         [HideInInspector] _ClearCoatMask("_ClearCoatMask", Float) = 0.0
    46.         [HideInInspector] _ClearCoatSmoothness("_ClearCoatSmoothness", Float) = 0.0
    47.  
    48.             // Blending state
    49.             [HideInInspector] _Surface("__surface", Float) = 0.0
    50.             [HideInInspector] _Blend("__blend", Float) = 0.0
    51.             [HideInInspector] _AlphaClip("__clip", Float) = 0.0
    52.             [HideInInspector] _SrcBlend("__src", Float) = 1.0
    53.             [HideInInspector] _DstBlend("__dst", Float) = 0.0
    54.             [HideInInspector] _ZWrite("__zw", Float) = 1.0
    55.             [HideInInspector] _Cull("__cull", Float) = 2.0
    56.  
    57.             _ReceiveShadows("Receive Shadows", Float) = 1.0
    58.             // Editmode props
    59.             [HideInInspector] _QueueOffset("Queue offset", Float) = 0.0
    60.  
    61.             // ObsoleteProperties
    62.             [HideInInspector] _MainTex("BaseMap", 2D) = "white" {}
    63.             [HideInInspector] _Color("Base Color", Color) = (1, 1, 1, 1)
    64.             [HideInInspector] _GlossMapScale("Smoothness", Float) = 0.0
    65.             [HideInInspector] _Glossiness("Smoothness", Float) = 0.0
    66.             [HideInInspector] _GlossyReflections("EnvironmentReflections", Float) = 0.0
    67.  
    68.             [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {}
    69.             [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {}
    70.             [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {}
    71.     }
    72.  
    73.     SubShader
    74.     {
    75.         // Universal Pipeline tag is required. If Universal render pipeline is not set in the graphics settings
    76.         // this Subshader will fail. One can add a subshader below or fallback to Standard built-in to make this
    77.         // material work with both Universal Render Pipeline and Builtin Unity Pipeline
    78.         Tags{"RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" "UniversalMaterialType" = "Lit" "IgnoreProjector" = "True" "ShaderModel" = "4.5"}
    79.         LOD 300
    80.  
    81.         // ------------------------------------------------------------------
    82.         //  Forward pass. Shades all light in a single pass. GI + emission + Fog
    83.         Pass
    84.         {
    85.             // Lightmode matches the ShaderPassName set in UniversalRenderPipeline.cs. SRPDefaultUnlit and passes with
    86.             // no LightMode tag are also rendered by Universal Render Pipeline
    87.             Name "ForwardLit"
    88.             Tags{"LightMode" = "UniversalForward"}
    89.  
    90.             Blend[_SrcBlend][_DstBlend]
    91.             ZWrite[_ZWrite]
    92.             Ztest Always
    93.             Cull[_Cull]
    94.  
    95.             HLSLPROGRAM
    96.             #pragma exclude_renderers gles gles3 glcore
    97.             #pragma target 4.5
    98.  
    99.         // -------------------------------------
    100.         // Material Keywords
    101.         #pragma shader_feature_local _NORMALMAP
    102.         #pragma shader_feature_local_fragment _ALPHATEST_ON
    103.         #pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_ON
    104.         #pragma shader_feature_local_fragment _EMISSION
    105.         #pragma shader_feature_local_fragment _METALLICSPECGLOSSMAP
    106.         #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
    107.         #pragma shader_feature_local_fragment _OCCLUSIONMAP
    108.         #pragma shader_feature_local _PARALLAXMAP
    109.         #pragma shader_feature_local _ _DETAIL_MULX2 _DETAIL_SCALED
    110.         #pragma shader_feature_local_fragment _SPECULARHIGHLIGHTS_OFF
    111.         #pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF
    112.         #pragma shader_feature_local_fragment _SPECULAR_SETUP
    113.         #pragma shader_feature_local _RECEIVE_SHADOWS_OFF
    114.  
    115.         // -------------------------------------
    116.         // Universal Pipeline keywords
    117.         #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
    118.         #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
    119.         #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
    120.         #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
    121.         #pragma multi_compile_fragment _ _SHADOWS_SOFT
    122.         #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
    123.         #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
    124.         #pragma multi_compile _ SHADOWS_SHADOWMASK
    125.  
    126.         // -------------------------------------
    127.         // Unity defined keywords
    128.         #pragma multi_compile _ DIRLIGHTMAP_COMBINED
    129.         #pragma multi_compile _ LIGHTMAP_ON
    130.         #pragma multi_compile_fog
    131.  
    132.         //--------------------------------------
    133.         // GPU Instancing
    134.         #pragma multi_compile_instancing
    135.         #pragma multi_compile _ DOTS_INSTANCING_ON
    136.  
    137.         #pragma vertex LitPassVertex
    138.         #pragma fragment LitPassFragment
    139.  
    140.         #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
    141.         #include "Packages/com.unity.render-pipelines.universal/Shaders/LitForwardPass.hlsl"
    142.         ENDHLSL
    143.     }
    144.  
    145.     Pass
    146.     {
    147.         Name "ShadowCaster"
    148.         Tags{"LightMode" = "ShadowCaster"}
    149.  
    150.         ZWrite On
    151.         ZTest Always
    152.         ColorMask 0
    153.         Cull[_Cull]
    154.  
    155.         HLSLPROGRAM
    156.         #pragma exclude_renderers gles gles3 glcore
    157.         #pragma target 4.5
    158.  
    159.         // -------------------------------------
    160.         // Material Keywords
    161.         #pragma shader_feature_local_fragment _ALPHATEST_ON
    162.         #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
    163.  
    164.         //--------------------------------------
    165.         // GPU Instancing
    166.         #pragma multi_compile_instancing
    167.         #pragma multi_compile _ DOTS_INSTANCING_ON
    168.  
    169.         #pragma vertex ShadowPassVertex
    170.         #pragma fragment ShadowPassFragment
    171.  
    172.         #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
    173.         #include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl"
    174.         ENDHLSL
    175.     }
    176.  
    177.     Pass
    178.     {
    179.             // Lightmode matches the ShaderPassName set in UniversalRenderPipeline.cs. SRPDefaultUnlit and passes with
    180.             // no LightMode tag are also rendered by Universal Render Pipeline
    181.             Name "GBuffer"
    182.             Tags{"LightMode" = "UniversalGBuffer"}
    183.  
    184.             ZWrite[_ZWrite]
    185.             ZTest Always
    186.             Cull[_Cull]
    187.  
    188.             HLSLPROGRAM
    189.             #pragma exclude_renderers gles gles3 glcore
    190.             #pragma target 4.5
    191.  
    192.         // -------------------------------------
    193.         // Material Keywords
    194.         #pragma shader_feature_local _NORMALMAP
    195.         #pragma shader_feature_local_fragment _ALPHATEST_ON
    196.         //#pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_ON
    197.         #pragma shader_feature_local_fragment _EMISSION
    198.         #pragma shader_feature_local_fragment _METALLICSPECGLOSSMAP
    199.         #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
    200.         #pragma shader_feature_local_fragment _OCCLUSIONMAP
    201.         #pragma shader_feature_local _PARALLAXMAP
    202.         #pragma shader_feature_local _ _DETAIL_MULX2 _DETAIL_SCALED
    203.  
    204.         #pragma shader_feature_local_fragment _SPECULARHIGHLIGHTS_OFF
    205.         #pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF
    206.         #pragma shader_feature_local_fragment _SPECULAR_SETUP
    207.         #pragma shader_feature_local _RECEIVE_SHADOWS_OFF
    208.  
    209.         // -------------------------------------
    210.         // Universal Pipeline keywords
    211.         #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
    212.         #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
    213.         //#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
    214.         //#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
    215.         #pragma multi_compile _ _SHADOWS_SOFT
    216.         #pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
    217.  
    218.         // -------------------------------------
    219.         // Unity defined keywords
    220.         #pragma multi_compile _ DIRLIGHTMAP_COMBINED
    221.         #pragma multi_compile _ LIGHTMAP_ON
    222.         #pragma multi_compile_fragment _ _GBUFFER_NORMALS_OCT
    223.  
    224.         //--------------------------------------
    225.         // GPU Instancing
    226.         #pragma multi_compile_instancing
    227.         #pragma multi_compile _ DOTS_INSTANCING_ON
    228.  
    229.         #pragma vertex LitGBufferPassVertex
    230.         #pragma fragment LitGBufferPassFragment
    231.  
    232.         #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
    233.         #include "Packages/com.unity.render-pipelines.universal/Shaders/LitGBufferPass.hlsl"
    234.         ENDHLSL
    235.     }
    236.  
    237.     Pass
    238.     {
    239.         Name "DepthOnly"
    240.         Tags{"LightMode" = "DepthOnly"}
    241.  
    242.         ZWrite On
    243.         Ztest Always
    244.         ColorMask 0
    245.         Cull[_Cull]
    246.  
    247.         HLSLPROGRAM
    248.         #pragma exclude_renderers gles gles3 glcore
    249.         #pragma target 4.5
    250.  
    251.         #pragma vertex DepthOnlyVertex
    252.         #pragma fragment DepthOnlyFragment
    253.  
    254.         // -------------------------------------
    255.         // Material Keywords
    256.         #pragma shader_feature_local_fragment _ALPHATEST_ON
    257.         #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
    258.  
    259.         //--------------------------------------
    260.         // GPU Instancing
    261.         #pragma multi_compile_instancing
    262.         #pragma multi_compile _ DOTS_INSTANCING_ON
    263.  
    264.         #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
    265.         #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"
    266.         ENDHLSL
    267.     }
    268.  
    269.         // This pass is used when drawing to a _CameraNormalsTexture texture
    270.         Pass
    271.         {
    272.             Name "DepthNormals"
    273.             Tags{"LightMode" = "DepthNormals"}
    274.  
    275.             ZWrite On
    276.             Ztest Always
    277.             Cull[_Cull]
    278.  
    279.             HLSLPROGRAM
    280.             #pragma exclude_renderers gles gles3 glcore
    281.             #pragma target 4.5
    282.  
    283.             #pragma vertex DepthNormalsVertex
    284.             #pragma fragment DepthNormalsFragment
    285.  
    286.         // -------------------------------------
    287.         // Material Keywords
    288.         #pragma shader_feature_local _NORMALMAP
    289.         #pragma shader_feature_local_fragment _ALPHATEST_ON
    290.         #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
    291.  
    292.         //--------------------------------------
    293.         // GPU Instancing
    294.         #pragma multi_compile_instancing
    295.         #pragma multi_compile _ DOTS_INSTANCING_ON
    296.  
    297.         #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
    298.         #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthNormalsPass.hlsl"
    299.         ENDHLSL
    300.     }
    301.  
    302.         // This pass it not used during regular rendering, only for lightmap baking.
    303.         Pass
    304.         {
    305.             Name "Meta"
    306.             Tags{"LightMode" = "Meta"}
    307.  
    308.             Cull Off
    309.             Ztest Always
    310.  
    311.             HLSLPROGRAM
    312.             #pragma exclude_renderers gles gles3 glcore
    313.             #pragma target 4.5
    314.  
    315.             #pragma vertex UniversalVertexMeta
    316.             #pragma fragment UniversalFragmentMeta
    317.  
    318.             #pragma shader_feature_local_fragment _SPECULAR_SETUP
    319.             #pragma shader_feature_local_fragment _EMISSION
    320.             #pragma shader_feature_local_fragment _METALLICSPECGLOSSMAP
    321.             #pragma shader_feature_local_fragment _ALPHATEST_ON
    322.             #pragma shader_feature_local_fragment _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
    323.             #pragma shader_feature_local _ _DETAIL_MULX2 _DETAIL_SCALED
    324.  
    325.             #pragma shader_feature_local_fragment _SPECGLOSSMAP
    326.  
    327.             #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
    328.             #include "Packages/com.unity.render-pipelines.universal/Shaders/LitMetaPass.hlsl"
    329.  
    330.             ENDHLSL
    331.         }
    332.         Pass
    333.         {
    334.             Name "Universal2D"
    335.             Tags{ "LightMode" = "Universal2D" }
    336.  
    337.             Blend[_SrcBlend][_DstBlend]
    338.             ZWrite[_ZWrite]
    339.             Ztest Always
    340.             Cull[_Cull]
    341.  
    342.             HLSLPROGRAM
    343.             #pragma exclude_renderers gles gles3 glcore
    344.             #pragma target 4.5
    345.  
    346.             #pragma vertex vert
    347.             #pragma fragment frag
    348.             #pragma shader_feature_local_fragment _ALPHATEST_ON
    349.             #pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_ON
    350.  
    351.             #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
    352.             #include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/Universal2D.hlsl"
    353.             ENDHLSL
    354.         }
    355.     }
    356.  
    357.         SubShader
    358.     {
    359.         // Universal Pipeline tag is required. If Universal render pipeline is not set in the graphics settings
    360.         // this Subshader will fail. One can add a subshader below or fallback to Standard built-in to make this
    361.         // material work with both Universal Render Pipeline and Builtin Unity Pipeline
    362.         Tags{"RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" "UniversalMaterialType" = "Lit" "IgnoreProjector" = "True" "ShaderModel" = "2.0"}
    363.         LOD 300
    364.  
    365.         // ------------------------------------------------------------------
    366.         //  Forward pass. Shades all light in a single pass. GI + emission + Fog
    367.         Pass
    368.         {
    369.             // Lightmode matches the ShaderPassName set in UniversalRenderPipeline.cs. SRPDefaultUnlit and passes with
    370.             // no LightMode tag are also rendered by Universal Render Pipeline
    371.             Name "ForwardLit"
    372.             Tags{"LightMode" = "UniversalForward"}
    373.  
    374.             Blend[_SrcBlend][_DstBlend]
    375.             ZWrite[_ZWrite]
    376.             Ztest Always
    377.             Cull[_Cull]
    378.  
    379.             HLSLPROGRAM
    380.             #pragma only_renderers gles gles3 glcore d3d11
    381.             #pragma target 2.0
    382.  
    383.         //--------------------------------------
    384.         // GPU Instancing
    385.         #pragma multi_compile_instancing
    386.  
    387.         // -------------------------------------
    388.         // Material Keywords
    389.         #pragma shader_feature_local _NORMALMAP
    390.         #pragma shader_feature_local_fragment _ALPHATEST_ON
    391.         #pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_ON
    392.         #pragma shader_feature_local_fragment _EMISSION
    393.         #pragma shader_feature_local_fragment _METALLICSPECGLOSSMAP
    394.         #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
    395.         #pragma shader_feature_local_fragment _OCCLUSIONMAP
    396.         #pragma shader_feature_local _PARALLAXMAP
    397.         #pragma shader_feature_local _ _DETAIL_MULX2 _DETAIL_SCALED
    398.  
    399.         #pragma shader_feature_local_fragment _SPECULARHIGHLIGHTS_OFF
    400.         #pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF
    401.         #pragma shader_feature_local_fragment _SPECULAR_SETUP
    402.         #pragma shader_feature_local _RECEIVE_SHADOWS_OFF
    403.  
    404.         // -------------------------------------
    405.         // Universal Pipeline keywords
    406.         #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
    407.         #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
    408.         #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
    409.         #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
    410.         #pragma multi_compile_fragment _ _SHADOWS_SOFT
    411.         #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
    412.         #pragma multi_compile _ SHADOWS_SHADOWMASK
    413.         #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
    414.  
    415.         // -------------------------------------
    416.         // Unity defined keywords
    417.         #pragma multi_compile _ DIRLIGHTMAP_COMBINED
    418.         #pragma multi_compile _ LIGHTMAP_ON
    419.         #pragma multi_compile_fog
    420.  
    421.         #pragma vertex LitPassVertex
    422.         #pragma fragment LitPassFragment
    423.  
    424.         #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
    425.         #include "Packages/com.unity.render-pipelines.universal/Shaders/LitForwardPass.hlsl"
    426.         ENDHLSL
    427.     }
    428.  
    429.     Pass
    430.     {
    431.         Name "ShadowCaster"
    432.         Tags{"LightMode" = "ShadowCaster"}
    433.  
    434.         ZWrite On
    435.         ZTest Always
    436.         ColorMask 0
    437.         Cull[_Cull]
    438.  
    439.         HLSLPROGRAM
    440.         #pragma only_renderers gles gles3 glcore d3d11
    441.         #pragma target 2.0
    442.  
    443.         //--------------------------------------
    444.         // GPU Instancing
    445.         #pragma multi_compile_instancing
    446.  
    447.         // -------------------------------------
    448.         // Material Keywords
    449.         #pragma shader_feature_local_fragment _ALPHATEST_ON
    450.         #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
    451.  
    452.         #pragma vertex ShadowPassVertex
    453.         #pragma fragment ShadowPassFragment
    454.  
    455.         #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
    456.         #include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl"
    457.         ENDHLSL
    458.     }
    459.  
    460.     Pass
    461.     {
    462.         Name "DepthOnly"
    463.         Tags{"LightMode" = "DepthOnly"}
    464.  
    465.         ZWrite On
    466.         Ztest Always
    467.         ColorMask 0
    468.         Cull[_Cull]
    469.  
    470.         HLSLPROGRAM
    471.         #pragma only_renderers gles gles3 glcore d3d11
    472.         #pragma target 2.0
    473.  
    474.         //--------------------------------------
    475.         // GPU Instancing
    476.         #pragma multi_compile_instancing
    477.  
    478.         #pragma vertex DepthOnlyVertex
    479.         #pragma fragment DepthOnlyFragment
    480.  
    481.         // -------------------------------------
    482.         // Material Keywords
    483.         #pragma shader_feature_local_fragment _ALPHATEST_ON
    484.         #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
    485.  
    486.         #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
    487.         #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"
    488.         ENDHLSL
    489.     }
    490.  
    491.         // This pass is used when drawing to a _CameraNormalsTexture texture
    492.         Pass
    493.         {
    494.             Name "DepthNormals"
    495.             Tags{"LightMode" = "DepthNormals"}
    496.  
    497.             ZWrite On
    498.             Ztest Always
    499.             Cull[_Cull]
    500.  
    501.             HLSLPROGRAM
    502.             #pragma only_renderers gles gles3 glcore d3d11
    503.             #pragma target 2.0
    504.  
    505.             #pragma vertex DepthNormalsVertex
    506.             #pragma fragment DepthNormalsFragment
    507.  
    508.         // -------------------------------------
    509.         // Material Keywords
    510.         #pragma shader_feature_local _NORMALMAP
    511.         #pragma shader_feature_local_fragment _ALPHATEST_ON
    512.         #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
    513.  
    514.         //--------------------------------------
    515.         // GPU Instancing
    516.         #pragma multi_compile_instancing
    517.  
    518.         #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
    519.         #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthNormalsPass.hlsl"
    520.         ENDHLSL
    521.     }
    522.  
    523.         // This pass it not used during regular rendering, only for lightmap baking.
    524.         Pass
    525.         {
    526.             Name "Meta"
    527.             Tags{"LightMode" = "Meta"}
    528.  
    529.             Cull Off
    530.             Ztest Always
    531.  
    532.             HLSLPROGRAM
    533.             #pragma only_renderers gles gles3 glcore d3d11
    534.             #pragma target 2.0
    535.  
    536.             #pragma vertex UniversalVertexMeta
    537.             #pragma fragment UniversalFragmentMeta
    538.  
    539.             #pragma shader_feature_local_fragment _SPECULAR_SETUP
    540.             #pragma shader_feature_local_fragment _EMISSION
    541.             #pragma shader_feature_local_fragment _METALLICSPECGLOSSMAP
    542.             #pragma shader_feature_local_fragment _ALPHATEST_ON
    543.             #pragma shader_feature_local_fragment _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
    544.             #pragma shader_feature_local _ _DETAIL_MULX2 _DETAIL_SCALED
    545.  
    546.             #pragma shader_feature_local_fragment _SPECGLOSSMAP
    547.  
    548.             #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
    549.             #include "Packages/com.unity.render-pipelines.universal/Shaders/LitMetaPass.hlsl"
    550.  
    551.             ENDHLSL
    552.         }
    553.         Pass
    554.         {
    555.             Name "Universal2D"
    556.             Tags{ "LightMode" = "Universal2D" }
    557.  
    558.             Blend[_SrcBlend][_DstBlend]
    559.             ZWrite[_ZWrite]
    560.             Ztest Always
    561.             Cull[_Cull]
    562.  
    563.             HLSLPROGRAM
    564.             #pragma only_renderers gles gles3 glcore d3d11
    565.             #pragma target 2.0
    566.  
    567.             #pragma vertex vert
    568.             #pragma fragment frag
    569.             #pragma shader_feature_local_fragment _ALPHATEST_ON
    570.             #pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_ON
    571.  
    572.             #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
    573.             #include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/Universal2D.hlsl"
    574.             ENDHLSL
    575.         }
    576.     }
    577.  
    578.         FallBack "Hidden/Universal Render Pipeline/FallbackError"
    579.         CustomEditor "UnityEditor.Rendering.Universal.ShaderGUI.LitShader"
    580. }
     
    Last edited: Sep 22, 2021
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    11,041
    _ QueueOffset
    is not the same as
    _QueueOffset
     
  3. Cylau

    Cylau

    Joined:
    Jun 5, 2019
    Posts:
    3
    Sorry, this is a typo in the post, it is not in the code.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    11,041
    Unfortunately I honestly have no idea how the queue offset is actually applied. Looking over the code I only see it setting that queue value. There are other parts that show it only shows the queue offset if there's also a
    _QueueControl
    property, but very few of the included shaders have this property and yet still show the queue offset, so I have no idea what's going on.
     
  5. Cylau

    Cylau

    Joined:
    Jun 5, 2019
    Posts:
    3
    In that case, maybe you know a working way to render a mesh on top of everything in URP? Perhaps using ZTest isn't the best way? To be honest, I'm pretty bad at shaders and rendering as such.
     
  6. Ghodikov

    Ghodikov

    Joined:
    Oct 8, 2020
    Posts:
    3
    The easiest one is to turn on the second camera, put it at the very bottom of the stack. Assign in the Culling Mask the layer that it will render, and assign this layer to the object. Well, and accordingly, uncheck this layer from your current camera.
     
unityunity