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

Move gamma correction logic from renderer/shader to vertex input #5721

Merged
merged 16 commits into from Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 0 additions & 106 deletions osu.Framework.Tests/Visual/Drawables/TestSceneColourInterpolation.cs

This file was deleted.

202 changes: 202 additions & 0 deletions osu.Framework.Tests/Visual/Drawables/TestSceneGammaCorrection.cs
@@ -0,0 +1,202 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Utils;
using osuTK;
using osuTK.Graphics;

namespace osu.Framework.Tests.Visual.Drawables
{
public partial class TestSceneGammaCorrection : FrameworkTestScene
{
private FillFlowContainer interpolatingLines = null!;

[Resolved]
private TextureStore textures { get; set; } = null!;

[SetUp]
public void SetUp() => Schedule(() =>
{
Child = new FillFlowContainer
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Margin = new MarginPadding(20),
Children = new Drawable[]
{
new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = "Interpolation in linear space (gamma-correct)",
Font = FrameworkFont.Regular.With(size: 24),
Margin = new MarginPadding { Bottom = 10f },
},
new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = "d3.interpolateRgb.gamma(2.2)(\"red\", \"blue\")"
},
new Sprite
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Size = new Vector2(750f, 50f),
// Taken from https://observablehq.com/@d3/working-with-color
Texture = textures.Get("d3-colour-interpolation"),
},
new SpriteText
{
Margin = new MarginPadding { Top = 20f },
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = $"{nameof(Interpolation)}.{nameof(Interpolation.ValueAt)}(Red, Red) with 1px boxes",
frenzibyte marked this conversation as resolved.
Show resolved Hide resolved
},
interpolatingLines = new FillFlowContainer
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.X,
Height = 50f,
ChildrenEnumerable = Enumerable.Range(0, 750).Select(i => new Box
{
Width = 1f,
RelativeSizeAxes = Axes.Y,
Colour = Interpolation.ValueAt(i, Color4.Red, Color4.Blue, 0, 750),
}),
},
new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = "Interpolation in sRGB space (gamma-incorrect)",
Font = FrameworkFont.Regular.With(size: 24),
Margin = new MarginPadding { Top = 50f, Bottom = 10f },
},
new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = "Figma design",
},
new Sprite
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Size = new Vector2(750f, 50f),
Texture = textures.Get("figma-colour-interpolation"),
},
new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Top = 20f },
Text = $"{nameof(ColourInfo)}.{nameof(ColourInfo.GradientHorizontal)}(Blue, Red)"
frenzibyte marked this conversation as resolved.
Show resolved Hide resolved
},
new Box
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Size = new Vector2(750f, 50f),
Colour = ColourInfo.GradientHorizontal(Color4.Red, Color4.Blue),
},
new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = "Colour blending",
Font = FrameworkFont.Regular.With(size: 24),
Margin = new MarginPadding { Top = 50f, Bottom = 10f },
},
new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = "Regular container",
},
new Container
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Size = new Vector2(750, 50),
Children = new[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Red
},
new Box
{
RelativeSizeAxes = Axes.Both,
Width = 0.5f,
Colour = Color4.Black,
Alpha = 0.5f
}
}
},
new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = "Buffered container",
Margin = new MarginPadding { Top = 20f },
},
new BufferedContainer
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Size = new Vector2(750, 50),
Children = new[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Red
},
new Box
{
RelativeSizeAxes = Axes.Both,
Width = 0.5f,
Colour = Color4.Black,
Alpha = 0.5f
}
}
},
}
};
});

[Test]
public void TestInterpolationInLinearSpace()
{
AddAssert("interpolation in linear space", () =>
{
var middle = interpolatingLines.Children[interpolatingLines.Children.Count / 2];
return middle.Colour.AverageColour.Linear == new Color4(0.5f, 0f, 0.5f, 1f);
});
}

public partial class SampleSpriteD3 : Sprite
{
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
// Taken from https://observablehq.com/@d3/working-with-color
Texture = textures.Get("colour-interpolation");
}
}
}
}
16 changes: 8 additions & 8 deletions osu.Framework/Graphics/Colour/ColourInfo.cs
Expand Up @@ -230,10 +230,10 @@ public void ApplyChild(ColourInfo childColour, Quad interp)
{
get
{
float max = TopLeft.Linear.A;
if (TopRight.Linear.A > max) max = TopRight.Linear.A;
if (BottomLeft.Linear.A > max) max = BottomLeft.Linear.A;
if (BottomRight.Linear.A > max) max = BottomRight.Linear.A;
float max = TopLeft.Alpha;
if (TopRight.Alpha > max) max = TopRight.Alpha;
if (BottomLeft.Alpha > max) max = BottomLeft.Alpha;
if (BottomRight.Alpha > max) max = BottomRight.Alpha;

return max;
}
Expand All @@ -246,10 +246,10 @@ public void ApplyChild(ColourInfo childColour, Quad interp)
{
get
{
float min = TopLeft.Linear.A;
if (TopRight.Linear.A < min) min = TopRight.Linear.A;
if (BottomLeft.Linear.A < min) min = BottomLeft.Linear.A;
if (BottomRight.Linear.A < min) min = BottomRight.Linear.A;
float min = TopLeft.Alpha;
if (TopRight.Alpha < min) min = TopRight.Alpha;
if (BottomLeft.Alpha < min) min = BottomLeft.Alpha;
if (BottomRight.Alpha < min) min = BottomRight.Alpha;

return min;
}
Expand Down