Ei kuvausta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CombinedShapeLightShared.hlsl 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #ifndef COMBINED_SHAPE_LIGHT_PASS
  2. #define COMBINED_SHAPE_LIGHT_PASS
  3. #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/SurfaceData2D.hlsl"
  4. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Debug/Debugging2D.hlsl"
  5. #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/ShapeLightVariables.hlsl"
  6. half4 CombinedShapeLightShared(in SurfaceData2D surfaceData, in InputData2D inputData)
  7. {
  8. #if defined(DEBUG_DISPLAY)
  9. half4 debugColor = 0;
  10. if (CanDebugOverrideOutputColor(surfaceData, inputData, debugColor))
  11. {
  12. return debugColor;
  13. }
  14. #endif
  15. half alpha = surfaceData.alpha;
  16. half4 color = half4(surfaceData.albedo, alpha);
  17. const half4 mask = surfaceData.mask;
  18. const half2 lightingUV = inputData.lightingUV;
  19. if (alpha == 0.0)
  20. discard;
  21. #if USE_SHAPE_LIGHT_TYPE_0
  22. half4 shapeLight0 = SAMPLE_TEXTURE2D(_ShapeLightTexture0, sampler_ShapeLightTexture0, lightingUV);
  23. if (any(_ShapeLightMaskFilter0))
  24. {
  25. half4 processedMask = (1 - _ShapeLightInvertedFilter0) * mask + _ShapeLightInvertedFilter0 * (1 - mask);
  26. shapeLight0 *= dot(processedMask, _ShapeLightMaskFilter0);
  27. }
  28. half4 shapeLight0Modulate = shapeLight0 * _ShapeLightBlendFactors0.x;
  29. half4 shapeLight0Additive = shapeLight0 * _ShapeLightBlendFactors0.y;
  30. #else
  31. half4 shapeLight0Modulate = 0;
  32. half4 shapeLight0Additive = 0;
  33. #endif
  34. #if USE_SHAPE_LIGHT_TYPE_1
  35. half4 shapeLight1 = SAMPLE_TEXTURE2D(_ShapeLightTexture1, sampler_ShapeLightTexture1, lightingUV);
  36. if (any(_ShapeLightMaskFilter1))
  37. {
  38. half4 processedMask = (1 - _ShapeLightInvertedFilter1) * mask + _ShapeLightInvertedFilter1 * (1 - mask);
  39. shapeLight1 *= dot(processedMask, _ShapeLightMaskFilter1);
  40. }
  41. half4 shapeLight1Modulate = shapeLight1 * _ShapeLightBlendFactors1.x;
  42. half4 shapeLight1Additive = shapeLight1 * _ShapeLightBlendFactors1.y;
  43. #else
  44. half4 shapeLight1Modulate = 0;
  45. half4 shapeLight1Additive = 0;
  46. #endif
  47. #if USE_SHAPE_LIGHT_TYPE_2
  48. half4 shapeLight2 = SAMPLE_TEXTURE2D(_ShapeLightTexture2, sampler_ShapeLightTexture2, lightingUV);
  49. if (any(_ShapeLightMaskFilter2))
  50. {
  51. half4 processedMask = (1 - _ShapeLightInvertedFilter2) * mask + _ShapeLightInvertedFilter2 * (1 - mask);
  52. shapeLight2 *= dot(processedMask, _ShapeLightMaskFilter2);
  53. }
  54. half4 shapeLight2Modulate = shapeLight2 * _ShapeLightBlendFactors2.x;
  55. half4 shapeLight2Additive = shapeLight2 * _ShapeLightBlendFactors2.y;
  56. #else
  57. half4 shapeLight2Modulate = 0;
  58. half4 shapeLight2Additive = 0;
  59. #endif
  60. #if USE_SHAPE_LIGHT_TYPE_3
  61. half4 shapeLight3 = SAMPLE_TEXTURE2D(_ShapeLightTexture3, sampler_ShapeLightTexture3, lightingUV);
  62. if (any(_ShapeLightMaskFilter3))
  63. {
  64. half4 processedMask = (1 - _ShapeLightInvertedFilter3) * mask + _ShapeLightInvertedFilter3 * (1 - mask);
  65. shapeLight3 *= dot(processedMask, _ShapeLightMaskFilter3);
  66. }
  67. half4 shapeLight3Modulate = shapeLight3 * _ShapeLightBlendFactors3.x;
  68. half4 shapeLight3Additive = shapeLight3 * _ShapeLightBlendFactors3.y;
  69. #else
  70. half4 shapeLight3Modulate = 0;
  71. half4 shapeLight3Additive = 0;
  72. #endif
  73. half4 finalOutput;
  74. #if !USE_SHAPE_LIGHT_TYPE_0 && !USE_SHAPE_LIGHT_TYPE_1 && !USE_SHAPE_LIGHT_TYPE_2 && ! USE_SHAPE_LIGHT_TYPE_3
  75. finalOutput = color;
  76. #else
  77. half4 finalModulate = shapeLight0Modulate + shapeLight1Modulate + shapeLight2Modulate + shapeLight3Modulate;
  78. half4 finalAdditve = shapeLight0Additive + shapeLight1Additive + shapeLight2Additive + shapeLight3Additive;
  79. finalOutput = _HDREmulationScale * (color * finalModulate + finalAdditve);
  80. #endif
  81. finalOutput.a = alpha;
  82. return max(0, finalOutput);
  83. }
  84. #endif