CTI URP Leaves ShadowCaster Pass.hlsl 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  2. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
  3. // Structs
  4. struct Attributes
  5. {
  6. float4 positionOS : POSITION;
  7. float3 normalOS : NORMAL;
  8. float2 texcoord : TEXCOORD0;
  9. float2 texcoord1 : TEXCOORD1; // Bending
  10. half4 color : COLOR; // Bending
  11. float3 texcoord2 : TEXCOORD2; // Leaves only: Pivot
  12. UNITY_VERTEX_INPUT_INSTANCE_ID
  13. };
  14. struct Varyings
  15. {
  16. float2 uv : TEXCOORD0;
  17. float4 positionCS : SV_POSITION;
  18. };
  19. // Shadow caster specific input
  20. float3 _LightDirection;
  21. float3 _LightPosition;
  22. //--------------------------------------
  23. // Vertex shader
  24. #include "Includes/CTI URP Bending.hlsl"
  25. Varyings ShadowPassVertex(Attributes input)
  26. {
  27. Varyings output = (Varyings)0;
  28. UNITY_SETUP_INSTANCE_ID(input);
  29. CTI_AnimateVertex(
  30. input,
  31. #if defined (_BENDINGCOLRSONLY)
  32. float4(input.color.rg, input.color.ab), // animParams,
  33. #else
  34. float4(input.color.rg, input.texcoord1.xy), // animParams,
  35. #endif
  36. _BaseWindMultipliers
  37. );
  38. output.uv = input.texcoord;
  39. float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
  40. float3 normalWS = TransformObjectToWorldDir(input.normalOS);
  41. #if _CASTING_PUNCTUAL_LIGHT_SHADOW
  42. float3 lightDirectionWS = normalize(_LightPosition - positionWS);
  43. #else
  44. float3 lightDirectionWS = _LightDirection;
  45. #endif
  46. output.positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, lightDirectionWS));
  47. #if UNITY_REVERSED_Z
  48. output.positionCS.z = min(output.positionCS.z, UNITY_NEAR_CLIP_VALUE);
  49. #else
  50. output.positionCS.z = max(output.positionCS.z, UNITY_NEAR_CLIP_VALUE);
  51. #endif
  52. return output;
  53. }
  54. //--------------------------------------
  55. // Fragment shader
  56. half4 ShadowPassFragment(Varyings input) : SV_Target
  57. {
  58. #if defined(LOD_FADE_CROSSFADE) && !defined(SHADER_API_GLES)
  59. LODDitheringTransition(input.positionCS.xyz, unity_LODFade.x);
  60. #endif
  61. half alpha = SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a;
  62. clip(alpha - _Cutoff);
  63. return 0;
  64. }