Debugging2D.hlsl 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #ifndef UNIVERSAL_DEBUGGING2D_INCLUDED
  2. #define UNIVERSAL_DEBUGGING2D_INCLUDED
  3. #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/InputData2D.hlsl"
  4. #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/SurfaceData2D.hlsl"
  5. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Debug/DebuggingCommon.hlsl"
  6. #if defined(DEBUG_DISPLAY)
  7. #define SETUP_DEBUG_TEXTURE_DATA_2D(inputData, positionWS, texture) SetupDebugDataTexture(inputData, positionWS, texture##_TexelSize, texture##_MipInfo, GetMipCount(TEXTURE2D_ARGS(texture, sampler##texture)))
  8. #define SETUP_DEBUG_DATA_2D(inputData, positionWS) SetupDebugData(inputData, positionWS)
  9. void SetupDebugData(inout InputData2D inputData, float3 positionWS)
  10. {
  11. inputData.positionWS = positionWS;
  12. }
  13. void SetupDebugDataTexture(inout InputData2D inputData, float3 positionWS, float4 texelSize, float4 mipInfo, uint mipCount)
  14. {
  15. SetupDebugData(inputData, positionWS);
  16. inputData.texelSize = texelSize;
  17. inputData.mipInfo = mipInfo;
  18. inputData.mipCount = mipCount;
  19. }
  20. bool CalculateDebugColorMaterialSettings(in SurfaceData2D surfaceData, in InputData2D inputData, inout half4 debugColor)
  21. {
  22. switch(_DebugMaterialMode)
  23. {
  24. case DEBUGMATERIALMODE_NONE:
  25. {
  26. return false;
  27. }
  28. case DEBUGMATERIALMODE_ALBEDO:
  29. {
  30. debugColor = half4(surfaceData.albedo, 1);
  31. return true;
  32. }
  33. case DEBUGMATERIALMODE_ALPHA:
  34. {
  35. debugColor = half4(surfaceData.alpha.rrr, 1);
  36. return true;
  37. }
  38. case DEBUGMATERIALMODE_SPRITE_MASK:
  39. {
  40. debugColor = surfaceData.mask;
  41. return true;
  42. }
  43. case DEBUGMATERIALMODE_NORMAL_TANGENT_SPACE:
  44. case DEBUGMATERIALMODE_NORMAL_WORLD_SPACE:
  45. {
  46. debugColor = half4(surfaceData.normalTS, 1);
  47. return true;
  48. }
  49. default:
  50. {
  51. return TryGetDebugColorInvalidMode(debugColor);
  52. }
  53. }
  54. }
  55. bool CalculateDebugColorForRenderingSettings(in SurfaceData2D surfaceData, in InputData2D inputData, inout half4 debugColor)
  56. {
  57. if (CalculateColorForDebugSceneOverride(debugColor))
  58. {
  59. return true;
  60. }
  61. return TryGetDebugColorInvalidMode(debugColor);
  62. }
  63. bool CalculateDebugColorLightingSettings(inout SurfaceData2D surfaceData, inout InputData2D inputData, inout half4 debugColor)
  64. {
  65. switch(_DebugLightingMode)
  66. {
  67. case DEBUGLIGHTINGMODE_NONE:
  68. {
  69. return false;
  70. }
  71. case DEBUGLIGHTINGMODE_LIGHTING_WITHOUT_NORMAL_MAPS:
  72. case DEBUGLIGHTINGMODE_LIGHTING_WITH_NORMAL_MAPS:
  73. {
  74. surfaceData.albedo = 1;
  75. return false;
  76. }
  77. default:
  78. {
  79. return TryGetDebugColorInvalidMode(debugColor);
  80. }
  81. } // End of switch.
  82. }
  83. bool CalculateDebugColorValidationSettings(in SurfaceData2D surfaceData, in InputData2D inputData, inout half4 debugColor)
  84. {
  85. switch(_DebugMaterialValidationMode)
  86. {
  87. case DEBUGMATERIALVALIDATIONMODE_NONE:
  88. return false;
  89. case DEBUGMATERIALVALIDATIONMODE_ALBEDO:
  90. return CalculateValidationAlbedo(surfaceData.albedo, debugColor);
  91. default:
  92. return TryGetDebugColorInvalidMode(debugColor);
  93. }
  94. }
  95. bool CanDebugOverrideOutputColor(inout SurfaceData2D surfaceData, inout InputData2D inputData, inout half4 debugColor)
  96. {
  97. if (CalculateDebugColorMaterialSettings(surfaceData, inputData, debugColor))
  98. {
  99. return _DebugMaterialMode != DEBUGMATERIALMODE_SPRITE_MASK;
  100. }
  101. else if (CalculateDebugColorForRenderingSettings(surfaceData, inputData, debugColor))
  102. {
  103. return true;
  104. }
  105. else if (CalculateDebugColorLightingSettings(surfaceData, inputData, debugColor))
  106. {
  107. return true;
  108. }
  109. else if (CalculateDebugColorValidationSettings(surfaceData, inputData, debugColor))
  110. {
  111. return true;
  112. }
  113. else
  114. {
  115. return false;
  116. }
  117. }
  118. #else
  119. #define SETUP_DEBUG_TEXTURE_DATA_2D(inputData, positionWS, texture)
  120. #define SETUP_DEBUG_DATA_2D(inputData, positionWS)
  121. #endif
  122. #endif