OSDN Git Service

Added Assets for main menu
[mindgames/Mindgames_main.git] / Mindgames / Library / PackageCache / com.unity.render-pipelines.high-definition@6.9.0-preview / Runtime / Debug / DebugColorPicker.shader
1 Shader "Hidden/HDRP/DebugColorPicker"
2 {
3     SubShader
4     {
5         Tags{ "RenderPipeline" = "HDRenderPipeline" }
6         Pass
7         {
8             ZWrite Off
9             ZTest Always
10             Blend Off
11             Cull Off
12
13             HLSLPROGRAM
14             #pragma target 4.5
15             #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch
16
17             #pragma vertex Vert
18             #pragma fragment Frag
19
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"
25
26             TEXTURE2D(_DebugColorPickerTexture);
27             SAMPLER(sampler_DebugColorPickerTexture);
28
29             float4 _ColorPickerParam; // 4 increasing threshold
30             float3 _ColorPickerFontColor;
31             float _ApplyLinearToSRGB;
32             int _FalseColor;
33             float4 _FalseColorThresholds; // 4 increasing threshold
34
35             struct Attributes
36             {
37                 uint vertexID : SV_VertexID;
38             };
39
40             struct Varyings
41             {
42                 float4 positionCS : SV_POSITION;
43                 float2 texcoord : TEXCOORD0;
44             };
45
46             Varyings Vert(Attributes input)
47             {
48                 Varyings output;
49                 output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID);
50                 output.texcoord = GetNormalizedFullScreenTriangleTexCoord(input.vertexID);
51
52                 return output;
53             }
54
55             float3 FasleColorRemap(float lum, float4 thresholds)
56             {
57                 //Gradient from 0 to 240 deg of HUE gradient
58                 const float l = DegToRad(240) / TWO_PI;
59
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));
63
64                 return HsvToRgb(float3(l - t, 1, 1));
65             }
66
67             float4 DisplayPixelInformationAtMousePosition(Varyings input, float4 result, float4 mouseResult, float4 mousePixelCoord)
68             {
69                 bool flipY = ShouldFlipDebugTexture();
70
71                 if (mousePixelCoord.z >= 0.0 && mousePixelCoord.z <= 1.0 && mousePixelCoord.w >= 0 && mousePixelCoord.w <= 1.0)
72                 {
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)
76                     {
77                         mouseResult.rgb = LinearToSRGB(mouseResult.rgb);
78                     }
79
80                     // Display message offset:
81                     int displayTextOffsetX = 1.5 * DEBUG_FONT_TEXT_WIDTH;
82                     int displayTextOffsetY;
83                     if (flipY)
84                     {
85                         displayTextOffsetY = DEBUG_FONT_TEXT_HEIGHT;
86                     }
87                     else
88                     {
89                         displayTextOffsetY = -DEBUG_FONT_TEXT_HEIGHT;
90                     }
91
92                     uint2 displayUnormCoord = uint2(mousePixelCoord.x + displayTextOffsetX, mousePixelCoord.y + displayTextOffsetY);
93                     uint2 unormCoord = input.positionCS.xy;
94
95                     if (_ColorPickerMode == COLORPICKERDEBUGMODE_BYTE || _ColorPickerMode == COLORPICKERDEBUGMODE_BYTE4)
96                     {
97                         uint4 mouseValue = int4(mouseResult * 255.5);
98
99                         DrawCharacter('R', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
100                         DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
101                         DrawInteger(mouseValue.x, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
102
103                         if (_ColorPickerMode == COLORPICKERDEBUGMODE_BYTE4)
104                         {
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);
120                         }
121                     }
122                     else // float
123                     {
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)
128                         {
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);
144                         }
145                     }
146                 }
147
148                 return result;
149             }
150
151             float4 Frag(Varyings input) : SV_Target
152             {
153                 if (ShouldFlipDebugTexture())
154                 {
155                     input.texcoord.y = 1.0 * _RTHandleScale.y - input.texcoord.y;
156                 }
157
158                 float4 result = SAMPLE_TEXTURE2D(_DebugColorPickerTexture, sampler_DebugColorPickerTexture, input.texcoord);
159
160                 //Decompress value if luxMeter is active
161                 if (_DebugLightingMode == DEBUGLIGHTINGMODE_LUX_METER && _ColorPickerMode != COLORPICKERDEBUGMODE_NONE)
162                     result.rgb = result.rgb * LUXMETER_COMPRESSION_RATIO;
163
164                 if (_DebugLightingMode == DEBUGLIGHTINGMODE_LUMINANCE_METER)
165                 {
166                     result = Luminance(result.rgb);
167                 }
168
169                 if (_FalseColor)
170                     result.rgb = FasleColorRemap(Luminance(result.rgb), _FalseColorThresholds);
171
172                 if (_ColorPickerMode != COLORPICKERDEBUGMODE_NONE)
173                 {
174                     float4 mousePixelCoord = _MousePixelCoord;
175                     if (ShouldFlipDebugTexture())
176                     {
177                         mousePixelCoord.y = _ScreenSize.y - mousePixelCoord.y;
178                         // Note: We must not flip the mousePixelCoord.w coordinate
179                     }
180
181                     float4 mouseResult = SAMPLE_TEXTURE2D(_DebugColorPickerTexture, sampler_DebugColorPickerTexture, mousePixelCoord.zw);
182
183                     //Decompress value if luxMeter is active
184                     if (_DebugLightingMode == DEBUGLIGHTINGMODE_LUX_METER)
185                         mouseResult = mouseResult * LUXMETER_COMPRESSION_RATIO;
186
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);
190
191                     result = DisplayPixelInformationAtMousePosition(input, result, mouseResult, mousePixelCoord);
192                 }
193
194                 return result;
195             }
196
197             ENDHLSL
198         }
199
200     }
201     Fallback Off
202 }