From 14a4de36f4cbd269f40b982930c9aedd8dbbba59 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Mon, 21 Nov 2022 10:20:35 +0300 Subject: [PATCH] Expose thickness property --- .../TestSceneTriangleBorderShader.cs | 41 ++++++++++++++++++- .../TestSceneTrianglesV2Background.cs | 1 + osu.Game/Graphics/Backgrounds/TrianglesV2.cs | 18 ++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneTriangleBorderShader.cs b/osu.Game.Tests/Visual/Background/TestSceneTriangleBorderShader.cs index 41a1d9b42e..64512bc651 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneTriangleBorderShader.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneTriangleBorderShader.cs @@ -14,6 +14,8 @@ namespace osu.Game.Tests.Visual.Background { public class TestSceneTriangleBorderShader : OsuTestScene { + private readonly TriangleBorder border; + public TestSceneTriangleBorderShader() { Children = new Drawable[] @@ -23,7 +25,7 @@ namespace osu.Game.Tests.Visual.Background RelativeSizeAxes = Axes.Both, Colour = Color4.DarkGreen }, - new TriangleBorder + border = new TriangleBorder { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -32,8 +34,27 @@ namespace osu.Game.Tests.Visual.Background }; } + protected override void LoadComplete() + { + base.LoadComplete(); + + AddSliderStep("Thickness", 0f, 1f, 0.02f, t => border.Thickness = t); + } + private class TriangleBorder : Sprite { + private float thickness = 0.02f; + + public float Thickness + { + get => thickness; + set + { + thickness = value; + Invalidate(Invalidation.DrawNode); + } + } + [BackgroundDependencyLoader] private void load(ShaderManager shaders, IRenderer renderer) { @@ -45,11 +66,29 @@ namespace osu.Game.Tests.Visual.Background private class TriangleBorderDrawNode : SpriteDrawNode { + public new TriangleBorder Source => (TriangleBorder)base.Source; + public TriangleBorderDrawNode(TriangleBorder source) : base(source) { } + private float thickness; + + public override void ApplyState() + { + base.ApplyState(); + + thickness = Source.thickness; + } + + public override void Draw(IRenderer renderer) + { + TextureShader.GetUniform("thickness").UpdateValue(ref thickness); + + base.Draw(renderer); + } + protected override bool CanDrawOpaqueInterior => false; } } diff --git a/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs b/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs index f6207c46a5..e8abc573cd 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs @@ -47,6 +47,7 @@ namespace osu.Game.Tests.Visual.Background base.LoadComplete(); AddSliderStep("Spawn ratio", 0f, 2f, 1f, s => triangles.SpawnRatio = s); + AddSliderStep("Thickness", 0f, 1f, 0.02f, t => triangles.Thickness = t); } } } diff --git a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs index 4da227d5d6..ca920bdd66 100644 --- a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs +++ b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs @@ -45,6 +45,21 @@ namespace osu.Game.Graphics.Backgrounds set => colourBottom.Value = value; } + private float thickness = 0.02f; + + public float Thickness + { + get => thickness; + set + { + if (thickness == value) + return; + + thickness = value; + // No need for invalidation since it's happening in Update() + } + } + /// /// Whether we should create new triangles as others expire. /// @@ -226,6 +241,7 @@ namespace osu.Game.Graphics.Backgrounds private readonly List parts = new List(); private Vector2 size; + private float thickness; private IVertexBatch? vertexBatch; @@ -241,6 +257,7 @@ namespace osu.Game.Graphics.Backgrounds shader = Source.shader; texture = Source.texture; size = Source.DrawSize; + thickness = Source.thickness; parts.Clear(); parts.AddRange(Source.parts); @@ -260,6 +277,7 @@ namespace osu.Game.Graphics.Backgrounds } shader.Bind(); + shader.GetUniform("thickness").UpdateValue(ref thickness); foreach (TriangleParticle particle in parts) {