1 Shader "Hidden/HDRP/DebugColorPicker"
5 Tags{ "RenderPipeline" = "HDRenderPipeline" }
15 #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch
20 #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
21 #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
22 #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
23 #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl"
24 #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
26 TEXTURE2D(_DebugColorPickerTexture);
27 SAMPLER(sampler_DebugColorPickerTexture);
29 float4 _ColorPickerParam; // 4 increasing threshold
30 float3 _ColorPickerFontColor;
31 float _ApplyLinearToSRGB;
33 float4 _FalseColorThresholds; // 4 increasing threshold
37 uint vertexID : SV_VertexID;
42 float4 positionCS : SV_POSITION;
43 float2 texcoord : TEXCOORD0;
46 Varyings Vert(Attributes input)
49 output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID);
50 output.texcoord = GetNormalizedFullScreenTriangleTexCoord(input.vertexID);
55 float3 FasleColorRemap(float lum, float4 thresholds)
57 //Gradient from 0 to 240 deg of HUE gradient
58 const float l = DegToRad(240) / TWO_PI;
60 float t = lerp(0.0, l / 3, RangeRemap(thresholds.x, thresholds.y, lum))
61 + lerp(0.0, l / 3, RangeRemap(thresholds.y, thresholds.z, lum))
62 + lerp(0.0, l / 3, RangeRemap(thresholds.z, thresholds.w, lum));
64 return HsvToRgb(float3(l - t, 1, 1));
67 float4 DisplayPixelInformationAtMousePosition(Varyings input, float4 result, float4 mouseResult, float4 mousePixelCoord)
69 bool flipY = ShouldFlipDebugTexture();
71 if (mousePixelCoord.z >= 0.0 && mousePixelCoord.z <= 1.0 && mousePixelCoord.w >= 0 && mousePixelCoord.w <= 1.0)
73 // As when we read with the color picker we don't go through the final blit (that current hardcode a conversion to sRGB)
74 // and as our material debug take it into account, we need to a transform here.
75 if (_ApplyLinearToSRGB > 0.0)
77 mouseResult.rgb = LinearToSRGB(mouseResult.rgb);
80 // Display message offset:
81 int displayTextOffsetX = 1.5 * DEBUG_FONT_TEXT_WIDTH;
82 int displayTextOffsetY;
85 displayTextOffsetY = DEBUG_FONT_TEXT_HEIGHT;
89 displayTextOffsetY = -DEBUG_FONT_TEXT_HEIGHT;
92 uint2 displayUnormCoord = uint2(mousePixelCoord.x + displayTextOffsetX, mousePixelCoord.y + displayTextOffsetY);
93 uint2 unormCoord = input.positionCS.xy;
95 if (_ColorPickerMode == COLORPICKERDEBUGMODE_BYTE || _ColorPickerMode == COLORPICKERDEBUGMODE_BYTE4)
97 uint4 mouseValue = int4(mouseResult * 255.5);
99 DrawCharacter('R', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
100 DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
101 DrawInteger(mouseValue.x, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
103 if (_ColorPickerMode == COLORPICKERDEBUGMODE_BYTE4)
105 displayUnormCoord.x = mousePixelCoord.x + displayTextOffsetX;
106 displayUnormCoord.y += displayTextOffsetY;
107 DrawCharacter('G', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
108 DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
109 DrawInteger(mouseValue.y, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
110 displayUnormCoord.x = mousePixelCoord.x + displayTextOffsetX;
111 displayUnormCoord.y += displayTextOffsetY;
112 DrawCharacter('B', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
113 DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
114 DrawInteger(mouseValue.z, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
115 displayUnormCoord.x = mousePixelCoord.x + displayTextOffsetX;
116 displayUnormCoord.y += displayTextOffsetY;
117 DrawCharacter('A', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
118 DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
119 DrawInteger(mouseValue.w, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
124 DrawCharacter('X', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
125 DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
126 DrawFloat(mouseResult.x, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
127 if (_ColorPickerMode == COLORPICKERDEBUGMODE_FLOAT4)
129 displayUnormCoord.x = mousePixelCoord.x + displayTextOffsetX;
130 displayUnormCoord.y += displayTextOffsetY;
131 DrawCharacter('Y', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
132 DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
133 DrawFloat(mouseResult.y, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
134 displayUnormCoord.x = mousePixelCoord.x + displayTextOffsetX;
135 displayUnormCoord.y += displayTextOffsetY;
136 DrawCharacter('Z', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
137 DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
138 DrawFloat(mouseResult.z, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
139 displayUnormCoord.x = mousePixelCoord.x + displayTextOffsetX;
140 displayUnormCoord.y += displayTextOffsetY;
141 DrawCharacter('W', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
142 DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
143 DrawFloat(mouseResult.w, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
151 float4 Frag(Varyings input) : SV_Target
153 if (ShouldFlipDebugTexture())
155 input.texcoord.y = 1.0 * _RTHandleScale.y - input.texcoord.y;
158 float4 result = SAMPLE_TEXTURE2D(_DebugColorPickerTexture, sampler_DebugColorPickerTexture, input.texcoord);
160 //Decompress value if luxMeter is active
161 if (_DebugLightingMode == DEBUGLIGHTINGMODE_LUX_METER && _ColorPickerMode != COLORPICKERDEBUGMODE_NONE)
162 result.rgb = result.rgb * LUXMETER_COMPRESSION_RATIO;
164 if (_DebugLightingMode == DEBUGLIGHTINGMODE_LUMINANCE_METER)
166 result = Luminance(result.rgb);
170 result.rgb = FasleColorRemap(Luminance(result.rgb), _FalseColorThresholds);
172 if (_ColorPickerMode != COLORPICKERDEBUGMODE_NONE)
174 float4 mousePixelCoord = _MousePixelCoord;
175 if (ShouldFlipDebugTexture())
177 mousePixelCoord.y = _ScreenSize.y - mousePixelCoord.y;
178 // Note: We must not flip the mousePixelCoord.w coordinate
181 float4 mouseResult = SAMPLE_TEXTURE2D(_DebugColorPickerTexture, sampler_DebugColorPickerTexture, mousePixelCoord.zw);
183 //Decompress value if luxMeter is active
184 if (_DebugLightingMode == DEBUGLIGHTINGMODE_LUX_METER)
185 mouseResult = mouseResult * LUXMETER_COMPRESSION_RATIO;
187 // Reverse debug exposure in order to display the real values.
188 // _DebugExposure will be set to zero if the debug view does not need it so we don't need to make a special case here. It's handled in only one place in C#
189 mouseResult = mouseResult / exp2(_DebugExposure);
191 result = DisplayPixelInformationAtMousePosition(input, result, mouseResult, mousePixelCoord);