Implement shader modifier for options title rectangle.

This commit is contained in:
Skyth 2025-01-29 14:19:09 +03:00
parent 9fa20ec678
commit bd0ec78cf5
3 changed files with 28 additions and 2 deletions

View file

@ -9,6 +9,7 @@
#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
#ifdef __cplusplus

View file

@ -146,7 +146,27 @@ float4 main(in Interpolators interpolators) : SV_Target
else if (any(g_PushConstants.BoundsMin != g_PushConstants.BoundsMax))
{
float2 factor = saturate((interpolators.Position.xy - g_PushConstants.BoundsMin) / (g_PushConstants.BoundsMax - g_PushConstants.BoundsMin));
color *= lerp(DecodeColor(g_PushConstants.GradientTop), DecodeColor(g_PushConstants.GradientBottom), smoothstep(0.0, 1.0, factor.y));
if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_RECTANGLE_BEVEL)
{
float bevelSize = 0.9;
float shadow = saturate((factor.x - bevelSize) / (1.0 - bevelSize));
shadow = max(shadow, saturate((factor.y - bevelSize) / (1.0 - bevelSize)));
float rim = saturate((1.0 - factor.x - bevelSize) / (1.0 - bevelSize));
rim = max(rim, saturate((1.0 - factor.y - bevelSize) / (1.0 - bevelSize)));
float3 rimColor = float3(1, 0.8, 0.29);
float3 shadowColor = float3(0.84, 0.57, 0);
color.rgb = lerp(color.rgb, rimColor, smoothstep(0.0, 1.0, rim));
color.rgb = lerp(color.rgb, shadowColor, smoothstep(0.0, 1.0, shadow));
}
else
{
color *= lerp(DecodeColor(g_PushConstants.GradientTop), DecodeColor(g_PushConstants.GradientBottom), smoothstep(0.0, 1.0, factor.y));
}
}
if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_GRAYSCALE)

View file

@ -200,8 +200,13 @@ static void DrawTitle()
drawList->AddRectFilled(rectOutlineMin, rectOutlineMax, IM_COL32(0, 0, 0, 255 * rectAlphaMotion), Scale(5));
// TODO: apply bevel to this square (may require a new shader modifier, existing ones don't work).
SetShaderModifier(IMGUI_SHADER_MODIFIER_RECTANGLE_BEVEL);
SetGradient(rectMin, rectMax, IM_COL32_WHITE, IM_COL32_WHITE);
drawList->AddRectFilled(rectMin, rectMax, IM_COL32(255, 188, 0, 255 * rectAlphaMotion));
ResetGradient();
SetShaderModifier(IMGUI_SHADER_MODIFIER_NONE);
}
// The flash gets rendered after the rectangle in the original game.