From 21c1d3683697621902bb4ae62ac2341c5d4eb992 Mon Sep 17 00:00:00 2001 From: "Skyth (Asilkan)" <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Thu, 30 Jan 2025 23:25:19 +0300 Subject: [PATCH] Allow specifying all corners for ImGui gradients. (#247) --- UnleashedRecomp/gpu/imgui/imgui_common.h | 6 ++++-- UnleashedRecomp/gpu/shader/imgui_common.hlsli | 6 ++++-- UnleashedRecomp/gpu/shader/imgui_ps.hlsl | 4 +++- UnleashedRecomp/gpu/video.cpp | 6 ++++-- UnleashedRecomp/ui/imgui_utils.cpp | 11 +++++++++-- UnleashedRecomp/ui/imgui_utils.h | 1 + 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/UnleashedRecomp/gpu/imgui/imgui_common.h b/UnleashedRecomp/gpu/imgui/imgui_common.h index bc3c795..a0216b2 100644 --- a/UnleashedRecomp/gpu/imgui/imgui_common.h +++ b/UnleashedRecomp/gpu/imgui/imgui_common.h @@ -32,8 +32,10 @@ union ImGuiCallbackData { float boundsMin[2]; float boundsMax[2]; - uint32_t gradientTop; - uint32_t gradientBottom; + uint32_t gradientTopLeft; + uint32_t gradientTopRight; + uint32_t gradientBottomRight; + uint32_t gradientBottomLeft; } setGradient; struct diff --git a/UnleashedRecomp/gpu/shader/imgui_common.hlsli b/UnleashedRecomp/gpu/shader/imgui_common.hlsli index 9f96d55..fe7a02e 100644 --- a/UnleashedRecomp/gpu/shader/imgui_common.hlsli +++ b/UnleashedRecomp/gpu/shader/imgui_common.hlsli @@ -6,8 +6,10 @@ struct PushConstants { float2 BoundsMin; float2 BoundsMax; - uint GradientTop; - uint GradientBottom; + uint GradientTopLeft; + uint GradientTopRight; + uint GradientBottomRight; + uint GradientBottomLeft; uint ShaderModifier; uint Texture2DDescriptorIndex; float2 InverseDisplaySize; diff --git a/UnleashedRecomp/gpu/shader/imgui_ps.hlsl b/UnleashedRecomp/gpu/shader/imgui_ps.hlsl index 5ebc551..7e7e03b 100644 --- a/UnleashedRecomp/gpu/shader/imgui_ps.hlsl +++ b/UnleashedRecomp/gpu/shader/imgui_ps.hlsl @@ -165,7 +165,9 @@ float4 main(in Interpolators interpolators) : SV_Target } else { - color *= lerp(DecodeColor(g_PushConstants.GradientTop), DecodeColor(g_PushConstants.GradientBottom), smoothstep(0.0, 1.0, factor.y)); + float4 top = lerp(DecodeColor(g_PushConstants.GradientTopLeft), DecodeColor(g_PushConstants.GradientTopRight), smoothstep(0.0, 1.0, factor.x)); + float4 bottom = lerp(DecodeColor(g_PushConstants.GradientBottomLeft), DecodeColor(g_PushConstants.GradientBottomRight), smoothstep(0.0, 1.0, factor.x)); + color *= lerp(top, bottom, smoothstep(0.0, 1.0, factor.y)); } } diff --git a/UnleashedRecomp/gpu/video.cpp b/UnleashedRecomp/gpu/video.cpp index 682b991..41f8bf1 100644 --- a/UnleashedRecomp/gpu/video.cpp +++ b/UnleashedRecomp/gpu/video.cpp @@ -1196,8 +1196,10 @@ struct ImGuiPushConstants { ImVec2 boundsMin{}; ImVec2 boundsMax{}; - ImU32 gradientTop{}; - ImU32 gradientBottom{}; + ImU32 gradientTopLeft{}; + ImU32 gradientTopRight{}; + ImU32 gradientBottomRight{}; + ImU32 gradientBottomLeft{}; uint32_t shaderModifier{}; uint32_t texture2DDescriptorIndex{}; ImVec2 inverseDisplaySize{}; diff --git a/UnleashedRecomp/ui/imgui_utils.cpp b/UnleashedRecomp/ui/imgui_utils.cpp index 2bed3ed..9f266f6 100644 --- a/UnleashedRecomp/ui/imgui_utils.cpp +++ b/UnleashedRecomp/ui/imgui_utils.cpp @@ -23,14 +23,21 @@ void InitImGuiUtils() } void SetGradient(const ImVec2& min, const ImVec2& max, ImU32 top, ImU32 bottom) +{ + SetGradient(min, max, top, top, bottom, bottom); +} + +void SetGradient(const ImVec2& min, const ImVec2& max, ImU32 topLeft, ImU32 topRight, ImU32 bottomRight, ImU32 bottomLeft) { auto callbackData = AddImGuiCallback(ImGuiCallback::SetGradient); callbackData->setGradient.boundsMin[0] = min.x; callbackData->setGradient.boundsMin[1] = min.y; callbackData->setGradient.boundsMax[0] = max.x; callbackData->setGradient.boundsMax[1] = max.y; - callbackData->setGradient.gradientTop = top; - callbackData->setGradient.gradientBottom = bottom; + callbackData->setGradient.gradientTopLeft = topLeft; + callbackData->setGradient.gradientTopRight = topRight; + callbackData->setGradient.gradientBottomRight = bottomRight; + callbackData->setGradient.gradientBottomLeft = bottomLeft; } void ResetGradient() diff --git a/UnleashedRecomp/ui/imgui_utils.h b/UnleashedRecomp/ui/imgui_utils.h index f664700..c957998 100644 --- a/UnleashedRecomp/ui/imgui_utils.h +++ b/UnleashedRecomp/ui/imgui_utils.h @@ -35,6 +35,7 @@ struct Paragraph { void InitImGuiUtils(); void SetGradient(const ImVec2& min, const ImVec2& max, ImU32 top, ImU32 bottom); +void SetGradient(const ImVec2& min, const ImVec2& max, ImU32 topLeft, ImU32 topRight, ImU32 bottomRight, ImU32 bottomLeft); void ResetGradient(); void SetShaderModifier(uint32_t shaderModifier); void SetOrigin(ImVec2 origin);