DebuggingFullscreen.hlsl 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Debug/DebuggingCommon.hlsl"
  2. #if defined(DEBUG_DISPLAY)
  3. int _ValidationChannels;
  4. float _RangeMinimum;
  5. float _RangeMaximum;
  6. TEXTURE2D_X(_DebugTexture);
  7. TEXTURE2D(_DebugTextureNoStereo);
  8. SAMPLER(sampler_DebugTexture);
  9. half4 _DebugTextureDisplayRect;
  10. int _DebugRenderTargetSupportsStereo;
  11. bool CalculateDebugColorRenderingSettings(half4 color, float2 uv, inout half4 debugColor)
  12. {
  13. switch(_DebugFullScreenMode)
  14. {
  15. case DEBUGFULLSCREENMODE_DEPTH:
  16. case DEBUGFULLSCREENMODE_MAIN_LIGHT_SHADOW_MAP:
  17. case DEBUGFULLSCREENMODE_ADDITIONAL_LIGHTS_SHADOW_MAP:
  18. {
  19. float2 uvOffset = half2(uv.x - _DebugTextureDisplayRect.x, uv.y - _DebugTextureDisplayRect.y);
  20. if ((uvOffset.x >= 0) && (uvOffset.x < _DebugTextureDisplayRect.z) &&
  21. (uvOffset.y >= 0) && (uvOffset.y < _DebugTextureDisplayRect.w))
  22. {
  23. float2 debugTextureUv = float2(uvOffset.x / _DebugTextureDisplayRect.z, uvOffset.y / _DebugTextureDisplayRect.w);
  24. half4 sampleColor = (half4)0;
  25. if (_DebugRenderTargetSupportsStereo == 1)
  26. sampleColor = SAMPLE_TEXTURE2D_X(_DebugTexture, sampler_DebugTexture, debugTextureUv);
  27. else
  28. sampleColor = SAMPLE_TEXTURE2D(_DebugTextureNoStereo, sampler_DebugTexture, debugTextureUv);
  29. debugColor = _DebugFullScreenMode == DEBUGFULLSCREENMODE_DEPTH ? half4(sampleColor.rrr, 1) : sampleColor;
  30. return true;
  31. }
  32. else
  33. {
  34. return false;
  35. }
  36. }
  37. default:
  38. {
  39. return false;
  40. }
  41. } // End of switch.
  42. }
  43. bool CalculateDebugColorValidationSettings(half4 color, float2 uv, inout half4 debugColor)
  44. {
  45. switch(_DebugValidationMode)
  46. {
  47. case DEBUGVALIDATIONMODE_HIGHLIGHT_NAN_INF_NEGATIVE:
  48. {
  49. #if !defined (SHADER_API_GLES)
  50. if (AnyIsNaN(color))
  51. {
  52. debugColor = half4(1, 0, 0, 1);
  53. }
  54. else if (AnyIsInf(color))
  55. {
  56. debugColor = half4(0, 1, 0, 1);
  57. }
  58. else
  59. #endif
  60. if (color.r < 0 || color.g < 0 || color.b < 0 || color.a < 0)
  61. {
  62. debugColor = half4(0, 0, 1, 1);
  63. }
  64. else
  65. {
  66. debugColor = half4(Luminance(color).rrr, 1);
  67. }
  68. return true;
  69. }
  70. case DEBUGVALIDATIONMODE_HIGHLIGHT_OUTSIDE_OF_RANGE:
  71. {
  72. float val;
  73. if (_ValidationChannels == PIXELVALIDATIONCHANNELS_RGB)
  74. {
  75. val = Luminance(color.rgb);
  76. }
  77. else if (_ValidationChannels == PIXELVALIDATIONCHANNELS_R)
  78. {
  79. val = color.r;
  80. }
  81. else if (_ValidationChannels == PIXELVALIDATIONCHANNELS_G)
  82. {
  83. val = color.g;
  84. }
  85. else if (_ValidationChannels == PIXELVALIDATIONCHANNELS_B)
  86. {
  87. val = color.b;
  88. }
  89. else if (_ValidationChannels == PIXELVALIDATIONCHANNELS_A)
  90. {
  91. val = color.a;
  92. }
  93. if (val < _RangeMinimum)
  94. debugColor = _DebugValidateBelowMinThresholdColor;
  95. else if (val > _RangeMaximum)
  96. debugColor = _DebugValidateAboveMaxThresholdColor;
  97. else
  98. debugColor = half4(Luminance(color.rgb).rrr, 1);
  99. return true;
  100. }
  101. default:
  102. {
  103. return false;
  104. }
  105. } // End of switch.
  106. }
  107. bool CanDebugOverrideOutputColor(half4 color, float2 uv, inout half4 debugColor)
  108. {
  109. return CalculateDebugColorRenderingSettings(color, uv, debugColor) ||
  110. CalculateDebugColorValidationSettings(color, uv, debugColor);
  111. }
  112. #endif