Shader "Unlit/SoftShadowMask" { SubShader { Pass { ZTest Always ZWrite Off Cull Off HLSLPROGRAM #pragma vertex vert #pragma fragment frag #pragma enable_d3d11_debug_symbols #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl" #pragma multi_compile _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE struct Varyings { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; }; Varyings vert(uint vertexID: SV_VertexID) { Varyings o; o.vertex = GetFullScreenTriangleVertexPosition(vertexID); o.uv = GetFullScreenTriangleTexCoord(vertexID); return o; } float4 _Offset5[2]; float4 _MaskSizeAndInvRenderSize; half GetDepth(float2 uv) { #if UNITY_REVERSED_Z float deviceDepth = SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_PointClamp, uv).r; #else float deviceDepth = SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_PointClamp, uv).r; deviceDepth = deviceDepth * 2.0 - 1.0; #endif return deviceDepth; } half frag(Varyings input) : SV_Target { float2 uv = input.uv; //Fetch shadow coordinates for cascade. float3 wpos = ComputeWorldSpacePosition(uv, GetDepth(uv), unity_MatrixInvVP); float4 coords = TransformWorldToShadowCoord(wpos); if(BEYOND_SHADOW_FAR(coords)) { return 1; } half shadow = 0; float2 uv0 = input.uv; for (int i = 0; i < 2; ++i) { uv = uv0 + _Offset5[i].xy; wpos = ComputeWorldSpacePosition(uv, GetDepth(uv), unity_MatrixInvVP); coords = TransformWorldToShadowCoord(wpos); shadow += BEYOND_SHADOW_FAR(coords) ? 1 : SAMPLE_TEXTURE2D_SHADOW(_MainLightShadowmapTexture, sampler_LinearClampCompare, coords.xyz); uv = uv0 + _Offset5[i].zw; wpos = ComputeWorldSpacePosition(uv, GetDepth(uv), unity_MatrixInvVP); coords = TransformWorldToShadowCoord(wpos); shadow += BEYOND_SHADOW_FAR(coords) ? 1 : SAMPLE_TEXTURE2D_SHADOW(_MainLightShadowmapTexture, sampler_LinearClampCompare, coords.xyz); } shadow *= 0.25f; return shadow; } ENDHLSL } } }