From 342d696f99b1f46af7255b598847f6d8b91aa24e Mon Sep 17 00:00:00 2001 From: "Skyth (Asilkan)" <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Sun, 2 Feb 2025 20:09:19 +0300 Subject: [PATCH] Implement vertical marquee fade. (#261) --- UnleashedRecomp/gpu/imgui/imgui_common.h | 21 +++++++++++---------- UnleashedRecomp/gpu/shader/imgui_ps.hlsl | 10 +++++++++- UnleashedRecomp/gpu/shader/imgui_vs.hlsl | 3 ++- UnleashedRecomp/ui/achievement_menu.cpp | 2 +- UnleashedRecomp/ui/imgui_utils.cpp | 16 ++++++++++++++-- UnleashedRecomp/ui/imgui_utils.h | 3 ++- UnleashedRecomp/ui/installer_wizard.cpp | 2 +- 7 files changed, 40 insertions(+), 17 deletions(-) diff --git a/UnleashedRecomp/gpu/imgui/imgui_common.h b/UnleashedRecomp/gpu/imgui/imgui_common.h index a0216b2..db2427a 100644 --- a/UnleashedRecomp/gpu/imgui/imgui_common.h +++ b/UnleashedRecomp/gpu/imgui/imgui_common.h @@ -1,15 +1,16 @@ #pragma once -#define IMGUI_SHADER_MODIFIER_NONE 0 -#define IMGUI_SHADER_MODIFIER_SCANLINE 1 -#define IMGUI_SHADER_MODIFIER_CHECKERBOARD 2 -#define IMGUI_SHADER_MODIFIER_SCANLINE_BUTTON 3 -#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 -#define IMGUI_SHADER_MODIFIER_RECTANGLE_BEVEL 9 +#define IMGUI_SHADER_MODIFIER_NONE 0 +#define IMGUI_SHADER_MODIFIER_SCANLINE 1 +#define IMGUI_SHADER_MODIFIER_CHECKERBOARD 2 +#define IMGUI_SHADER_MODIFIER_SCANLINE_BUTTON 3 +#define IMGUI_SHADER_MODIFIER_TEXT_SKEW 4 +#define IMGUI_SHADER_MODIFIER_HORIZONTAL_MARQUEE_FADE 5 +#define IMGUI_SHADER_MODIFIER_VERTICAL_MARQUEE_FADE 6 +#define IMGUI_SHADER_MODIFIER_GRAYSCALE 7 +#define IMGUI_SHADER_MODIFIER_TITLE_BEVEL 8 +#define IMGUI_SHADER_MODIFIER_CATEGORY_BEVEL 9 +#define IMGUI_SHADER_MODIFIER_RECTANGLE_BEVEL 10 #ifdef __cplusplus diff --git a/UnleashedRecomp/gpu/shader/imgui_ps.hlsl b/UnleashedRecomp/gpu/shader/imgui_ps.hlsl index 7e7e03b..11069c4 100644 --- a/UnleashedRecomp/gpu/shader/imgui_ps.hlsl +++ b/UnleashedRecomp/gpu/shader/imgui_ps.hlsl @@ -135,7 +135,7 @@ float4 main(in Interpolators interpolators) : SV_Target } } - if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_MARQUEE_FADE) + if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_HORIZONTAL_MARQUEE_FADE) { float minAlpha = saturate((interpolators.Position.x - g_PushConstants.BoundsMin.x) / g_PushConstants.Scale.x); float maxAlpha = saturate((g_PushConstants.BoundsMax.x - interpolators.Position.x) / g_PushConstants.Scale.x); @@ -143,6 +143,14 @@ float4 main(in Interpolators interpolators) : SV_Target color.a *= minAlpha; color.a *= maxAlpha; } + else if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_VERTICAL_MARQUEE_FADE) + { + float minAlpha = saturate((interpolators.Position.y - g_PushConstants.BoundsMin.y) / g_PushConstants.Scale.y); + float maxAlpha = saturate((g_PushConstants.BoundsMax.y - interpolators.Position.y) / g_PushConstants.Scale.y); + + color.a *= minAlpha; + color.a *= maxAlpha; + } else if (any(g_PushConstants.BoundsMin != g_PushConstants.BoundsMax)) { float2 factor = saturate((interpolators.Position.xy - g_PushConstants.BoundsMin) / (g_PushConstants.BoundsMax - g_PushConstants.BoundsMin)); diff --git a/UnleashedRecomp/gpu/shader/imgui_vs.hlsl b/UnleashedRecomp/gpu/shader/imgui_vs.hlsl index 994be88..50a53f4 100644 --- a/UnleashedRecomp/gpu/shader/imgui_vs.hlsl +++ b/UnleashedRecomp/gpu/shader/imgui_vs.hlsl @@ -7,7 +7,8 @@ void main(in float2 position : POSITION, in float2 uv : TEXCOORD, in float4 colo if (position.y < g_PushConstants.Origin.y) position.x += g_PushConstants.Scale.x; } - else if (g_PushConstants.ShaderModifier != IMGUI_SHADER_MODIFIER_MARQUEE_FADE) + else if (g_PushConstants.ShaderModifier != IMGUI_SHADER_MODIFIER_HORIZONTAL_MARQUEE_FADE && + g_PushConstants.ShaderModifier != IMGUI_SHADER_MODIFIER_VERTICAL_MARQUEE_FADE) { position.xy = g_PushConstants.Origin + (position.xy - g_PushConstants.Origin) * g_PushConstants.Scale; } diff --git a/UnleashedRecomp/ui/achievement_menu.cpp b/UnleashedRecomp/ui/achievement_menu.cpp index 122be3c..a42dc22 100644 --- a/UnleashedRecomp/ui/achievement_menu.cpp +++ b/UnleashedRecomp/ui/achievement_menu.cpp @@ -197,7 +197,7 @@ static void DrawAchievement(int rowIndex, float yOffset, Achievement& achievemen ImVec2 marqueeMin = { textMarqueeX, min.y }; ImVec2 marqueeMax = { max.x - Scale(10) /* timestamp margin X */, max.y }; - SetMarqueeFade(marqueeMin, marqueeMax, Scale(32)); + SetHorizontalMarqueeFade(marqueeMin, marqueeMax, Scale(32)); if (isSelected && textX + textSize.x >= max.x - Scale(10)) { diff --git a/UnleashedRecomp/ui/imgui_utils.cpp b/UnleashedRecomp/ui/imgui_utils.cpp index 9f266f6..5e9ac0e 100644 --- a/UnleashedRecomp/ui/imgui_utils.cpp +++ b/UnleashedRecomp/ui/imgui_utils.cpp @@ -80,7 +80,7 @@ void ResetTextSkew() SetScale({ 1.0f, 1.0f }); } -void SetMarqueeFade(ImVec2 min, ImVec2 max, float fadeScale) +void SetHorizontalMarqueeFade(ImVec2 min, ImVec2 max, float fadeScale) { auto callbackData = AddImGuiCallback(ImGuiCallback::SetMarqueeFade); callbackData->setMarqueeFade.boundsMin[0] = min.x; @@ -88,10 +88,22 @@ void SetMarqueeFade(ImVec2 min, ImVec2 max, float fadeScale) callbackData->setMarqueeFade.boundsMax[0] = max.x; callbackData->setMarqueeFade.boundsMax[1] = max.y; - SetShaderModifier(IMGUI_SHADER_MODIFIER_MARQUEE_FADE); + SetShaderModifier(IMGUI_SHADER_MODIFIER_HORIZONTAL_MARQUEE_FADE); SetScale({ fadeScale, 1.0f }); } +void SetVerticalMarqueeFade(ImVec2 min, ImVec2 max, float fadeScale) +{ + auto callbackData = AddImGuiCallback(ImGuiCallback::SetMarqueeFade); + callbackData->setMarqueeFade.boundsMin[0] = min.x; + callbackData->setMarqueeFade.boundsMin[1] = min.y; + callbackData->setMarqueeFade.boundsMax[0] = max.x; + callbackData->setMarqueeFade.boundsMax[1] = max.y; + + SetShaderModifier(IMGUI_SHADER_MODIFIER_VERTICAL_MARQUEE_FADE); + SetScale({ 1.0f, fadeScale }); +} + void ResetMarqueeFade() { ResetGradient(); diff --git a/UnleashedRecomp/ui/imgui_utils.h b/UnleashedRecomp/ui/imgui_utils.h index c957998..8d669f2 100644 --- a/UnleashedRecomp/ui/imgui_utils.h +++ b/UnleashedRecomp/ui/imgui_utils.h @@ -42,7 +42,8 @@ void SetOrigin(ImVec2 origin); void SetScale(ImVec2 scale); void SetTextSkew(float yCenter, float skewScale); void ResetTextSkew(); -void SetMarqueeFade(ImVec2 min, ImVec2 max, float fadeScale); +void SetHorizontalMarqueeFade(ImVec2 min, ImVec2 max, float fadeScale); +void SetVerticalMarqueeFade(ImVec2 min, ImVec2 max, float fadeScale); void ResetMarqueeFade(); void SetOutline(float outline); void ResetOutline(); diff --git a/UnleashedRecomp/ui/installer_wizard.cpp b/UnleashedRecomp/ui/installer_wizard.cpp index 9b736eb..870d9d5 100644 --- a/UnleashedRecomp/ui/installer_wizard.cpp +++ b/UnleashedRecomp/ui/installer_wizard.cpp @@ -797,7 +797,7 @@ static void DrawDescriptionContainer() ImVec2 textMin = { g_aspectRatioOffsetX + Scale(CONTAINER_X), textPos.y }; ImVec2 textMax = { g_aspectRatioOffsetX + Scale(CONTAINER_X) + Scale(CONTAINER_WIDTH), g_aspectRatioOffsetY + Scale(CONTAINER_Y) + Scale(CONTAINER_HEIGHT) }; - SetMarqueeFade(textMin, textMax, Scale(32)); + SetHorizontalMarqueeFade(textMin, textMax, Scale(32)); DrawTextWithMarquee(g_seuratFont, fontSize, textPos, textMin, textMax, colWhite, g_creditsStr.c_str(), g_installerEndTime, 0.9, Scale(200)); ResetMarqueeFade(); }