@@ -61,10 +61,10 @@ float4 SampleLinear(float2 uvTexspace)
6161
6262float4 PixelAntialiasing (float2 uvTexspace)
6363{
64- if ((g_PushConstants.InverseDisplaySize.y / g_PushConstants.InverseDisplaySize.x ) >= (4.0 / 3.0 ))
65- uvTexspace *= g_PushConstants.InverseDisplaySize.y * 720.0f ;
64+ if ((g_PushConstants.DisplaySize.x * g_PushConstants.InverseDisplaySize.y ) >= (4.0 / 3.0 ))
65+ uvTexspace *= g_PushConstants.InverseDisplaySize.y * 720.0 ;
6666 else
67- uvTexspace *= g_PushConstants.InverseDisplaySize.x * 960.0f ;
67+ uvTexspace *= g_PushConstants.InverseDisplaySize.x * 960.0 ;
6868
6969 float2 seam = floor (uvTexspace + 0.5 );
7070 uvTexspace = (uvTexspace - seam) / fwidth (uvTexspace) + seam;
@@ -78,6 +78,51 @@ float median(float r, float g, float b)
7878 return max (min (r, g), min (max (r, g), b));
7979}
8080
81+ float4 SampleSdfFont (float4 color, Texture2D <float4 > texture, float2 uv, float2 screenTexSize)
82+ {
83+ float4 textureColor = texture.Sample (g_SamplerDescriptorHeap[0 ], uv);
84+
85+ uint width, height;
86+ texture.GetDimensions (width, height);
87+
88+ float pxRange = 8.0 ;
89+ float2 unitRange = pxRange / float2 (width, height);
90+ float screenPxRange = max (0.5 * dot (unitRange, screenTexSize), 1.0 );
91+
92+ float sd = median (textureColor.r, textureColor.g, textureColor.b) - 0.5 ;
93+ float screenPxDistance = screenPxRange * (sd + g_PushConstants.Outline / (pxRange * 2.0 ));
94+
95+ if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_TITLE_BEVEL)
96+ {
97+ float2 normal = normalize (float3 (ddx (sd), ddy (sd), 0.01 )).xy;
98+ float3 rimColor = float3 (1 , 0.8 , 0.29 );
99+ float3 shadowColor = float3 (0.84 , 0.57 , 0 );
100+
101+ float cosTheta = dot (normal, normalize (float2 (1 , 1 )));
102+ float3 gradient = lerp (color.rgb, cosTheta >= 0.0 ? rimColor : shadowColor, abs (cosTheta));
103+ color.rgb = lerp (gradient, color.rgb, pow (saturate (sd + 0.8 ), 32.0 ));
104+ }
105+ else if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_CATEGORY_BEVEL)
106+ {
107+ float2 normal = normalize (float3 (ddx (sd), ddy (sd), 0.25 )).xy;
108+ float cosTheta = dot (normal, normalize (float2 (1 , 1 )));
109+ float gradient = 1.0 + cosTheta * 0.5 ;
110+ color.rgb = saturate (color.rgb * gradient);
111+ }
112+ else if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_TEXT_SKEW)
113+ {
114+ float2 normal = normalize (float3 (ddx (sd), ddy (sd), 0.5 )).xy;
115+ float cosTheta = dot (normal, normalize (float2 (1 , 1 )));
116+ float gradient = saturate (1.0 + cosTheta);
117+ color.rgb = lerp (color.rgb * gradient, color.rgb, pow (saturate (sd + 0.77 ), 32.0 ));
118+ }
119+
120+ color.a *= saturate (screenPxDistance + 0.5 );
121+ color.a *= textureColor.a;
122+
123+ return color;
124+ }
125+
81126float4 main (in Interpolators interpolators) : SV_Target
82127{
83128 float4 color = interpolators.Color;
@@ -86,52 +131,50 @@ float4 main(in Interpolators interpolators) : SV_Target
86131 if (g_PushConstants.Texture2DDescriptorIndex != 0 )
87132 {
88133 Texture2D <float4 > texture = g_Texture2DDescriptorHeap[g_PushConstants.Texture2DDescriptorIndex & 0x7FFFFFFF ];
89- float4 textureColor = texture.Sample (g_SamplerDescriptorHeap[0 ], interpolators.UV);
90134
91135 if ((g_PushConstants.Texture2DDescriptorIndex & 0x80000000 ) != 0 )
92136 {
93- uint width, height;
94- texture.GetDimensions (width, height);
95-
96- float pxRange = 8.0 ;
97- float2 unitRange = pxRange / float2 (width, height);
98- float2 screenTexSize = 1.0 / fwidth (interpolators.UV);
99- float screenPxRange = max (0.5 * dot (unitRange, screenTexSize), 1.0 );
100-
101- float sd = median (textureColor.r, textureColor.g, textureColor.b) - 0.5 ;
102- float screenPxDistance = screenPxRange * (sd + g_PushConstants.Outline / (pxRange * 2.0 ));
103-
104- if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_TITLE_BEVEL)
105- {
106- float2 normal = normalize (float3 (ddx (sd), ddy (sd), 0.01 )).xy;
107- float3 rimColor = float3 (1 , 0.8 , 0.29 );
108- float3 shadowColor = float3 (0.84 , 0.57 , 0 );
109-
110- float cosTheta = dot (normal, normalize (float2 (1 , 1 )));
111- float3 gradient = lerp (color.rgb, cosTheta >= 0.0 ? rimColor : shadowColor, abs (cosTheta));
112- color.rgb = lerp (gradient, color.rgb, pow (saturate (sd + 0.8 ), 32.0 ));
113- }
114- else if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_CATEGORY_BEVEL)
137+ if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_LOW_QUALITY_TEXT)
115138 {
116- float2 normal = normalize (float3 (ddx (sd), ddy (sd), 0.25 )).xy;
117- float cosTheta = dot (normal, normalize (float2 (1 , 1 )));
118- float gradient = 1.0 + cosTheta * 0.5 ;
119- color.rgb = saturate (color.rgb * gradient);
139+ float scale;
140+ float invScale;
141+
142+ if ((g_PushConstants.DisplaySize.x * g_PushConstants.InverseDisplaySize.y) >= (4.0 / 3.0 ))
143+ {
144+ scale = g_PushConstants.InverseDisplaySize.y * 720.0 ;
145+ invScale = g_PushConstants.DisplaySize.y / 720.0 ;
146+ }
147+ else
148+ {
149+ scale = g_PushConstants.InverseDisplaySize.x * 960.0 ;
150+ invScale = g_PushConstants.DisplaySize.x / 960.0 ;
151+ }
152+
153+ float2 lowQualityPosition = (interpolators.Position.xy - 0.5 ) * scale;
154+ float2 fracPart = frac (lowQualityPosition);
155+
156+ float2 uvStep = fwidth (interpolators.UV) * invScale;
157+ float2 lowQualityUV = interpolators.UV - fracPart * uvStep;
158+ float2 screenTexSize = 1.0 / uvStep;
159+
160+ float4 topLeft = SampleSdfFont (color, texture, lowQualityUV + float2 (0 , 0 ), screenTexSize);
161+ float4 topRight = SampleSdfFont (color, texture, lowQualityUV + float2 (uvStep.x, 0 ), screenTexSize);
162+ float4 bottomLeft = SampleSdfFont (color, texture, lowQualityUV + float2 (0 , uvStep.y), screenTexSize);
163+ float4 bottomRight = SampleSdfFont (color, texture, lowQualityUV + uvStep.xy, screenTexSize);
164+
165+ float4 top = lerp (topLeft, topRight, fracPart.x);
166+ float4 bottom = lerp (bottomLeft, bottomRight, fracPart.x);
167+
168+ color = lerp (top, bottom, fracPart.y);
120169 }
121- else if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_TEXT_SKEW)
170+ else
122171 {
123- float2 normal = normalize (float3 (ddx (sd), ddy (sd), 0.5 )).xy;
124- float cosTheta = dot (normal, normalize (float2 (1 , 1 )));
125- float gradient = saturate (1.0 + cosTheta);
126- color.rgb = lerp (color.rgb * gradient, color.rgb, pow (saturate (sd + 0.77 ), 32.0 ));
172+ color = SampleSdfFont (color, texture, interpolators.UV, 1.0 / fwidth (interpolators.UV));
127173 }
128-
129- color.a *= saturate (screenPxDistance + 0.5 );
130- color.a *= textureColor.a;
131174 }
132175 else
133176 {
134- color *= textureColor ;
177+ color *= texture. Sample (g_SamplerDescriptorHeap[ 0 ], interpolators.UV) ;
135178 }
136179 }
137180
0 commit comments