Spine-Sprite-NormalsPass-URP-2D.hlsl 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef SPRITE_NORMALS_PASS_URP_INCLUDED
  2. #define SPRITE_NORMALS_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. struct Varyings
  7. {
  8. float4 positionCS : SV_POSITION;
  9. float4 color : COLOR;
  10. float2 uv : TEXCOORD0;
  11. float3 normalWS : TEXCOORD1;
  12. float3 tangentWS : TEXCOORD2;
  13. float3 bitangentWS : TEXCOORD3;
  14. };
  15. SAMPLER(sampler_BumpMap);
  16. float4 _BumpMap_ST;
  17. Varyings NormalsRenderingVertex(VertexInput attributes)
  18. {
  19. Varyings o = (Varyings)0;
  20. o.positionCS = calculateLocalPos(attributes.vertex);
  21. o.uv = attributes.texcoord.xy;
  22. o.color = attributes.color;
  23. o.normalWS = TransformObjectToWorldDir(float3(0, 0, -1));
  24. float3 positionWS = TransformObjectToWorld(attributes.vertex.xyz);
  25. float backFaceSign = 1;
  26. #if defined(FIXED_NORMALS_BACKFACE_RENDERING)
  27. backFaceSign = calculateBackfacingSign(positionWS.xyz);
  28. #endif
  29. half3 normalWS = calculateSpriteWorldNormal(attributes, -backFaceSign);
  30. o.normalWS.xyz = normalWS;
  31. #if defined(_NORMALMAP)
  32. o.tangentWS.xyz = calculateWorldTangent(attributes.tangent);
  33. o.bitangentWS.xyz = calculateSpriteWorldBinormal(attributes, o.normalWS.xyz, o.tangentWS.xyz, backFaceSign);
  34. #endif
  35. return o;
  36. }
  37. #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/NormalsRenderingShared.hlsl"
  38. half4 NormalsRenderingFragment(Varyings i) : SV_Target
  39. {
  40. half4 mainTex = i.color * tex2D(_MainTex, i.uv);
  41. #if defined(_NORMALMAP)
  42. half3 normalTS = normalize(UnpackScaleNormal(tex2D(_BumpMap, i.uv.xy), _BumpScale));
  43. return NormalsRenderingShared(mainTex, normalTS, i.tangentWS.xyz, i.bitangentWS.xyz, i.normalWS.xyz);
  44. #else
  45. half3 normalTS = half3(0, 0, 1);
  46. half3 tangentWS = half3(0, 0, 0);
  47. half3 bitangentWS = half3(0, 0, 0);
  48. half3 normalWS = i.normalWS.xyz;
  49. return NormalsRenderingShared(mainTex, normalTS, tangentWS, bitangentWS, normalWS);
  50. #endif
  51. }
  52. #endif