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.

DebuggingFullscreen.hlsl 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Debug/DebuggingCommon.hlsl"
  2. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl"
  3. #if defined(DEBUG_DISPLAY)
  4. int _DebugMaxPixelCost;
  5. int _ValidationChannels;
  6. float _RangeMinimum;
  7. float _RangeMaximum;
  8. TEXTURE2D_X(_DebugTexture);
  9. TEXTURE2D(_DebugTextureNoStereo);
  10. // 2023.3 Deprecated. This is for backwards compatibility. Remove in the future.
  11. #define sampler_DebugTexture sampler_PointClamp
  12. half4 _DebugTextureDisplayRect;
  13. int _DebugRenderTargetSupportsStereo;
  14. float4 _DebugRenderTargetRangeRemap;
  15. // CPU parametrized, non-clamping, range remap. (RangeRemap in common.hlsl saturates!)
  16. half4 RemapSourceRange(half4 source)
  17. {
  18. float4 r = _DebugRenderTargetRangeRemap;
  19. float4 s = source;
  20. // Remap(float origFrom, float origTo, float targetFrom, float targetTo, float value)
  21. s.r = Remap(r.x, r.y, r.z, r.w, s.r);
  22. s.g = Remap(r.x, r.y, r.z, r.w, s.g);
  23. s.b = Remap(r.x, r.y, r.z, r.w, s.b);
  24. s.a = Remap(r.x, r.y, r.z, r.w, s.a);
  25. return half4(s);
  26. }
  27. bool CalculateDebugColorRenderingSettings(half4 color, float2 uv, inout half4 debugColor)
  28. {
  29. if (_DebugSceneOverrideMode == DEBUGSCENEOVERRIDEMODE_OVERDRAW)
  30. {
  31. // color.r is (Number of overdraw / Max displayed overdraw count)
  32. debugColor.rgb = GetOverdrawColor(color.r * _DebugMaxPixelCost, _DebugMaxPixelCost).rgb;
  33. DrawOverdrawLegend(uv, _DebugMaxPixelCost, _ScreenSize, debugColor.rgb);
  34. return true;
  35. }
  36. if (_DebugMipInfoMode != DEBUGMIPINFOMODE_NONE)
  37. {
  38. debugColor = color; // just passing through
  39. // draw legend
  40. switch(_DebugMipInfoMode)
  41. {
  42. case DEBUGMIPINFOMODE_MIP_COUNT:
  43. DrawMipCountLegend(uv, _ScreenSize, debugColor.rgb);
  44. break;
  45. case DEBUGMIPINFOMODE_MIP_RATIO:
  46. DrawMipRatioLegend(uv, _ScreenSize, debugColor.rgb);
  47. break;
  48. case DEBUGMIPINFOMODE_MIP_STREAMING_STATUS:
  49. if (_DebugMipMapStatusMode == DEBUGMIPMAPSTATUSMODE_TEXTURE)
  50. DrawMipStreamingStatusLegend(uv, _ScreenSize, _DebugMipMapShowStatusCode, debugColor.rgb);
  51. else
  52. DrawMipStreamingStatusPerMaterialLegend(uv, _ScreenSize, debugColor.rgb);
  53. break;
  54. case DEBUGMIPINFOMODE_MIP_STREAMING_PERFORMANCE:
  55. DrawTextureStreamingPerformanceLegend(uv, _ScreenSize, debugColor.rgb);
  56. break;
  57. case DEBUGMIPINFOMODE_MIP_STREAMING_PRIORITY:
  58. DrawMipPriorityLegend(uv, _ScreenSize, debugColor.rgb);
  59. break;
  60. case DEBUGMIPINFOMODE_MIP_STREAMING_ACTIVITY:
  61. DrawMipRecentlyUpdatedLegend(uv, _ScreenSize, _DebugMipMapStatusMode == DEBUGMIPMAPSTATUSMODE_MATERIAL, debugColor.rgb);
  62. break;
  63. }
  64. return true;
  65. }
  66. switch(_DebugFullScreenMode)
  67. {
  68. case DEBUGFULLSCREENMODE_DEPTH:
  69. case DEBUGFULLSCREENMODE_MOTION_VECTOR:
  70. case DEBUGFULLSCREENMODE_MAIN_LIGHT_SHADOW_MAP:
  71. case DEBUGFULLSCREENMODE_ADDITIONAL_LIGHTS_SHADOW_MAP:
  72. case DEBUGFULLSCREENMODE_ADDITIONAL_LIGHTS_COOKIE_ATLAS:
  73. case DEBUGFULLSCREENMODE_REFLECTION_PROBE_ATLAS:
  74. case DEBUGFULLSCREENMODE_STP:
  75. {
  76. float2 uvOffset = half2(uv.x - _DebugTextureDisplayRect.x, uv.y - _DebugTextureDisplayRect.y);
  77. if ((uvOffset.x >= 0) && (uvOffset.x < _DebugTextureDisplayRect.z) &&
  78. (uvOffset.y >= 0) && (uvOffset.y < _DebugTextureDisplayRect.w))
  79. {
  80. float2 debugTextureUv = float2(uvOffset.x / _DebugTextureDisplayRect.z, uvOffset.y / _DebugTextureDisplayRect.w);
  81. half4 sampleColor = (half4)0;
  82. if (_DebugRenderTargetSupportsStereo == 1)
  83. sampleColor = SAMPLE_TEXTURE2D_X(_DebugTexture, sampler_DebugTexture, debugTextureUv);
  84. else
  85. sampleColor = SAMPLE_TEXTURE2D(_DebugTextureNoStereo, sampler_DebugTexture, debugTextureUv);
  86. // Optionally remap source to valid visualization range.
  87. if(any(_DebugRenderTargetRangeRemap != 0))
  88. {
  89. sampleColor.rgb = RemapSourceRange(sampleColor).rgb;
  90. }
  91. if (_DebugFullScreenMode == DEBUGFULLSCREENMODE_DEPTH)
  92. {
  93. debugColor = half4(sampleColor.rrr, 1);
  94. }
  95. else if (_DebugFullScreenMode == DEBUGFULLSCREENMODE_MOTION_VECTOR)
  96. {
  97. // Motion vector is RG only.
  98. debugColor = half4(sampleColor.rg, 0, 1);
  99. }
  100. else if (_DebugFullScreenMode == DEBUGFULLSCREENMODE_STP)
  101. {
  102. // This is encoded in gamma 2.0 (so the square is needed to get it back to linear).
  103. debugColor = sampleColor * sampleColor;
  104. }
  105. else
  106. {
  107. debugColor = sampleColor;
  108. }
  109. return true;
  110. }
  111. else
  112. {
  113. return false;
  114. }
  115. }
  116. default:
  117. {
  118. return false;
  119. }
  120. } // End of switch.
  121. }
  122. bool CalculateDebugColorValidationSettings(half4 color, float2 uv, inout half4 debugColor)
  123. {
  124. switch(_DebugValidationMode)
  125. {
  126. case DEBUGVALIDATIONMODE_HIGHLIGHT_NAN_INF_NEGATIVE:
  127. {
  128. if (AnyIsNaN(color))
  129. {
  130. debugColor = half4(1, 0, 0, 1);
  131. }
  132. else if (AnyIsInf(color))
  133. {
  134. debugColor = half4(0, 1, 0, 1);
  135. }
  136. else if (color.r < 0 || color.g < 0 || color.b < 0 || color.a < 0)
  137. {
  138. debugColor = half4(0, 0, 1, 1);
  139. }
  140. else
  141. {
  142. debugColor = half4(Luminance(color).rrr, 1);
  143. }
  144. return true;
  145. }
  146. case DEBUGVALIDATIONMODE_HIGHLIGHT_OUTSIDE_OF_RANGE:
  147. {
  148. float val;
  149. if (_ValidationChannels == PIXELVALIDATIONCHANNELS_RGB)
  150. {
  151. val = Luminance(color.rgb);
  152. }
  153. else if (_ValidationChannels == PIXELVALIDATIONCHANNELS_R)
  154. {
  155. val = color.r;
  156. }
  157. else if (_ValidationChannels == PIXELVALIDATIONCHANNELS_G)
  158. {
  159. val = color.g;
  160. }
  161. else if (_ValidationChannels == PIXELVALIDATIONCHANNELS_B)
  162. {
  163. val = color.b;
  164. }
  165. else if (_ValidationChannels == PIXELVALIDATIONCHANNELS_A)
  166. {
  167. val = color.a;
  168. }
  169. if (val < _RangeMinimum)
  170. debugColor = _DebugValidateBelowMinThresholdColor;
  171. else if (val > _RangeMaximum)
  172. debugColor = _DebugValidateAboveMaxThresholdColor;
  173. else
  174. debugColor = half4(Luminance(color.rgb).rrr, 1);
  175. return true;
  176. }
  177. default:
  178. {
  179. return false;
  180. }
  181. } // End of switch.
  182. }
  183. bool CanDebugOverrideOutputColor(half4 color, float2 uv, inout half4 debugColor)
  184. {
  185. return CalculateDebugColorRenderingSettings(color, uv, debugColor) ||
  186. CalculateDebugColorValidationSettings(color, uv, debugColor);
  187. }
  188. #endif