From 06242223a31ef5f65d5ded8190ef696727976fd2 Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Wed, 11 Dec 2024 21:50:25 +0300 Subject: [PATCH] Implement bevel. --- UnleashedRecomp/gpu/imgui_common.h | 2 ++ UnleashedRecomp/gpu/shader/imgui_ps.hlsl | 25 ++++++++++++++++++++++++ UnleashedRecomp/ui/imgui_utils.h | 8 +++++++- UnleashedRecomp/ui/installer_wizard.cpp | 2 +- UnleashedRecomp/ui/options_menu.cpp | 13 ++++++++++-- 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/UnleashedRecomp/gpu/imgui_common.h b/UnleashedRecomp/gpu/imgui_common.h index a68bb28e..91d5b4ee 100644 --- a/UnleashedRecomp/gpu/imgui_common.h +++ b/UnleashedRecomp/gpu/imgui_common.h @@ -7,6 +7,8 @@ #define IMGUI_SHADER_MODIFIER_TEXT_SKEW 4 #define IMGUI_SHADER_MODIFIER_MARQUEE_FADE 5 #define IMGUI_SHADER_MODIFIER_GRAYSCALE 6 +#define IMGUI_SHADER_MODIFIER_TITLE_BEVEL 7 +#define IMGUI_SHADER_MODIFIER_CATEGORY_BEVEL 8 #ifdef __cplusplus diff --git a/UnleashedRecomp/gpu/shader/imgui_ps.hlsl b/UnleashedRecomp/gpu/shader/imgui_ps.hlsl index 2116a498..18928e0f 100644 --- a/UnleashedRecomp/gpu/shader/imgui_ps.hlsl +++ b/UnleashedRecomp/gpu/shader/imgui_ps.hlsl @@ -101,6 +101,31 @@ float4 main(in Interpolators interpolators) : SV_Target 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; } diff --git a/UnleashedRecomp/ui/imgui_utils.h b/UnleashedRecomp/ui/imgui_utils.h index 99175a96..dba911ea 100644 --- a/UnleashedRecomp/ui/imgui_utils.h +++ b/UnleashedRecomp/ui/imgui_utils.h @@ -190,7 +190,7 @@ static void DrawTextWithMarquee(const ImFont* font, float fontSize, const ImVec2 drawList->PopClipRect(); } -static void DrawTextWithOutline(const ImFont* font, float fontSize, const ImVec2& pos, ImU32 color, const char* text, float outlineSize, ImU32 outlineColor) +static void DrawTextWithOutline(const ImFont* font, float fontSize, const ImVec2& pos, ImU32 color, const char* text, float outlineSize, ImU32 outlineColor, uint32_t shaderModifier = IMGUI_SHADER_MODIFIER_NONE) { auto drawList = ImGui::GetForegroundDrawList(); @@ -198,7 +198,13 @@ static void DrawTextWithOutline(const ImFont* font, float fontSize, const ImVec2 drawList->AddText(font, fontSize, pos, outlineColor, text); ResetOutline(); + if (shaderModifier != IMGUI_SHADER_MODIFIER_NONE) + SetShaderModifier(shaderModifier); + drawList->AddText(font, fontSize, pos, color, text); + + if (shaderModifier != IMGUI_SHADER_MODIFIER_NONE) + SetShaderModifier(IMGUI_SHADER_MODIFIER_NONE); } static void DrawTextWithShadow(const ImFont* font, float fontSize, const ImVec2& pos, ImU32 colour, const char* text, float offset = 2.0f, float radius = 0.4f, ImU32 shadowColour = IM_COL32(0, 0, 0, 255)) diff --git a/UnleashedRecomp/ui/installer_wizard.cpp b/UnleashedRecomp/ui/installer_wizard.cpp index 4576d809..dfb316af 100644 --- a/UnleashedRecomp/ui/installer_wizard.cpp +++ b/UnleashedRecomp/ui/installer_wizard.cpp @@ -559,7 +559,7 @@ static void DrawScanlineBars() // Installer text const std::string &headerText = Localise(g_currentPage == WizardPage::Installing ? "Installer_Header_Installing" : "Installer_Header_Installer"); int textAlpha = std::lround(255.0f * ComputeMotionInstaller(g_appearTime, g_disappearTime, TITLE_ANIMATION_TIME, TITLE_ANIMATION_DURATION)); - DrawTextWithOutline(g_dfsogeistdFont, Scale(42.0f), { Scale(285.0f), Scale(57.0f) }, IM_COL32(255, 195, 0, textAlpha), headerText.c_str(), 4, IM_COL32(0, 0, 0, textAlpha)); + DrawTextWithOutline(g_dfsogeistdFont, Scale(42.0f), { Scale(285.0f), Scale(57.0f) }, IM_COL32(255, 195, 0, textAlpha), headerText.c_str(), 4, IM_COL32(0, 0, 0, textAlpha), IMGUI_SHADER_MODIFIER_TITLE_BEVEL); // Top bar line drawList->AddLine diff --git a/UnleashedRecomp/ui/options_menu.cpp b/UnleashedRecomp/ui/options_menu.cpp index 0f2492ea..1d78fe72 100644 --- a/UnleashedRecomp/ui/options_menu.cpp +++ b/UnleashedRecomp/ui/options_menu.cpp @@ -138,7 +138,15 @@ static void DrawScanlineBars() // Options text // TODO: localise this. - DrawTextWithOutline(g_dfsogeistdFont, Scale(48.0f), { Scale(122.0f), Scale(56.0f) }, IM_COL32(255, 195, 0, 255), "OPTIONS", 4, IM_COL32_BLACK); + DrawTextWithOutline( + g_dfsogeistdFont, + Scale(48.0f), + { Scale(122.0f), Scale(56.0f) }, + IM_COL32(255, 190, 33, 255), + "OPTIONS", + 4, + IM_COL32_BLACK, + IMGUI_SHADER_MODIFIER_TITLE_BEVEL); // Top bar line drawList->AddLine @@ -397,7 +405,8 @@ static bool DrawCategories() IM_COL32_WHITE, GetCategory(i).c_str(), 3, - IM_COL32_BLACK + IM_COL32_BLACK, + IMGUI_SHADER_MODIFIER_CATEGORY_BEVEL ); ResetGradient();