Spine-SkeletonLit-ShadowCasterPass-URP.hlsl 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef SKELETONLIT_SHADOW_CASTER_PASS_URP_INCLUDED
  2. #define SKELETONLIT_SHADOW_CASTER_PASS_URP_INCLUDED
  3. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
  4. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  5. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
  6. float3 _LightDirection;
  7. struct AttributesSpine
  8. {
  9. float4 positionOS : POSITION;
  10. float3 normalOS : NORMAL;
  11. float4 vertexColor : COLOR;
  12. float2 texcoord : TEXCOORD0;
  13. UNITY_VERTEX_INPUT_INSTANCE_ID
  14. };
  15. struct VaryingsSpine
  16. {
  17. float4 positionCS : SV_POSITION;
  18. float4 texcoordAndAlpha: TEXCOORD0;
  19. };
  20. float4 GetShadowPositionHClip(float3 positionOS, half3 normalWS)
  21. {
  22. float3 positionWS = TransformObjectToWorld(positionOS);
  23. float4 positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, _LightDirection));
  24. #if UNITY_REVERSED_Z
  25. positionCS.z = min(positionCS.z, positionCS.w * UNITY_NEAR_CLIP_VALUE);
  26. #else
  27. positionCS.z = max(positionCS.z, positionCS.w * UNITY_NEAR_CLIP_VALUE);
  28. #endif
  29. return positionCS;
  30. }
  31. VaryingsSpine ShadowPassVertexSkeletonLit(AttributesSpine input)
  32. {
  33. VaryingsSpine output;
  34. UNITY_SETUP_INSTANCE_ID(input);
  35. output.texcoordAndAlpha.xyz = float3(TRANSFORM_TEX(input.texcoord, _MainTex).xy, 0);
  36. half3 fixedNormalOS = half3(0, 0, -1);
  37. half3 normalWS = normalize(TransformObjectToWorldNormal(fixedNormalOS));
  38. #ifdef _DOUBLE_SIDED_LIGHTING
  39. // flip normal for shadow bias if necessary
  40. // unfortunately we have to compute the sign here in the vertex shader
  41. // instead of using VFACE in fragment shader stage.
  42. half3 viewDirWS = UNITY_MATRIX_V[2].xyz;
  43. half faceSign = sign(dot(viewDirWS, normalWS));
  44. normalWS *= faceSign;
  45. #endif
  46. output.positionCS = GetShadowPositionHClip(input.positionOS.xyz, normalWS);
  47. output.texcoordAndAlpha.a = input.vertexColor.a;
  48. return output;
  49. }
  50. half4 ShadowPassFragmentSkeletonLit(VaryingsSpine input) : SV_TARGET
  51. {
  52. fixed4 texureColor = tex2D(_MainTex, input.texcoordAndAlpha.xy);
  53. clip(texureColor.a * input.texcoordAndAlpha.a - _Cutoff);
  54. return 0;
  55. }
  56. #endif