Spine-Sprite-DepthNormalsPass-URP.hlsl 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef SPRITES_DEPTH_NORMALS_PASS_URP_INCLUDED
  2. #define SPRITES_DEPTH_NORMALS_PASS_URP_INCLUDED
  3. #include "Include/Spine-Sprite-Common-URP.hlsl"
  4. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  5. #include "SpineCoreShaders/SpriteLighting.cginc"
  6. #include "SpineCoreShaders/Spine-Common.cginc"
  7. #include "Spine-Common-URP.hlsl"
  8. //#include "Include/Spine-Sprite-Common-URP.hlsl"
  9. //#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  10. struct VaryingsSprite
  11. {
  12. float4 pos : SV_POSITION;
  13. fixed4 vertexColor : COLOR;
  14. float3 texcoord : TEXCOORD0;
  15. #if defined(_NORMALMAP)
  16. half4 normalWorld : TEXCOORD4;
  17. half4 tangentWorld : TEXCOORD5;
  18. half4 binormalWorld : TEXCOORD6;
  19. #else
  20. half3 normalWorld : TEXCOORD4;
  21. #endif
  22. UNITY_VERTEX_INPUT_INSTANCE_ID
  23. UNITY_VERTEX_OUTPUT_STEREO
  24. };
  25. VaryingsSprite DepthNormalsVertexSprite(VertexInput input)
  26. {
  27. VaryingsSprite output = (VaryingsSprite)0;
  28. UNITY_SETUP_INSTANCE_ID(input);
  29. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  30. output.pos = calculateLocalPos(input.vertex);
  31. output.vertexColor = calculateVertexColor(input.color);
  32. output.texcoord = float3(calculateTextureCoord(input.texcoord), 0);
  33. float backFaceSign = 1;
  34. #if defined(FIXED_NORMALS_BACKFACE_RENDERING)
  35. backFaceSign = calculateBackfacingSign(positionWS.xyz);
  36. #endif
  37. half3 normalWS = calculateSpriteWorldNormal(input, -backFaceSign);
  38. output.normalWorld.xyz = normalWS;
  39. #if defined(_NORMALMAP)
  40. output.tangentWorld.xyz = calculateWorldTangent(input.tangent);
  41. output.binormalWorld.xyz = calculateSpriteWorldBinormal(input, output.normalWorld.xyz, output.tangentWorld.xyz, backFaceSign);
  42. #endif
  43. return output;
  44. }
  45. void DepthNormalsFragmentSprite(VaryingsSprite input,
  46. out half4 outNormalWS : SV_Target0
  47. #ifdef _WRITE_RENDERING_LAYERS
  48. , out float4 outRenderingLayers : SV_Target1
  49. #endif
  50. )
  51. {
  52. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  53. fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
  54. ALPHA_CLIP(texureColor, input.vertexColor)
  55. #if defined(PER_PIXEL_LIGHTING) && defined(_NORMALMAP)
  56. half3 normalWS = calculateNormalFromBumpMap(input.texcoord.xy, input.tangentWorld.xyz, input.binormalWorld.xyz, input.normalWorld.xyz);
  57. #else
  58. half3 normalWS = input.normalWorld.xyz;
  59. #endif
  60. #if defined(_GBUFFER_NORMALS_OCT)
  61. float2 octNormalWS = PackNormalOctQuadEncode(normalWS); // values between [-1, +1], must use fp32 on some platforms.
  62. float2 remappedOctNormalWS = saturate(octNormalWS * 0.5 + 0.5); // values between [ 0, 1]
  63. half3 packedNormalWS = PackFloat2To888(remappedOctNormalWS); // values between [ 0, 1]
  64. outNormalWS = half4(packedNormalWS, 0.0);
  65. #else
  66. outNormalWS = half4(normalWS, 0.0);
  67. #endif
  68. #ifdef USE_WRITE_RENDERING_LAYERS
  69. uint renderingLayers = GetMeshRenderingLayerBackwardsCompatible();
  70. outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0);
  71. #endif
  72. }
  73. #endif