Please use this shader if you are using Fast Shadow Receiver with a shadowmap in URP. Only main light shadows are supported.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
Shader "FastShadowReceiver/Receiver/URP/Shadowmap/Multiply" { Properties { _Darkness ("Shadow Darkness", Range (0, 1)) = 0.5 } SubShader { Tags { "RenderType"="Transparent" "Queue"="Transparent-500" } Pass { Tags { "LightMode"="UniversalForward" } Cull Back ZWrite Off Fog { Color (1, 1, 1) } ColorMask RGB Blend DstColor Zero Offset -1, -1 HLSLPROGRAM #pragma prefer_hlslcc gles #pragma exclude_renderers d3d11_9x #pragma target 2.0 #pragma vertex vert #pragma fragment frag // ------------------------------------- // Universal Pipeline keywords #pragma multi_compile _ _MAIN_LIGHT_SHADOWS #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE //#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS //#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS #pragma multi_compile _ _SHADOWS_SOFT #pragma multi_compile_fog #pragma multi_compile_instancing #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" #if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2) #define UNITY_CALC_FOG_FACTOR(outpos) float unityFogFactor = ComputeFogFactor((outpos).z) #define UNITY_FOG_COORDS(idx) float1 fogCoord : TEXCOORD##idx; #define UNITY_TRANSFER_FOG(o,outpos) o.fogCoord.x = ComputeFogFactor((outpos).z) #define UNITY_APPLY_FOG_COLOR(coord,col,fogCol) col.rgb = MixFogColor(col.rgb,(fogCol).rgb,(coord).x) #else #define UNITY_FOG_COORDS(idx) #define UNITY_TRANSFER_FOG(o,outpos) #define UNITY_APPLY_FOG_COLOR(coord,col,fogCol) #endif struct appdata { float4 vertex : POSITION; UNITY_VERTEX_INPUT_INSTANCE_ID }; struct v2f { float4 pos : SV_POSITION; #if defined(MAIN_LIGHT_CALCULATE_SHADOWS) float4 shadowCoord : TEXCOORD0; #endif UNITY_FOG_COORDS(1) UNITY_VERTEX_OUTPUT_STEREO }; v2f vert(appdata v) { v2f o; UNITY_SETUP_INSTANCE_ID(v); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); #if defined(MAIN_LIGHT_CALCULATE_SHADOWS) float3 worldPos = TransformObjectToWorld(v.vertex.xyz); o.pos = TransformWorldToHClip(worldPos); #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) o.shadowCoord = TransformWorldToShadowCoord(worldPos); #else o.shadowCoord = float4(worldPos, 1); #endif #else o.pos = float4(v.vertex.x,v.vertex.y,-1,-1); #endif UNITY_TRANSFER_FOG(o, o.pos); return o; } CBUFFER_START(UnityPerMaterial) half _Darkness; CBUFFER_END half4 frag(v2f i) : SV_Target { #if defined(MAIN_LIGHT_CALCULATE_SHADOWS) float4 shadowCoord = i.shadowCoord; #if !defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) shadowCoord = TransformWorldToShadowCoord(shadowCoord.xyz); #endif half shadow = MainLightRealtimeShadow(shadowCoord); half4 col = lerp(1.0f, shadow, _Darkness); UNITY_APPLY_FOG_COLOR(i.fogCoord, col, half4(1,1,1,1)); return col; #else return 1; #endif } ENDHLSL } } } |