CTI URP Billboard ShadowCaster Pass.hlsl 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. float4 positionOS : POSITION;
  6. float3 normalOS : NORMAL;
  7. //float4 tangentOS : TANGENT;
  8. float2 texcoord : TEXCOORD0;
  9. float3 texcoord1 : TEXCOORD1;
  10. UNITY_VERTEX_INPUT_INSTANCE_ID
  11. };
  12. struct Varyings {
  13. float4 positionCS : SV_POSITION;
  14. float2 uv : TEXCOORD0;
  15. };
  16. // Shadow caster specific input
  17. float3 _LightDirection;
  18. float3 _LightPosition;
  19. //--------------------------------------
  20. // Vertex shader
  21. #include "Includes/CTI URP Billboard.hlsl"
  22. Varyings ShadowPassVertex(Attributes input)
  23. {
  24. Varyings output = (Varyings)0;
  25. UNITY_SETUP_INSTANCE_ID(input);
  26. half4 color;
  27. CTIBillboardVert(input, _LightDirection, color);
  28. output.uv = input.texcoord.xy;
  29. float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
  30. float3 normalWS = TransformObjectToWorldDir(input.normalOS);
  31. #if _CASTING_PUNCTUAL_LIGHT_SHADOW
  32. float3 lightDirectionWS = normalize(_LightPosition - positionWS);
  33. #else
  34. float3 lightDirectionWS = _LightDirection;
  35. #endif
  36. output.positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, lightDirectionWS));
  37. #if UNITY_REVERSED_Z
  38. output.positionCS.z = min(output.positionCS.z, UNITY_NEAR_CLIP_VALUE);
  39. #else
  40. output.positionCS.z = max(output.positionCS.z, UNITY_NEAR_CLIP_VALUE);
  41. #endif
  42. return output;
  43. }
  44. //--------------------------------------
  45. // Fragment shader
  46. half4 ShadowPassFragment(Varyings input) : SV_Target
  47. {
  48. #if defined(LOD_FADE_CROSSFADE) && !defined(SHADER_API_GLES)
  49. LODDitheringTransition(input.positionCS.xyz, unity_LODFade.x);
  50. #endif
  51. half alpha = SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a;
  52. clip(alpha - _Cutoff);
  53. return 0;
  54. }