Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update all shaders to treat colours as premultiplied #348

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion osu.Game.Resources/Shaders/sh_ArgonBarPath.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ lowp vec4 glowColAt(highp float absoluteTexturePos, highp float absoluteGlowPort
mixValue *= mixValue;
mixValue *= mixValue;
mixValue *= mixValue;
return vec4(glowColour.rgb, glowColour.a * mixValue);
return glowColour.rgba * mixValue;
}

lowp vec4 getColour(highp float absoluteTexturePos)
Expand Down
10 changes: 8 additions & 2 deletions osu.Game.Resources/Shaders/sh_ArgonBarPathBackground.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ layout(location = 0) out vec4 o_Colour;
lowp vec4 bgColAt(highp float absoluteTexturePos, mediump float pathRadius)
{
highp float relativeTexturePos = clamp(absoluteTexturePos / pathRadius, 0.0, 1.5);
return mix(vec4(vec3(0.0), 0.2), vec4(vec3(1.0), 0.8), relativeTexturePos / 1.5);
vec4 result = mix(vec4(0.2), vec4(vec3(1.0), 0.8), relativeTexturePos / 1.5);
result = vec4(result.rgb * result.a, result.a);
return result;
}

lowp vec4 getColour(highp float absoluteTexturePos, mediump float pathRadius)
{
if (absoluteTexturePos > pathRadius - 1.0)
return mix(vec4(1.0), vec4(vec3(1.0), 0.0), absoluteTexturePos - (pathRadius - 1.0));
{
vec4 result = mix(vec4(1.0), vec4(vec3(1.0), 0.0), absoluteTexturePos - (pathRadius - 1.0));
result = vec4(result.rgb * result.a, result.a);
return result;
}

if (absoluteTexturePos > pathRadius - 2.0)
return mix(bgColAt(absoluteTexturePos, pathRadius), vec4(1.0), absoluteTexturePos - (pathRadius - 2.0));
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Resources/Shaders/sh_CircularFlashlight.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ lowp vec4 getColourAt(highp vec2 diff, highp vec2 size, lowp vec4 originalColour
highp float dist = length(diff);
highp float flashlightRadius = length(size);

return originalColour * vec4(1.0, 1.0, 1.0, smoothstep(flashlightRadius, flashlightRadius * flashlightSmoothness, dist));
return originalColour * vec4(smoothstep(flashlightRadius, flashlightRadius * flashlightSmoothness, dist));
}
2 changes: 1 addition & 1 deletion osu.Game.Resources/Shaders/sh_CursorTrail.vs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void main(void)
vec3 maskingPos = g_ToMaskingSpace * vec3(m_Position, 1.0);
v_MaskingPosition = maskingPos.xy / maskingPos.z;

v_Colour = vec4(m_Colour.rgb, m_Colour.a * pow(clamp(m_Time - g_FadeClock, 0.0, 1.0), g_FadeExponent));
v_Colour = m_Colour.rgba * pow(clamp(m_Time - g_FadeClock, 0.0, 1.0), g_FadeExponent);

v_TexCoord = m_TexCoord;
v_TexRect = m_TexRect;
Expand Down
4 changes: 3 additions & 1 deletion osu.Game.Resources/Shaders/sh_Flashlight.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ void main(void)
// todo: workaround for a SPIR-V bug (https://github.com/ppy/osu-framework/issues/5719)
float one = g_WrapModeS >= 0 ? 1 : 0;

o_Colour = mix(getColourAt(flashlightPos - v_Position, flashlightSize, v_Colour), vec4(0.0, 0.0, 0.0, v_Colour.a), flashlightDim) * one;
vec4 result = mix(getColourAt(flashlightPos - v_Position, flashlightSize, v_Colour), vec4(vec3(0.0), v_Colour.a), flashlightDim) * one;
result = vec4(result.rgb * result.a, result.a);
o_Colour = result;
}
10 changes: 8 additions & 2 deletions osu.Game.Resources/Shaders/sh_LogoAnimation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ void main(void)
// todo: workaround for a SPIR-V bug (https://github.com/ppy/osu-framework/issues/5719)
float one = g_BackbufferDraw ? 1 : 0;

vec4 colour = texture(sampler2D(m_Texture, m_Sampler), v_TexCoord, -0.9) * one;
vec4 texel = texture(sampler2D(m_Texture, m_Sampler), v_TexCoord, -0.9) * one;

o_Colour = colour.r < progress ? vec4(v_Colour.rgb, v_Colour.a * colour.a) : vec4(0);
// in the logo animation textures, progress information is stored in red channel,
// and alpha information is stored in green channel. this is done this way
// to avoid alpha pre-multiplication causing data precision loss.
float current = texel.r;
float alpha = texel.g;

o_Colour = current < progress ? v_Colour.rgba * alpha : vec4(0);
}
2 changes: 1 addition & 1 deletion osu.Game.Resources/Shaders/sh_RectangularFlashlight.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ lowp vec4 getColourAt(highp vec2 diff, highp vec2 size, lowp vec4 originalColour

lowp float alpha = length(smoothstep(size, size * flashlightSmoothness, diff));

return originalColour * vec4(1.0, 1.0, 1.0, alpha);
return originalColour * vec4(alpha);
}
2 changes: 1 addition & 1 deletion osu.Game.Resources/Shaders/sh_TriangleBorder.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ void main(void)

lowp vec4 col = getRoundedColor(vec4(1.0), v_TexCoord);

o_Colour = vec4(col.rgb, col.a * alpha);
o_Colour = col.rgba * alpha;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Post-process for logo animation path textures, moving alpha information away from the alpha channel
// for the shader to produce correct animation without losing information from textures being alpha-premultiplied.
// Input: textures with colours in the form: (x, x, x, y), in which x represents current progress and y represents alpha.
// Output: textures with colours in the form: (x, y, 0, 255).

// Code is commented to not cause compile errors on osu-resources.

/*
const string path = "<osu-resources>/osu.Game.Resources/Textures/Intro/Triangles";
processImage(Path.Combine(path, "logo-background.png"));
processImage(Path.Combine(path, "logo-highlight.png"));

void processImage(string filename)
{
using var image = Image.Load<Rgba32>(filename);

image.ProcessPixelRows(p =>
{
for (int i = 0; i < p.Height; i++)
{
foreach (ref var pixel in p.GetRowSpan(i))
pixel = new Rgba32(pixel.R, pixel.A, 0, 255);
}
});

image.SaveAsPng(filename);
}
*/
Binary file modified osu.Game.Resources/Textures/Intro/Triangles/logo-background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified osu.Game.Resources/Textures/Intro/Triangles/logo-highlight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.