From f8f3b3105db1d7688dcc6eee71456b960bdf83e6 Mon Sep 17 00:00:00 2001 From: Salman Alshamrani Date: Fri, 13 Dec 2024 07:38:36 -0500 Subject: [PATCH] Update all shaders to interpret colours as premultiplied --- osu.Framework/Resources/Shaders/sh_CircularBlob.fs | 2 +- osu.Framework/Resources/Shaders/sh_CircularProgress.fs | 2 +- osu.Framework/Resources/Shaders/sh_FastCircle.fs | 2 +- osu.Framework/Resources/Shaders/sh_Masking.h | 8 ++++---- osu.Framework/Resources/Shaders/sh_Particle.vs | 2 +- osu.Framework/Resources/Shaders/sh_Utils.h | 10 +--------- 6 files changed, 9 insertions(+), 17 deletions(-) diff --git a/osu.Framework/Resources/Shaders/sh_CircularBlob.fs b/osu.Framework/Resources/Shaders/sh_CircularBlob.fs index fa5f027085..a4899f4c96 100644 --- a/osu.Framework/Resources/Shaders/sh_CircularBlob.fs +++ b/osu.Framework/Resources/Shaders/sh_CircularBlob.fs @@ -33,7 +33,7 @@ void main(void) highp vec2 wrappedCoord = wrap(v_TexCoord, v_TexRect); lowp vec4 textureColour = getRoundedColor(wrappedSampler(wrappedCoord, v_TexRect, m_Texture, m_Sampler, -0.9), wrappedCoord); - o_Colour = vec4(textureColour.rgb, textureColour.a * blobAlphaAt(pixelPos, innerRadius, texelSize, frequency, amplitude, noisePosition)); + o_Colour = textureColour.rgba * blobAlphaAt(pixelPos, innerRadius, texelSize, frequency, amplitude, noisePosition); } #endif \ No newline at end of file diff --git a/osu.Framework/Resources/Shaders/sh_CircularProgress.fs b/osu.Framework/Resources/Shaders/sh_CircularProgress.fs index 559a064831..bf5f4b8a10 100644 --- a/osu.Framework/Resources/Shaders/sh_CircularProgress.fs +++ b/osu.Framework/Resources/Shaders/sh_CircularProgress.fs @@ -32,7 +32,7 @@ void main(void) highp vec2 wrappedCoord = wrap(v_TexCoord, v_TexRect); lowp vec4 textureColour = getRoundedColor(wrappedSampler(wrappedCoord, v_TexRect, m_Texture, m_Sampler, -0.9), wrappedCoord); - o_Colour = vec4(textureColour.rgb, textureColour.a * progressAlphaAt(pixelPos, progress, innerRadius, roundedCaps, texelSize)); + o_Colour = textureColour.rgba * progressAlphaAt(pixelPos, progress, innerRadius, roundedCaps, texelSize); } #endif \ No newline at end of file diff --git a/osu.Framework/Resources/Shaders/sh_FastCircle.fs b/osu.Framework/Resources/Shaders/sh_FastCircle.fs index 307f00a74c..be60600f41 100644 --- a/osu.Framework/Resources/Shaders/sh_FastCircle.fs +++ b/osu.Framework/Resources/Shaders/sh_FastCircle.fs @@ -20,7 +20,7 @@ void main(void) highp float alpha = v_BlendRange.x == 0.0 ? float(dst < radius) : (clamp(radius - dst, 0.0, v_BlendRange.x) / v_BlendRange.x); - o_Colour = getRoundedColor(vec4(vec3(1.0), alpha), vec2(0.0)); + o_Colour = getRoundedColor(vec4(alpha), vec2(0.0)); } #endif diff --git a/osu.Framework/Resources/Shaders/sh_Masking.h b/osu.Framework/Resources/Shaders/sh_Masking.h index 3fdc6c8846..e9e0223052 100644 --- a/osu.Framework/Resources/Shaders/sh_Masking.h +++ b/osu.Framework/Resources/Shaders/sh_Masking.h @@ -116,15 +116,15 @@ lowp vec4 getRoundedColor(lowp vec4 texel, mediump vec2 texCoord) lowp vec4 contentColour = v_Colour * texel; if (colourWeight == 1.0) - return vec4(contentColour.rgb, contentColour.a * alphaFactor); + return contentColour.rgba * alphaFactor; lowp vec4 borderColour = getBorderColour(); if (colourWeight <= 0.0) - return vec4(borderColour.rgb, borderColour.a * alphaFactor); + return borderColour.rgba * alphaFactor; - contentColour.a *= alphaFactor; - borderColour.a *= 1.0 - colourWeight; + contentColour.rgba *= alphaFactor; + borderColour.rgba *= 1.0 - colourWeight; return blend(borderColour, contentColour); } diff --git a/osu.Framework/Resources/Shaders/sh_Particle.vs b/osu.Framework/Resources/Shaders/sh_Particle.vs index 8da3d9ed64..9a8781f19e 100644 --- a/osu.Framework/Resources/Shaders/sh_Particle.vs +++ b/osu.Framework/Resources/Shaders/sh_Particle.vs @@ -23,7 +23,7 @@ void main(void) vec2(0.0, g_Gravity * g_FadeClock * g_FadeClock / 1000000.0); gl_Position = g_ProjMatrix * vec4(targetPosition, 1.0, 1.0); - v_Colour = vec4(1.0, 1.0, 1.0, 1.0 - clamp(g_FadeClock / m_Time, 0.0, 1.0)); + v_Colour = vec4(1.0 - clamp(g_FadeClock / m_Time, 0.0, 1.0)); v_TexCoord = m_TexCoord; } diff --git a/osu.Framework/Resources/Shaders/sh_Utils.h b/osu.Framework/Resources/Shaders/sh_Utils.h index 6e2e010c25..ffeb972298 100644 --- a/osu.Framework/Resources/Shaders/sh_Utils.h +++ b/osu.Framework/Resources/Shaders/sh_Utils.h @@ -8,15 +8,7 @@ // see http://apoorvaj.io/alpha-compositing-opengl-blending-and-premultiplied-alpha.html lowp vec4 blend(lowp vec4 src, lowp vec4 dst) { - lowp float finalAlpha = src.a + dst.a * (1.0 - src.a); - - if (finalAlpha == 0.0) - return vec4(0); - - return vec4( - (src.rgb * src.a + dst.rgb * dst.a * (1.0 - src.a)) / finalAlpha, - finalAlpha - ); + return src.rgba + dst.rgba * (1.0 - src.a); } // http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl