123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Debug/DebuggingCommon.hlsl"
- #if defined(DEBUG_DISPLAY)
- int _ValidationChannels;
- float _RangeMinimum;
- float _RangeMaximum;
- TEXTURE2D_X(_DebugTexture);
- TEXTURE2D(_DebugTextureNoStereo);
- SAMPLER(sampler_DebugTexture);
- half4 _DebugTextureDisplayRect;
- int _DebugRenderTargetSupportsStereo;
- bool CalculateDebugColorRenderingSettings(half4 color, float2 uv, inout half4 debugColor)
- {
- switch(_DebugFullScreenMode)
- {
- case DEBUGFULLSCREENMODE_DEPTH:
- case DEBUGFULLSCREENMODE_MAIN_LIGHT_SHADOW_MAP:
- case DEBUGFULLSCREENMODE_ADDITIONAL_LIGHTS_SHADOW_MAP:
- {
- float2 uvOffset = half2(uv.x - _DebugTextureDisplayRect.x, uv.y - _DebugTextureDisplayRect.y);
- if ((uvOffset.x >= 0) && (uvOffset.x < _DebugTextureDisplayRect.z) &&
- (uvOffset.y >= 0) && (uvOffset.y < _DebugTextureDisplayRect.w))
- {
- float2 debugTextureUv = float2(uvOffset.x / _DebugTextureDisplayRect.z, uvOffset.y / _DebugTextureDisplayRect.w);
- half4 sampleColor = (half4)0;
- if (_DebugRenderTargetSupportsStereo == 1)
- sampleColor = SAMPLE_TEXTURE2D_X(_DebugTexture, sampler_DebugTexture, debugTextureUv);
- else
- sampleColor = SAMPLE_TEXTURE2D(_DebugTextureNoStereo, sampler_DebugTexture, debugTextureUv);
- debugColor = _DebugFullScreenMode == DEBUGFULLSCREENMODE_DEPTH ? half4(sampleColor.rrr, 1) : sampleColor;
- return true;
- }
- else
- {
- return false;
- }
- }
- default:
- {
- return false;
- }
- } // End of switch.
- }
- bool CalculateDebugColorValidationSettings(half4 color, float2 uv, inout half4 debugColor)
- {
- switch(_DebugValidationMode)
- {
- case DEBUGVALIDATIONMODE_HIGHLIGHT_NAN_INF_NEGATIVE:
- {
- #if !defined (SHADER_API_GLES)
- if (AnyIsNaN(color))
- {
- debugColor = half4(1, 0, 0, 1);
- }
- else if (AnyIsInf(color))
- {
- debugColor = half4(0, 1, 0, 1);
- }
- else
- #endif
- if (color.r < 0 || color.g < 0 || color.b < 0 || color.a < 0)
- {
- debugColor = half4(0, 0, 1, 1);
- }
- else
- {
- debugColor = half4(Luminance(color).rrr, 1);
- }
- return true;
- }
- case DEBUGVALIDATIONMODE_HIGHLIGHT_OUTSIDE_OF_RANGE:
- {
- float val;
- if (_ValidationChannels == PIXELVALIDATIONCHANNELS_RGB)
- {
- val = Luminance(color.rgb);
- }
- else if (_ValidationChannels == PIXELVALIDATIONCHANNELS_R)
- {
- val = color.r;
- }
- else if (_ValidationChannels == PIXELVALIDATIONCHANNELS_G)
- {
- val = color.g;
- }
- else if (_ValidationChannels == PIXELVALIDATIONCHANNELS_B)
- {
- val = color.b;
- }
- else if (_ValidationChannels == PIXELVALIDATIONCHANNELS_A)
- {
- val = color.a;
- }
- if (val < _RangeMinimum)
- debugColor = _DebugValidateBelowMinThresholdColor;
- else if (val > _RangeMaximum)
- debugColor = _DebugValidateAboveMaxThresholdColor;
- else
- debugColor = half4(Luminance(color.rgb).rrr, 1);
- return true;
- }
- default:
- {
- return false;
- }
- } // End of switch.
- }
- bool CanDebugOverrideOutputColor(half4 color, float2 uv, inout half4 debugColor)
- {
- return CalculateDebugColorRenderingSettings(color, uv, debugColor) ||
- CalculateDebugColorValidationSettings(color, uv, debugColor);
- }
- #endif
|