URPShadowReceiver.shader 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. Shader "URP Shadow Receiver"
  2. {
  3. Properties
  4. {
  5. _ShadowColor ("Shadow Color", Color) = (0.35, 0.4, 0.45, 1.0)
  6. }
  7. SubShader
  8. {
  9. Tags
  10. {
  11. "RenderPipeline" = "UniversalPipeline"
  12. "RenderType" = "Transparent"
  13. "Queue" = "Transparent-1"
  14. }
  15. Pass
  16. {
  17. Name "ForwardLit"
  18. Tags
  19. {
  20. "LightMode" = "UniversalForward"
  21. }
  22. Blend DstColor Zero, Zero One
  23. Cull Back
  24. ZTest LEqual
  25. ZWrite Off
  26. HLSLPROGRAM
  27. #pragma vertex vert
  28. #pragma fragment frag
  29. #pragma prefer_hlslcc gles
  30. #pragma exclude_renderers d3d11_9x
  31. #pragma target 2.0
  32. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
  33. #pragma multi_compile _ _SHADOWS_SOFT
  34. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  35. CBUFFER_START(UnityPerMaterial)
  36. float4 _ShadowColor;
  37. CBUFFER_END
  38. struct Attributes
  39. {
  40. half4 positionOS : POSITION;
  41. };
  42. struct Varyings
  43. {
  44. half4 positionCS : SV_POSITION;
  45. half3 positionWS : TEXCOORD0;
  46. };
  47. Varyings vert(Attributes input)
  48. {
  49. Varyings output;
  50. VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
  51. output.positionCS = vertexInput.positionCS;
  52. output.positionWS = vertexInput.positionWS;
  53. return output;
  54. }
  55. half4 frag(Varyings input) : SV_Target
  56. {
  57. half4 color = half4(1, 1, 1, 1);
  58. #if (defined(_MAIN_LIGHT_SHADOWS) || defined(_MAIN_LIGHT_SHADOWS_CASCADE) || defined(_MAIN_LIGHT_SHADOWS_SCREEN))
  59. VertexPositionInputs vertexInput = (VertexPositionInputs)0;
  60. vertexInput.positionWS = input.positionWS;
  61. float4 shadowCoord = GetShadowCoord(vertexInput);
  62. half shadowAttenutation = MainLightRealtimeShadow(shadowCoord);
  63. color = lerp(half4(1, 1, 1, 1), _ShadowColor, (1.0 - shadowAttenutation) * _ShadowColor.a);
  64. #endif
  65. return color;
  66. }
  67. ENDHLSL
  68. }
  69. }
  70. }