Skip to content

Commit

Permalink
Update all shaders to interpret colours as premultiplied
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzibyte committed Dec 14, 2024
1 parent 5c9e39d commit f8f3b31
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 17 deletions.
2 changes: 1 addition & 1 deletion osu.Framework/Resources/Shaders/sh_CircularBlob.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion osu.Framework/Resources/Shaders/sh_CircularProgress.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion osu.Framework/Resources/Shaders/sh_FastCircle.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions osu.Framework/Resources/Shaders/sh_Masking.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Resources/Shaders/sh_Particle.vs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
10 changes: 1 addition & 9 deletions osu.Framework/Resources/Shaders/sh_Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f8f3b31

Please sign in to comment.