mirror of
https://github.com/hedge-dev/UnleashedRecomp
synced 2026-06-06 11:47:50 -04:00
Implement SDF fonts. (#24)
* Initial SDF font generation work. * Text now correctly displaying with proper spacing. * Fix untextured draws, implement custom rectangles. * Fix regular image display. * Slightly refactor ImGui rendering. * Implement outlines. * Implement bevel. * Create host device after loading the module if the installer wasn't run. * Move ImGui files to its own folder. * Fix outline sizes. * Fix default ImGui font and font scales. * Update font atlas files.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../imgui_common.h"
|
||||
#include "../imgui/imgui_common.h"
|
||||
|
||||
struct PushConstants
|
||||
{
|
||||
@@ -13,6 +13,7 @@ struct PushConstants
|
||||
float2 InverseDisplaySize;
|
||||
float2 Origin;
|
||||
float2 Scale;
|
||||
float Outline;
|
||||
};
|
||||
|
||||
Texture2D<float4> g_Texture2DDescriptorHeap[] : register(t0, space0);
|
||||
|
||||
@@ -73,13 +73,67 @@ float4 PixelAntialiasing(float2 uvTexspace)
|
||||
return SampleLinear(uvTexspace);
|
||||
}
|
||||
|
||||
float median(float r, float g, float b)
|
||||
{
|
||||
return max(min(r, g), min(max(r, g), b));
|
||||
}
|
||||
|
||||
float4 main(in Interpolators interpolators) : SV_Target
|
||||
{
|
||||
float4 color = interpolators.Color;
|
||||
color *= PixelAntialiasing(interpolators.Position.xy - 0.5);
|
||||
|
||||
if (g_PushConstants.Texture2DDescriptorIndex != 0)
|
||||
color *= g_Texture2DDescriptorHeap[g_PushConstants.Texture2DDescriptorIndex].Sample(g_SamplerDescriptorHeap[0], interpolators.UV);
|
||||
{
|
||||
Texture2D<float4> texture = g_Texture2DDescriptorHeap[g_PushConstants.Texture2DDescriptorIndex & 0x7FFFFFFF];
|
||||
float4 textureColor = texture.Sample(g_SamplerDescriptorHeap[0], interpolators.UV);
|
||||
|
||||
if ((g_PushConstants.Texture2DDescriptorIndex & 0x80000000) != 0)
|
||||
{
|
||||
uint width, height;
|
||||
texture.GetDimensions(width, height);
|
||||
|
||||
float pxRange = 8.0;
|
||||
float2 unitRange = pxRange / float2(width, height);
|
||||
float2 screenTexSize = 1.0 / fwidth(interpolators.UV);
|
||||
float screenPxRange = max(0.5 * dot(unitRange, screenTexSize), 1.0);
|
||||
|
||||
float sd = median(textureColor.r, textureColor.g, textureColor.b) - 0.5;
|
||||
float screenPxDistance = screenPxRange * (sd + g_PushConstants.Outline / (pxRange * 2.0));
|
||||
|
||||
if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_TITLE_BEVEL)
|
||||
{
|
||||
float2 normal = normalize(float3(ddx(sd), ddy(sd), 0.01)).xy;
|
||||
float3 rimColor = float3(1, 0.8, 0.29);
|
||||
float3 shadowColor = float3(0.84, 0.57, 0);
|
||||
|
||||
float cosTheta = dot(normal, normalize(float2(1, 1)));
|
||||
float3 gradient = lerp(color.rgb, cosTheta >= 0.0 ? rimColor : shadowColor, abs(cosTheta));
|
||||
color.rgb = lerp(gradient, color.rgb, pow(saturate(sd + 0.8), 32.0));
|
||||
}
|
||||
else if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_CATEGORY_BEVEL)
|
||||
{
|
||||
float2 normal = normalize(float3(ddx(sd), ddy(sd), 0.25)).xy;
|
||||
float cosTheta = dot(normal, normalize(float2(1, 1)));
|
||||
float gradient = 1.0 + cosTheta * 0.5;
|
||||
color.rgb = saturate(color.rgb * gradient);
|
||||
}
|
||||
else if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_TEXT_SKEW)
|
||||
{
|
||||
float2 normal = normalize(float3(ddx(sd), ddy(sd), 0.5)).xy;
|
||||
float cosTheta = dot(normal, normalize(float2(1, 1)));
|
||||
float gradient = saturate(1.0 + cosTheta);
|
||||
color.rgb = lerp(color.rgb * gradient, color.rgb, pow(saturate(sd + 0.77), 32.0));
|
||||
}
|
||||
|
||||
color.a *= saturate(screenPxDistance + 0.5);
|
||||
color.a *= textureColor.a;
|
||||
}
|
||||
else
|
||||
{
|
||||
color *= textureColor;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_MARQUEE_FADE)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user