I am trying to write a shader that uses the alpha of the Main Texture in the Shadow Caster pass in Unity 2022.2.6. Currently the shader writes to the ShadowCaster Pass but it only uses one Texture for all Materials. I have looked into the Frame Debugger and there the Main Texture is always the same. Am I missing something or is it some kind of Bug with the SRP Batcher? The Renderer Data Settings: The Render Pipeline Settings: This is the Shader I am working on: Code (HLSL): Shader "Question/Lit" { Properties { _MainTex ("Albedo Texture", 2D) = "white" {} } CustomEditor "Ulisses.Hexxen1733.Shader.Editor.CelShaderEditor" SubShader { Tags { "RenderType"="Opaque" "RenderPipeline"="UniversalRenderPipeline"} // this pass renders the shadows Pass{ Name "ShadowCaster" Tags { "LightMode"="ShadowCaster"} ZWrite On ZTest LEqual ColorMask 0 CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma multi_compile_instancing #pragma multi_compile_shadowcaster #pragma multi_compile _ DOTS_INSTANCING_ON #include "UnityCG.cginc" CBUFFER_START(UnityPerMaterial) sampler2D _MainTex; float4 _MainTex_ST; CBUFFER_END struct v2f { V2F_SHADOW_CASTER; float2 uv : TEXCOORD1; }; v2f vert(appdata_full v ) { v2f o; o.uv = v.texcoord; TRANSFER_SHADOW_CASTER(o) return o; } void frag(v2f i) { float alpha = tex2D (_MainTex, i.uv).a; clip(alpha -0.5f); } ENDCG } // This Pass Renders the Depth of to the Depth Texture Pass{ Name "Depth" Tags { "LightMode"="DepthOnly" } ZWrite On ZTest LEqual Cull BACK CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma multi_compile_shadowcaster #include "UnityCG.cginc" CBUFFER_START(UnityPerMaterial) sampler2D _MainTex; float4 _MainTex_ST; CBUFFER_END struct appdata{ float2 uv : TEXCOORD0; }; struct v2f{ V2F_SHADOW_CASTER; float2 uv : TEXCOORD1; }; v2f vert(appdata_full v ){ v2f o; o.uv = v.texcoord; TRANSFER_SHADOW_CASTER(o) return o; } float4 frag(v2f i) : COLOR{ float alpha = tex2D (_MainTex, i.uv).a; clip(alpha -0.5f); SHADOW_CASTER_FRAGMENT(i) } ENDCG } // This Pass Renders the final color Pass { Tags { "LightMode"="UniversalForward" } Blend One Zero AlphaToMask On HLSLPROGRAM #pragma vertex vert #pragma fragment frag #pragma multi_compile _ _MAIN_LIGHT_SHADOWS #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE #pragma multi_compile _ _SHADOWS_SOFT #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" #include "Utility/HeXXen1733_Utility.hlsl" CBUFFER_START(UnityPerMaterial) sampler2D _MainTex; float4 _MainTex_ST; CBUFFER_END struct appdata { float4 positionOS : POSITION; float2 uv : TEXCOORD0; float3 normal : NORMAL; }; struct v2f { float2 uv : TEXCOORD0; float3 vertexWS : TEXCOORD1; float4 vertex : SV_POSITION; float4 screenSpace : TEXCOORD2; float3 normal : NORMAL; }; sampler2D _CameraDepthTexture; v2f vert(appdata v) { v2f o; VertexPositionInputs positionInputs = GetVertexPositionInputs(v.positionOS.xyz); o.vertex = positionInputs.positionCS; o.vertexWS = positionInputs.positionWS; o.screenSpace = ComputeScreenPos(o.vertex); o.normal = v.normal; o.uv = TRANSFORM_TEX(v.uv, _MainTex); return o; } half4 frag(v2f i) : SV_Target { float4 shadowCoord = TransformWorldToShadowCoord(i.vertexWS); Light mainLight = GetMainLight(shadowCoord); float2 screenSpaceUV = i.screenSpace.xy / i.screenSpace.w; //float depth = tex2D(_CameraDepthTexture, screenSpaceUV).r; Surface surf; surf.normal = i.normal; float4 texCol = tex2D(_MainTex, i.uv); float3 color = surfaceAtten(mainLight, surf, 0) * texCol.rgb; float alpha = smoothstep(0.5f,0.5f,texCol.a); return float4(color, alpha); } ENDHLSL } } }
I just found out that if I remove the Tag "RenderPipeline"="UniversalRenderPipeline" the textures will be displayed correctly. In Unity 2022.1 the Tag had no issues.