Spine-Sprite-StandardPass-URP-2D.hlsl 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #ifndef SPRITE_STANDARD_PASS_URP_INCLUDED
  2. #define SPRITE_STANDARD_PASS_URP_INCLUDED
  3. #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/LightingUtility.hlsl"
  4. #include "../Include/SpineCoreShaders/ShaderShared.cginc"
  5. #include "../Include/SpineCoreShaders/SpriteLighting.cginc"
  6. #if USE_SHAPE_LIGHT_TYPE_0
  7. SHAPE_LIGHT(0)
  8. #endif
  9. #if USE_SHAPE_LIGHT_TYPE_1
  10. SHAPE_LIGHT(1)
  11. #endif
  12. #if USE_SHAPE_LIGHT_TYPE_2
  13. SHAPE_LIGHT(2)
  14. #endif
  15. #if USE_SHAPE_LIGHT_TYPE_3
  16. SHAPE_LIGHT(3)
  17. #endif
  18. TEXTURE2D(_MaskTex);
  19. SAMPLER(sampler_MaskTex);
  20. struct VertexOutputSpriteURP2D
  21. {
  22. float4 pos : SV_POSITION;
  23. half4 vertexColor : COLOR;
  24. float3 texcoord : TEXCOORD0;
  25. float2 lightingUV : TEXCOORD1;
  26. half3 viewDirectionWS : TEXCOORD2;
  27. #if defined(_NORMALMAP)
  28. half4 normalWorld : TEXCOORD4;
  29. half4 tangentWorld : TEXCOORD5;
  30. half4 binormalWorld : TEXCOORD6;
  31. #else
  32. half3 normalWorld : TEXCOORD4;
  33. #endif
  34. #if defined(_RIM_LIGHTING)
  35. float4 positionWS : TEXCOORD8;
  36. #endif
  37. };
  38. VertexOutputSpriteURP2D CombinedShapeLightVertex(VertexInput input)
  39. {
  40. VertexOutputSpriteURP2D output = (VertexOutputSpriteURP2D)0;
  41. UNITY_SETUP_INSTANCE_ID(input);
  42. output.pos = calculateLocalPos(input.vertex);
  43. float4 clipVertex = output.pos / output.pos.w;
  44. output.lightingUV = ComputeScreenPos(clipVertex).xy;
  45. output.vertexColor = calculateVertexColor(input.color);
  46. output.texcoord = float3(calculateTextureCoord(input.texcoord), 0);
  47. float3 positionWS = TransformObjectToWorld(input.vertex.xyz);
  48. float backFaceSign = 1;
  49. #if defined(FIXED_NORMALS_BACKFACE_RENDERING)
  50. backFaceSign = calculateBackfacingSign(positionWS.xyz);
  51. #endif
  52. output.viewDirectionWS = GetCameraPositionWS() - positionWS;
  53. #if defined(_RIM_LIGHTING)
  54. output.positionWS = float4(positionWS, 1);
  55. #endif
  56. half3 normalWS = calculateSpriteWorldNormal(input, -backFaceSign);
  57. output.normalWorld.xyz = normalWS;
  58. #if defined(_RIM_LIGHTING)
  59. #if defined(_NORMALMAP)
  60. output.tangentWorld.xyz = calculateWorldTangent(input.tangent);
  61. output.binormalWorld.xyz = calculateSpriteWorldBinormal(input, output.normalWorld.xyz, output.tangentWorld.xyz, backFaceSign);
  62. #endif
  63. #endif
  64. return output;
  65. }
  66. #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/CombinedShapeLightShared.hlsl"
  67. half4 CombinedShapeLightFragment(VertexOutputSpriteURP2D input) : SV_Target
  68. {
  69. fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
  70. RETURN_UNLIT_IF_ADDITIVE_SLOT(texureColor, input.vertexColor) // shall be called before ALPHA_CLIP
  71. ALPHA_CLIP(texureColor, input.vertexColor)
  72. half4 main = texureColor * input.vertexColor;
  73. half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, input.texcoord.xy);
  74. #if UNITY_VERSION < 202120
  75. half4 pixel = half4(CombinedShapeLightShared(half4(main.rgb, 1), mask, input.lightingUV).rgb, main.a);
  76. #else
  77. SurfaceData2D surfaceData;
  78. InputData2D inputData;
  79. surfaceData.albedo = main.rgb;
  80. surfaceData.alpha = 1;
  81. surfaceData.mask = mask;
  82. inputData.uv = input.texcoord;
  83. inputData.lightingUV = input.lightingUV;
  84. half4 pixel = half4(CombinedShapeLightShared(surfaceData, inputData).rgb, main.a);
  85. #endif
  86. #if defined(_RIM_LIGHTING)
  87. #if defined(_NORMALMAP)
  88. half3 normalWS = calculateNormalFromBumpMap(input.texcoord.xy, input.tangentWorld.xyz, input.binormalWorld.xyz, input.normalWorld.xyz);
  89. #else
  90. half3 normalWS = input.normalWorld.xyz;
  91. #endif
  92. pixel.rgb = applyRimLighting(input.positionWS.xyz, normalWS, pixel);
  93. #endif
  94. APPLY_EMISSION(pixel.rgb, input.texcoord.xy)
  95. pixel = prepareLitPixelForOutput(pixel, texureColor.a, input.vertexColor.a);
  96. COLORISE(pixel)
  97. return pixel;
  98. }
  99. #endif