From 48e5d188a74ee5bc90f29e5e49df2f1410397350 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Mon, 16 Sep 2024 18:05:53 +0300 Subject: [PATCH 01/47] Added "Background Colour" setting --- osu.Game/Configuration/OsuConfigManager.cs | 2 ++ osu.Game/Localisation/GameplaySettingsStrings.cs | 5 +++++ .../Settings/Sections/Gameplay/BackgroundSettings.cs | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index 8d6c244b350c..ed8301471175 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -133,6 +133,7 @@ protected override void InitialiseDefaults() // Gameplay SetDefault(OsuSetting.PositionalHitsoundsLevel, 0.2f, 0, 1); SetDefault(OsuSetting.DimLevel, 0.7, 0, 1, 0.01); + SetDefault(OsuSetting.DimColour, 0.0, 0, 1, 0.01); SetDefault(OsuSetting.BlurLevel, 0, 0, 1, 0.01); SetDefault(OsuSetting.LightenDuringBreaks, true); @@ -329,6 +330,7 @@ public enum OsuSetting AutoCursorSize, GameplayCursorDuringTouch, DimLevel, + DimColour, BlurLevel, EditorDim, LightenDuringBreaks, diff --git a/osu.Game/Localisation/GameplaySettingsStrings.cs b/osu.Game/Localisation/GameplaySettingsStrings.cs index 6de61f7ebeae..3acbb4c6aaf1 100644 --- a/osu.Game/Localisation/GameplaySettingsStrings.cs +++ b/osu.Game/Localisation/GameplaySettingsStrings.cs @@ -49,6 +49,11 @@ public static class GameplaySettingsStrings /// public static LocalisableString BackgroundBlur => new TranslatableString(getKey(@"blur"), @"Background blur"); + /// + /// "Background colour" + /// + public static LocalisableString BackgroundColour => new TranslatableString(getKey(@"bg_colour"), @"Background colour"); + /// /// "Lighten playfield during breaks" /// diff --git a/osu.Game/Overlays/Settings/Sections/Gameplay/BackgroundSettings.cs b/osu.Game/Overlays/Settings/Sections/Gameplay/BackgroundSettings.cs index 048351b4cbb7..041821b60ff9 100644 --- a/osu.Game/Overlays/Settings/Sections/Gameplay/BackgroundSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Gameplay/BackgroundSettings.cs @@ -32,6 +32,13 @@ private void load(OsuConfigManager config) KeyboardStep = 0.01f, DisplayAsPercentage = true }, + new SettingsSlider + { + LabelText = GameplaySettingsStrings.BackgroundColour, + Current = config.GetBindable(OsuSetting.DimColour), + KeyboardStep = 0.01f, + DisplayAsPercentage = true + }, new SettingsCheckbox { LabelText = GameplaySettingsStrings.LightenDuringBreaks, From 261e5ab4f00a13b3e6693e2a4252bdf01762a3aa Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Fri, 20 Sep 2024 06:59:14 +0300 Subject: [PATCH 02/47] Made Background.Sprite replaceable --- osu.Game/Graphics/Backgrounds/Background.cs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/Background.cs b/osu.Game/Graphics/Backgrounds/Background.cs index bc2ad81fefb3..6023fbf92db5 100644 --- a/osu.Game/Graphics/Backgrounds/Background.cs +++ b/osu.Game/Graphics/Backgrounds/Background.cs @@ -20,7 +20,22 @@ namespace osu.Game.Graphics.Backgrounds /// public partial class Background : CompositeDrawable, IEquatable { - public readonly Sprite Sprite; + private Sprite sprite; + + public Sprite Sprite + { + get => sprite; + protected set + { + if (bufferedContainer == null) { + if (sprite != null) + RemoveInternal(sprite, true); + AddInternal(sprite = value); + } else { + bufferedContainer.Child = sprite = value; + } + } + } private readonly string textureName; @@ -31,13 +46,13 @@ public Background(string textureName = @"") this.textureName = textureName; RelativeSizeAxes = Axes.Both; - AddInternal(Sprite = new Sprite + Sprite = new Sprite { RelativeSizeAxes = Axes.Both, Anchor = Anchor.Centre, Origin = Anchor.Centre, FillMode = FillMode.Fill, - }); + }; } [BackgroundDependencyLoader] From 30b37984a8572dcb66ba5f63a83b69cac0af72bd Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Fri, 20 Sep 2024 06:59:50 +0300 Subject: [PATCH 03/47] Made a custom class for BeatmapBackground with a custom BeatmapBackgroundSprite --- .../Backgrounds/BackgroundScreenBeatmap.cs | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 185e2cab9961..e361a5eae1b7 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -8,6 +8,7 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; using osu.Game.Beatmaps; using osu.Game.Configuration; using osu.Game.Graphics.Backgrounds; @@ -148,6 +149,30 @@ public partial class DimmableBackground : UserDimContainer public readonly Bindable StoryboardReplacesBackground = new Bindable(); + public partial class BeatmapBackgroundSprite : Sprite { } + + public partial class BeatmapBackground : Background { + private Background Background; + + public BeatmapBackground(Background background) { + Background = background; + + Sprite = new BeatmapBackgroundSprite { + RelativeSizeAxes = Axes.Both, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + FillMode = FillMode.Fill, + }; + } + + [BackgroundDependencyLoader] + private void load() + { + if (Background != null) + Sprite.Texture = Background.Sprite.Texture; + } + } + public Background Background { get => background; @@ -155,14 +180,14 @@ public Background Background { background?.Expire(); - base.Add(background = value); + base.Add(background = new BeatmapBackground(value)); background.BlurTo(blurTarget, 0, Easing.OutQuint); } } private Bindable userBlurLevel { get; set; } - private Background background; + private BeatmapBackground background; public override void Add(Drawable drawable) { From 1d57a8341a398adc1fa443c652fee1ff40472f80 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Fri, 20 Sep 2024 07:10:24 +0300 Subject: [PATCH 04/47] Made BeatmapBackgroundSprite use a custom shader --- osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index e361a5eae1b7..3c04786a8ffd 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -8,6 +8,7 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Framework.Graphics.Shaders; using osu.Framework.Graphics.Sprites; using osu.Game.Beatmaps; using osu.Game.Configuration; @@ -149,7 +150,13 @@ public partial class DimmableBackground : UserDimContainer public readonly Bindable StoryboardReplacesBackground = new Bindable(); - public partial class BeatmapBackgroundSprite : Sprite { } + public partial class BeatmapBackgroundSprite : Sprite { + [BackgroundDependencyLoader] + private void load(ShaderManager shaders) + { + TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "BeatmapBackground"); + } + } public partial class BeatmapBackground : Background { private Background Background; From 42579a61f46a5f967f34bcac35e11445c69db72b Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Fri, 20 Sep 2024 08:06:24 +0300 Subject: [PATCH 05/47] Added a custom DrawNode for BeatmapBackgroundSprite --- .../Screens/Backgrounds/BackgroundScreenBeatmap.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 3c04786a8ffd..8f442c001126 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -156,6 +156,17 @@ private void load(ShaderManager shaders) { TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "BeatmapBackground"); } + + protected override DrawNode CreateDrawNode() => new BeatmapBackgroundSpriteDrawNode(this); + + public class BeatmapBackgroundSpriteDrawNode : SpriteDrawNode { + public new BeatmapBackgroundSprite Source => (BeatmapBackgroundSprite)base.Source; + + public BeatmapBackgroundSpriteDrawNode(BeatmapBackgroundSprite source) + : base(source) + { + } + } } public partial class BeatmapBackground : Background { From 5b78d6fd41b3516d49d01d32db0570f8aa4d2fc9 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Fri, 20 Sep 2024 08:48:25 +0300 Subject: [PATCH 06/47] Passing parameters to the shader --- .../Backgrounds/BackgroundScreenBeatmap.cs | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 8f442c001126..6c6eee16a248 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -5,10 +5,13 @@ using System; using System.Threading; +using System.Runtime.InteropServices; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Framework.Graphics.Rendering; using osu.Framework.Graphics.Shaders; +using osu.Framework.Graphics.Shaders.Types; using osu.Framework.Graphics.Sprites; using osu.Game.Beatmaps; using osu.Game.Configuration; @@ -166,6 +169,62 @@ public BeatmapBackgroundSpriteDrawNode(BeatmapBackgroundSprite source) : base(source) { } + + private float DimLevel; + private float DimColour; + + private IShader textureShader; + + public override void ApplyState() + { + base.ApplyState(); + + DimLevel = 0.5f; + DimColour = 1.0f; + + textureShader = Source.TextureShader; + } + + private IUniformBuffer beatmapBackgroundParametersBuffer; + + private void BindParametersBuffer(IRenderer renderer) + { + beatmapBackgroundParametersBuffer ??= renderer.CreateUniformBuffer(); + + beatmapBackgroundParametersBuffer.Data = beatmapBackgroundParametersBuffer.Data with + { + DimLevel = DimLevel, + DimColour = DimColour, + }; + + textureShader.BindUniformBlock("m_BeatmapBackgroundParameters", beatmapBackgroundParametersBuffer); + } + + protected override void Draw(IRenderer renderer) + { + BindParametersBuffer(renderer); + base.Draw(renderer); + } + + protected override void DrawOpaqueInterior(IRenderer renderer) + { + BindParametersBuffer(renderer); + base.DrawOpaqueInterior(renderer); + } + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + beatmapBackgroundParametersBuffer?.Dispose(); + } + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + private record struct BeatmapBackgroundParameters + { + public UniformFloat DimLevel; + public UniformFloat DimColour; + private readonly UniformPadding8 pad1; + } } } From d088fc326f0d24478785bea2ae3dd49415531f96 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Fri, 20 Sep 2024 10:59:46 +0300 Subject: [PATCH 07/47] Made BeatmapBackground shader handle dimming --- osu.Game/Graphics/Backgrounds/Background.cs | 2 +- .../Graphics/Containers/UserDimContainer.cs | 2 +- .../Backgrounds/BackgroundScreenBeatmap.cs | 42 +++++++++++++++++-- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/Background.cs b/osu.Game/Graphics/Backgrounds/Background.cs index 6023fbf92db5..55a0cecee529 100644 --- a/osu.Game/Graphics/Backgrounds/Background.cs +++ b/osu.Game/Graphics/Backgrounds/Background.cs @@ -39,7 +39,7 @@ protected set private readonly string textureName; - private BufferedContainer bufferedContainer; + protected BufferedContainer bufferedContainer { get; private set; } public Background(string textureName = @"") { diff --git a/osu.Game/Graphics/Containers/UserDimContainer.cs b/osu.Game/Graphics/Containers/UserDimContainer.cs index af5e7692b3ec..67454b6b438e 100644 --- a/osu.Game/Graphics/Containers/UserDimContainer.cs +++ b/osu.Game/Graphics/Containers/UserDimContainer.cs @@ -40,7 +40,7 @@ public abstract partial class UserDimContainer : Container /// /// Whether the content of this container is currently being displayed. /// - public bool ContentDisplayed { get; private set; } + public bool ContentDisplayed { get; protected set; } protected Bindable UserDimLevel { get; private set; } = null!; diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 6c6eee16a248..027d5f06a0be 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -154,6 +154,9 @@ public partial class DimmableBackground : UserDimContainer public readonly Bindable StoryboardReplacesBackground = new Bindable(); public partial class BeatmapBackgroundSprite : Sprite { + public float DimLevel; + public float DimColour; + [BackgroundDependencyLoader] private void load(ShaderManager shaders) { @@ -179,8 +182,8 @@ public override void ApplyState() { base.ApplyState(); - DimLevel = 0.5f; - DimColour = 1.0f; + DimLevel = Source.DimLevel; + DimColour = Source.DimColour; textureShader = Source.TextureShader; } @@ -231,6 +234,31 @@ private record struct BeatmapBackgroundParameters public partial class BeatmapBackground : Background { private Background Background; + private float dimLevel; + private float dimColour; + + public float DimLevel { + get => dimLevel; + set { + dimLevel = value; + BeatmapBackgroundSprite sprite = (BeatmapBackgroundSprite)Sprite; + sprite.DimLevel = dimLevel; + + bufferedContainer?.ForceRedraw(); + } + } + + public float DimColour { + get => dimColour; + set { + dimColour = value; + BeatmapBackgroundSprite sprite = (BeatmapBackgroundSprite)Sprite; + sprite.DimColour = dimColour; + + bufferedContainer?.ForceRedraw(); + } + } + public BeatmapBackground(Background background) { Background = background; @@ -296,6 +324,11 @@ protected override void LoadComplete() userBlurLevel.ValueChanged += _ => UpdateVisuals(); BlurAmount.ValueChanged += _ => UpdateVisuals(); StoryboardReplacesBackground.ValueChanged += _ => UpdateVisuals(); + + if (background != null) { + background.DimLevel = DimLevel; + background.DimColour = 0.0f; + } } protected override float DimLevel @@ -311,7 +344,10 @@ protected override float DimLevel protected override void UpdateVisuals() { - base.UpdateVisuals(); + ContentDisplayed = ShowDimContent; + + Content.FadeTo(ContentDisplayed ? 1 : 0, BACKGROUND_FADE_DURATION, Easing.OutQuint); + background?.TransformTo(nameof(BeatmapBackground.DimLevel), DimLevel, BACKGROUND_FADE_DURATION, Easing.OutQuint); Background?.BlurTo(blurTarget, BACKGROUND_FADE_DURATION, Easing.OutQuint); } From be56dd7b71910c756743604e443c327a852de049 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Fri, 20 Sep 2024 11:14:29 +0300 Subject: [PATCH 08/47] Added support for DimColour --- osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 027d5f06a0be..91e6c8527f29 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -291,6 +291,7 @@ public Background Background } private Bindable userBlurLevel { get; set; } + private Bindable userDimColour { get; set; } private BeatmapBackground background; @@ -315,6 +316,7 @@ public override void Add(Drawable drawable) private void load(OsuConfigManager config) { userBlurLevel = config.GetBindable(OsuSetting.BlurLevel); + userDimColour = config.GetBindable(OsuSetting.DimColour); } protected override void LoadComplete() @@ -322,12 +324,13 @@ protected override void LoadComplete() base.LoadComplete(); userBlurLevel.ValueChanged += _ => UpdateVisuals(); + userDimColour.ValueChanged += _ => UpdateVisuals(); BlurAmount.ValueChanged += _ => UpdateVisuals(); StoryboardReplacesBackground.ValueChanged += _ => UpdateVisuals(); if (background != null) { background.DimLevel = DimLevel; - background.DimColour = 0.0f; + background.DimColour = DimColour; } } @@ -342,6 +345,8 @@ protected override float DimLevel } } + protected virtual float DimColour => (float)userDimColour.Value; + protected override void UpdateVisuals() { ContentDisplayed = ShowDimContent; @@ -349,6 +354,8 @@ protected override void UpdateVisuals() Content.FadeTo(ContentDisplayed ? 1 : 0, BACKGROUND_FADE_DURATION, Easing.OutQuint); background?.TransformTo(nameof(BeatmapBackground.DimLevel), DimLevel, BACKGROUND_FADE_DURATION, Easing.OutQuint); + background?.TransformTo(nameof(BeatmapBackground.DimColour), DimColour, BACKGROUND_FADE_DURATION, Easing.OutQuint); + Background?.BlurTo(blurTarget, BACKGROUND_FADE_DURATION, Easing.OutQuint); } } From b5156d95a0ddc414b5eb534a81e0ccd59f60760f Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Fri, 20 Sep 2024 11:32:09 +0300 Subject: [PATCH 09/47] Pass a full colour for DimColour instead of a single value into a shader --- osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 91e6c8527f29..26b348fe64e6 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -196,8 +196,8 @@ private void BindParametersBuffer(IRenderer renderer) beatmapBackgroundParametersBuffer.Data = beatmapBackgroundParametersBuffer.Data with { + DimColour = new Vector4(DimColour, DimColour, DimColour, 1.0f), DimLevel = DimLevel, - DimColour = DimColour, }; textureShader.BindUniformBlock("m_BeatmapBackgroundParameters", beatmapBackgroundParametersBuffer); @@ -224,9 +224,9 @@ protected override void Dispose(bool isDisposing) [StructLayout(LayoutKind.Sequential, Pack = 1)] private record struct BeatmapBackgroundParameters { + public UniformVector4 DimColour; public UniformFloat DimLevel; - public UniformFloat DimColour; - private readonly UniformPadding8 pad1; + private readonly UniformPadding12 pad1; } } } From fa965fab7c4838824f8331fb3c6c69ef128dbcc3 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Sat, 21 Sep 2024 07:13:17 +0300 Subject: [PATCH 10/47] Changed BeatmapBackground class name to DimmableBeatmapBackground to avoid confusion with existing BeatmapBackground class --- .../Backgrounds/BackgroundScreenBeatmap.cs | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 26b348fe64e6..fea49e215aac 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -153,22 +153,22 @@ public partial class DimmableBackground : UserDimContainer public readonly Bindable StoryboardReplacesBackground = new Bindable(); - public partial class BeatmapBackgroundSprite : Sprite { + public partial class DimmableBeatmapBackgroundSprite : Sprite { public float DimLevel; public float DimColour; [BackgroundDependencyLoader] private void load(ShaderManager shaders) { - TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "BeatmapBackground"); + TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "DimmableBeatmapBackground"); } - protected override DrawNode CreateDrawNode() => new BeatmapBackgroundSpriteDrawNode(this); + protected override DrawNode CreateDrawNode() => new DimmableBeatmapBackgroundSpriteDrawNode(this); - public class BeatmapBackgroundSpriteDrawNode : SpriteDrawNode { - public new BeatmapBackgroundSprite Source => (BeatmapBackgroundSprite)base.Source; + public class DimmableBeatmapBackgroundSpriteDrawNode : SpriteDrawNode { + public new DimmableBeatmapBackgroundSprite Source => (DimmableBeatmapBackgroundSprite)base.Source; - public BeatmapBackgroundSpriteDrawNode(BeatmapBackgroundSprite source) + public DimmableBeatmapBackgroundSpriteDrawNode(DimmableBeatmapBackgroundSprite source) : base(source) { } @@ -188,19 +188,19 @@ public override void ApplyState() textureShader = Source.TextureShader; } - private IUniformBuffer beatmapBackgroundParametersBuffer; + private IUniformBuffer dimmableBeatmapBackgroundParametersBuffer; private void BindParametersBuffer(IRenderer renderer) { - beatmapBackgroundParametersBuffer ??= renderer.CreateUniformBuffer(); + dimmableBeatmapBackgroundParametersBuffer ??= renderer.CreateUniformBuffer(); - beatmapBackgroundParametersBuffer.Data = beatmapBackgroundParametersBuffer.Data with + dimmableBeatmapBackgroundParametersBuffer.Data = dimmableBeatmapBackgroundParametersBuffer.Data with { DimColour = new Vector4(DimColour, DimColour, DimColour, 1.0f), DimLevel = DimLevel, }; - textureShader.BindUniformBlock("m_BeatmapBackgroundParameters", beatmapBackgroundParametersBuffer); + textureShader.BindUniformBlock("m_DimmableBeatmapBackgroundParameters", dimmableBeatmapBackgroundParametersBuffer); } protected override void Draw(IRenderer renderer) @@ -218,11 +218,11 @@ protected override void DrawOpaqueInterior(IRenderer renderer) protected override void Dispose(bool isDisposing) { base.Dispose(isDisposing); - beatmapBackgroundParametersBuffer?.Dispose(); + dimmableBeatmapBackgroundParametersBuffer?.Dispose(); } [StructLayout(LayoutKind.Sequential, Pack = 1)] - private record struct BeatmapBackgroundParameters + private record struct DimmableBeatmapBackgroundParameters { public UniformVector4 DimColour; public UniformFloat DimLevel; @@ -231,7 +231,7 @@ private record struct BeatmapBackgroundParameters } } - public partial class BeatmapBackground : Background { + public partial class DimmableBeatmapBackground : Background { private Background Background; private float dimLevel; @@ -241,7 +241,7 @@ public float DimLevel { get => dimLevel; set { dimLevel = value; - BeatmapBackgroundSprite sprite = (BeatmapBackgroundSprite)Sprite; + DimmableBeatmapBackgroundSprite sprite = (DimmableBeatmapBackgroundSprite)Sprite; sprite.DimLevel = dimLevel; bufferedContainer?.ForceRedraw(); @@ -252,17 +252,17 @@ public float DimColour { get => dimColour; set { dimColour = value; - BeatmapBackgroundSprite sprite = (BeatmapBackgroundSprite)Sprite; + DimmableBeatmapBackgroundSprite sprite = (DimmableBeatmapBackgroundSprite)Sprite; sprite.DimColour = dimColour; bufferedContainer?.ForceRedraw(); } } - public BeatmapBackground(Background background) { + public DimmableBeatmapBackground(Background background) { Background = background; - Sprite = new BeatmapBackgroundSprite { + Sprite = new DimmableBeatmapBackgroundSprite { RelativeSizeAxes = Axes.Both, Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -285,7 +285,7 @@ public Background Background { background?.Expire(); - base.Add(background = new BeatmapBackground(value)); + base.Add(background = new DimmableBeatmapBackground(value)); background.BlurTo(blurTarget, 0, Easing.OutQuint); } } @@ -293,7 +293,7 @@ public Background Background private Bindable userBlurLevel { get; set; } private Bindable userDimColour { get; set; } - private BeatmapBackground background; + private DimmableBeatmapBackground background; public override void Add(Drawable drawable) { @@ -352,9 +352,9 @@ protected override void UpdateVisuals() ContentDisplayed = ShowDimContent; Content.FadeTo(ContentDisplayed ? 1 : 0, BACKGROUND_FADE_DURATION, Easing.OutQuint); - background?.TransformTo(nameof(BeatmapBackground.DimLevel), DimLevel, BACKGROUND_FADE_DURATION, Easing.OutQuint); + background?.TransformTo(nameof(DimmableBeatmapBackground.DimLevel), DimLevel, BACKGROUND_FADE_DURATION, Easing.OutQuint); - background?.TransformTo(nameof(BeatmapBackground.DimColour), DimColour, BACKGROUND_FADE_DURATION, Easing.OutQuint); + background?.TransformTo(nameof(DimmableBeatmapBackground.DimColour), DimColour, BACKGROUND_FADE_DURATION, Easing.OutQuint); Background?.BlurTo(blurTarget, BACKGROUND_FADE_DURATION, Easing.OutQuint); } From 7a6f1972979e66525719ae2313e26465174fb2e8 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Sat, 21 Sep 2024 07:29:54 +0300 Subject: [PATCH 11/47] Moved DimmableBeatmapBackground to its own file --- .../Backgrounds/DimmableBeatmapBackground.cs | 149 ++++++++++++++++++ .../Backgrounds/BackgroundScreenBeatmap.cs | 130 --------------- 2 files changed, 149 insertions(+), 130 deletions(-) create mode 100644 osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs diff --git a/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs b/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs new file mode 100644 index 000000000000..6ab38cc72bd6 --- /dev/null +++ b/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs @@ -0,0 +1,149 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +#nullable disable + +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Rendering; +using osu.Framework.Graphics.Shaders; +using osu.Framework.Graphics.Shaders.Types; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Textures; +using osu.Framework.Graphics.Transforms; +using osuTK; + +namespace osu.Game.Graphics.Backgrounds +{ + /// + /// A background which offers dimming using a custom shader with ability to change dim colour. + /// + public partial class DimmableBeatmapBackground : Background { + private Background Background; + + private float dimLevel; + private float dimColour; + + public float DimLevel { + get => dimLevel; + set { + dimLevel = value; + DimmableBeatmapBackgroundSprite sprite = (DimmableBeatmapBackgroundSprite)Sprite; + sprite.DimLevel = dimLevel; + + bufferedContainer?.ForceRedraw(); + } + } + + public float DimColour { + get => dimColour; + set { + dimColour = value; + DimmableBeatmapBackgroundSprite sprite = (DimmableBeatmapBackgroundSprite)Sprite; + sprite.DimColour = dimColour; + + bufferedContainer?.ForceRedraw(); + } + } + + public DimmableBeatmapBackground(Background background) { + Background = background; + + Sprite = new DimmableBeatmapBackgroundSprite { + RelativeSizeAxes = Axes.Both, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + FillMode = FillMode.Fill, + }; + } + + [BackgroundDependencyLoader] + private void load() + { + if (Background != null) + Sprite.Texture = Background.Sprite.Texture; + } + + public partial class DimmableBeatmapBackgroundSprite : Sprite { + public float DimLevel; + public float DimColour; + + [BackgroundDependencyLoader] + private void load(ShaderManager shaders) + { + TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "DimmableBeatmapBackground"); + } + + protected override DrawNode CreateDrawNode() => new DimmableBeatmapBackgroundSpriteDrawNode(this); + + public class DimmableBeatmapBackgroundSpriteDrawNode : SpriteDrawNode { + public new DimmableBeatmapBackgroundSprite Source => (DimmableBeatmapBackgroundSprite)base.Source; + + public DimmableBeatmapBackgroundSpriteDrawNode(DimmableBeatmapBackgroundSprite source) + : base(source) + { + } + + private float DimLevel; + private float DimColour; + + private IShader textureShader; + + public override void ApplyState() + { + base.ApplyState(); + + DimLevel = Source.DimLevel; + DimColour = Source.DimColour; + + textureShader = Source.TextureShader; + } + + private IUniformBuffer dimmableBeatmapBackgroundParametersBuffer; + + private void BindParametersBuffer(IRenderer renderer) + { + dimmableBeatmapBackgroundParametersBuffer ??= renderer.CreateUniformBuffer(); + + dimmableBeatmapBackgroundParametersBuffer.Data = dimmableBeatmapBackgroundParametersBuffer.Data with + { + DimColour = new Vector4(DimColour, DimColour, DimColour, 1.0f), + DimLevel = DimLevel, + }; + + textureShader.BindUniformBlock("m_DimmableBeatmapBackgroundParameters", dimmableBeatmapBackgroundParametersBuffer); + } + + protected override void Draw(IRenderer renderer) + { + BindParametersBuffer(renderer); + base.Draw(renderer); + } + + protected override void DrawOpaqueInterior(IRenderer renderer) + { + BindParametersBuffer(renderer); + base.DrawOpaqueInterior(renderer); + } + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + dimmableBeatmapBackgroundParametersBuffer?.Dispose(); + } + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + private record struct DimmableBeatmapBackgroundParameters + { + public UniformVector4 DimColour; + public UniformFloat DimLevel; + private readonly UniformPadding12 pad1; + } + } + } + } +} diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index fea49e215aac..5f79902cdb02 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -5,14 +5,9 @@ using System; using System.Threading; -using System.Runtime.InteropServices; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; -using osu.Framework.Graphics.Rendering; -using osu.Framework.Graphics.Shaders; -using osu.Framework.Graphics.Shaders.Types; -using osu.Framework.Graphics.Sprites; using osu.Game.Beatmaps; using osu.Game.Configuration; using osu.Game.Graphics.Backgrounds; @@ -153,131 +148,6 @@ public partial class DimmableBackground : UserDimContainer public readonly Bindable StoryboardReplacesBackground = new Bindable(); - public partial class DimmableBeatmapBackgroundSprite : Sprite { - public float DimLevel; - public float DimColour; - - [BackgroundDependencyLoader] - private void load(ShaderManager shaders) - { - TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "DimmableBeatmapBackground"); - } - - protected override DrawNode CreateDrawNode() => new DimmableBeatmapBackgroundSpriteDrawNode(this); - - public class DimmableBeatmapBackgroundSpriteDrawNode : SpriteDrawNode { - public new DimmableBeatmapBackgroundSprite Source => (DimmableBeatmapBackgroundSprite)base.Source; - - public DimmableBeatmapBackgroundSpriteDrawNode(DimmableBeatmapBackgroundSprite source) - : base(source) - { - } - - private float DimLevel; - private float DimColour; - - private IShader textureShader; - - public override void ApplyState() - { - base.ApplyState(); - - DimLevel = Source.DimLevel; - DimColour = Source.DimColour; - - textureShader = Source.TextureShader; - } - - private IUniformBuffer dimmableBeatmapBackgroundParametersBuffer; - - private void BindParametersBuffer(IRenderer renderer) - { - dimmableBeatmapBackgroundParametersBuffer ??= renderer.CreateUniformBuffer(); - - dimmableBeatmapBackgroundParametersBuffer.Data = dimmableBeatmapBackgroundParametersBuffer.Data with - { - DimColour = new Vector4(DimColour, DimColour, DimColour, 1.0f), - DimLevel = DimLevel, - }; - - textureShader.BindUniformBlock("m_DimmableBeatmapBackgroundParameters", dimmableBeatmapBackgroundParametersBuffer); - } - - protected override void Draw(IRenderer renderer) - { - BindParametersBuffer(renderer); - base.Draw(renderer); - } - - protected override void DrawOpaqueInterior(IRenderer renderer) - { - BindParametersBuffer(renderer); - base.DrawOpaqueInterior(renderer); - } - - protected override void Dispose(bool isDisposing) - { - base.Dispose(isDisposing); - dimmableBeatmapBackgroundParametersBuffer?.Dispose(); - } - - [StructLayout(LayoutKind.Sequential, Pack = 1)] - private record struct DimmableBeatmapBackgroundParameters - { - public UniformVector4 DimColour; - public UniformFloat DimLevel; - private readonly UniformPadding12 pad1; - } - } - } - - public partial class DimmableBeatmapBackground : Background { - private Background Background; - - private float dimLevel; - private float dimColour; - - public float DimLevel { - get => dimLevel; - set { - dimLevel = value; - DimmableBeatmapBackgroundSprite sprite = (DimmableBeatmapBackgroundSprite)Sprite; - sprite.DimLevel = dimLevel; - - bufferedContainer?.ForceRedraw(); - } - } - - public float DimColour { - get => dimColour; - set { - dimColour = value; - DimmableBeatmapBackgroundSprite sprite = (DimmableBeatmapBackgroundSprite)Sprite; - sprite.DimColour = dimColour; - - bufferedContainer?.ForceRedraw(); - } - } - - public DimmableBeatmapBackground(Background background) { - Background = background; - - Sprite = new DimmableBeatmapBackgroundSprite { - RelativeSizeAxes = Axes.Both, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - FillMode = FillMode.Fill, - }; - } - - [BackgroundDependencyLoader] - private void load() - { - if (Background != null) - Sprite.Texture = Background.Sprite.Texture; - } - } - public Background Background { get => background; From 4c3401fbd67bf2c7a0e5449d9b06ce1a7544b417 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Sat, 21 Sep 2024 10:08:53 +0300 Subject: [PATCH 12/47] Made DimmableBeatmapBackground inherit from BeatmapBackground, switched BeatmapBackground to DimmableBeatmapBackground in BackgroundScreenBeatmap --- .../Backgrounds/DimmableBeatmapBackground.cs | 16 +++------------- .../Backgrounds/BackgroundScreenBeatmap.cs | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs b/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs index 6ab38cc72bd6..e7362d9cca49 100644 --- a/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs +++ b/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs @@ -15,6 +15,7 @@ using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Transforms; +using osu.Game.Beatmaps; using osuTK; namespace osu.Game.Graphics.Backgrounds @@ -22,9 +23,7 @@ namespace osu.Game.Graphics.Backgrounds /// /// A background which offers dimming using a custom shader with ability to change dim colour. /// - public partial class DimmableBeatmapBackground : Background { - private Background Background; - + public partial class DimmableBeatmapBackground : BeatmapBackground { private float dimLevel; private float dimColour; @@ -50,9 +49,7 @@ public float DimColour { } } - public DimmableBeatmapBackground(Background background) { - Background = background; - + public DimmableBeatmapBackground(WorkingBeatmap beatmap, string fallbackTextureName = @"Backgrounds/bg1") : base(beatmap, fallbackTextureName) { Sprite = new DimmableBeatmapBackgroundSprite { RelativeSizeAxes = Axes.Both, Anchor = Anchor.Centre, @@ -61,13 +58,6 @@ public DimmableBeatmapBackground(Background background) { }; } - [BackgroundDependencyLoader] - private void load() - { - if (Background != null) - Sprite.Texture = Background.Sprite.Texture; - } - public partial class DimmableBeatmapBackgroundSprite : Sprite { public float DimLevel; public float DimColour; diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 5f79902cdb02..c2aad8974630 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -73,7 +73,7 @@ public BackgroundScreenBeatmap(WorkingBeatmap beatmap = null) [BackgroundDependencyLoader] private void load() { - var background = new BeatmapBackground(beatmap); + var background = new DimmableBeatmapBackground(beatmap); LoadComponent(background); switchBackground(background); } @@ -92,11 +92,11 @@ public WorkingBeatmap Beatmap Schedule(() => { - if ((Background as BeatmapBackground)?.Beatmap.BeatmapInfo.BackgroundEquals(beatmap?.BeatmapInfo) ?? false) + if ((Background as DimmableBeatmapBackground)?.Beatmap.BeatmapInfo.BackgroundEquals(beatmap?.BeatmapInfo) ?? false) return; cancellationSource?.Cancel(); - LoadComponentAsync(new BeatmapBackground(beatmap), switchBackground, (cancellationSource = new CancellationTokenSource()).Token); + LoadComponentAsync(new DimmableBeatmapBackground(beatmap), switchBackground, (cancellationSource = new CancellationTokenSource()).Token); }); } } @@ -109,11 +109,11 @@ public void RefreshBackground() Schedule(() => { cancellationSource?.Cancel(); - LoadComponentAsync(new BeatmapBackground(beatmap), switchBackground, (cancellationSource = new CancellationTokenSource()).Token); + LoadComponentAsync(new DimmableBeatmapBackground(beatmap), switchBackground, (cancellationSource = new CancellationTokenSource()).Token); }); } - private void switchBackground(BeatmapBackground b) + private void switchBackground(DimmableBeatmapBackground b) { float newDepth = 0; @@ -126,7 +126,7 @@ private void switchBackground(BeatmapBackground b) } b.Depth = newDepth; - dimmable.Background = Background = b; + Background = dimmable.DimmableBeatmapBackground = b; } public override bool Equals(BackgroundScreen other) @@ -148,14 +148,16 @@ public partial class DimmableBackground : UserDimContainer public readonly Bindable StoryboardReplacesBackground = new Bindable(); - public Background Background + public Background Background => background; + + public DimmableBeatmapBackground DimmableBeatmapBackground { get => background; set { background?.Expire(); - base.Add(background = new DimmableBeatmapBackground(value)); + base.Add(background = value); background.BlurTo(blurTarget, 0, Easing.OutQuint); } } From 9283107fbf8c1ab602c09f391dbdff75597570de Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Sat, 21 Sep 2024 10:43:06 +0300 Subject: [PATCH 13/47] Switched to using Color4 for DimColour instead of float --- .../Graphics/Backgrounds/DimmableBeatmapBackground.cs | 11 ++++++----- .../Screens/Backgrounds/BackgroundScreenBeatmap.cs | 4 +++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs b/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs index e7362d9cca49..95f3df7052ff 100644 --- a/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs +++ b/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs @@ -17,6 +17,7 @@ using osu.Framework.Graphics.Transforms; using osu.Game.Beatmaps; using osuTK; +using osuTK.Graphics; namespace osu.Game.Graphics.Backgrounds { @@ -25,7 +26,7 @@ namespace osu.Game.Graphics.Backgrounds /// public partial class DimmableBeatmapBackground : BeatmapBackground { private float dimLevel; - private float dimColour; + private Color4 dimColour; public float DimLevel { get => dimLevel; @@ -38,7 +39,7 @@ public float DimLevel { } } - public float DimColour { + public Color4 DimColour { get => dimColour; set { dimColour = value; @@ -60,7 +61,7 @@ public DimmableBeatmapBackground(WorkingBeatmap beatmap, string fallbackTextureN public partial class DimmableBeatmapBackgroundSprite : Sprite { public float DimLevel; - public float DimColour; + public Color4 DimColour; [BackgroundDependencyLoader] private void load(ShaderManager shaders) @@ -79,7 +80,7 @@ public DimmableBeatmapBackgroundSpriteDrawNode(DimmableBeatmapBackgroundSprite s } private float DimLevel; - private float DimColour; + private Color4 DimColour; private IShader textureShader; @@ -101,7 +102,7 @@ private void BindParametersBuffer(IRenderer renderer) dimmableBeatmapBackgroundParametersBuffer.Data = dimmableBeatmapBackgroundParametersBuffer.Data with { - DimColour = new Vector4(DimColour, DimColour, DimColour, 1.0f), + DimColour = new Vector4(DimColour.R, DimColour.G, DimColour.B, DimColour.A), DimLevel = DimLevel, }; diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index c2aad8974630..de77a1080fd1 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -10,10 +10,12 @@ using osu.Framework.Graphics; using osu.Game.Beatmaps; using osu.Game.Configuration; +using osu.Game.Graphics; using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Containers; using osu.Game.Screens.Play; using osuTK; +using osuTK.Graphics; namespace osu.Game.Screens.Backgrounds { @@ -217,7 +219,7 @@ protected override float DimLevel } } - protected virtual float DimColour => (float)userDimColour.Value; + protected virtual Color4 DimColour => OsuColour.Gray((float)userDimColour.Value); protected override void UpdateVisuals() { From a341c3a575d92252fed8032f51dcfc54a0a632a9 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Sat, 21 Sep 2024 13:30:20 +0300 Subject: [PATCH 14/47] Made DimmableBeatmapBackgroundSprite invalidate DrawNode on DimColour and DimLevel update --- .../Backgrounds/DimmableBeatmapBackground.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs b/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs index 95f3df7052ff..397e4f5fa5a8 100644 --- a/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs +++ b/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs @@ -60,8 +60,24 @@ public DimmableBeatmapBackground(WorkingBeatmap beatmap, string fallbackTextureN } public partial class DimmableBeatmapBackgroundSprite : Sprite { - public float DimLevel; - public Color4 DimColour; + private float dimLevel; + private Color4 dimColour; + + public float DimLevel { + get => dimLevel; + set { + dimLevel = value; + Invalidate(Invalidation.DrawNode); + } + } + + public Color4 DimColour { + get => dimColour; + set { + dimColour = value; + Invalidate(Invalidation.DrawNode); + } + } [BackgroundDependencyLoader] private void load(ShaderManager shaders) From b7311fdeadd5127e34cb3e6ddf0c796152112400 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Sat, 21 Sep 2024 14:17:54 +0300 Subject: [PATCH 15/47] Formatting fixes --- osu.Game/Graphics/Backgrounds/Background.cs | 25 +++---- .../Backgrounds/DimmableBeatmapBackground.cs | 66 +++++++++++-------- .../Backgrounds/BackgroundScreenBeatmap.cs | 3 +- 3 files changed, 53 insertions(+), 41 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/Background.cs b/osu.Game/Graphics/Backgrounds/Background.cs index 55a0cecee529..259a868707e5 100644 --- a/osu.Game/Graphics/Backgrounds/Background.cs +++ b/osu.Game/Graphics/Backgrounds/Background.cs @@ -27,19 +27,22 @@ public Sprite Sprite get => sprite; protected set { - if (bufferedContainer == null) { + if (BufferedContainer == null) + { if (sprite != null) RemoveInternal(sprite, true); AddInternal(sprite = value); - } else { - bufferedContainer.Child = sprite = value; + } + else + { + BufferedContainer.Child = sprite = value; } } } private readonly string textureName; - protected BufferedContainer bufferedContainer { get; private set; } + protected BufferedContainer BufferedContainer { get; private set; } public Background(string textureName = @"") { @@ -62,7 +65,7 @@ private void load(LargeTextureStore textures) Sprite.Texture = textures.Get(textureName); } - public Vector2 BlurSigma => Vector2.Divide(bufferedContainer?.BlurSigma ?? Vector2.Zero, blurScale); + public Vector2 BlurSigma => Vector2.Divide(BufferedContainer?.BlurSigma ?? Vector2.Zero, blurScale); /// /// Smoothly adjusts over time. @@ -70,11 +73,11 @@ private void load(LargeTextureStore textures) /// A to which further transforms can be added. public void BlurTo(Vector2 newBlurSigma, double duration = 0, Easing easing = Easing.None) { - if (bufferedContainer == null && newBlurSigma != Vector2.Zero) + if (BufferedContainer == null && newBlurSigma != Vector2.Zero) { RemoveInternal(Sprite, false); - AddInternal(bufferedContainer = new BufferedContainer(cachedFrameBuffer: true) + AddInternal(BufferedContainer = new BufferedContainer(cachedFrameBuffer: true) { RelativeSizeAxes = Axes.Both, RedrawOnScale = false, @@ -82,7 +85,7 @@ public void BlurTo(Vector2 newBlurSigma, double duration = 0, Easing easing = Ea }); } - if (bufferedContainer != null) + if (BufferedContainer != null) transformBlurSigma(newBlurSigma, duration, easing); } @@ -97,13 +100,13 @@ private Vector2 blurSigma get => blurSigmaBacking; set { - Debug.Assert(bufferedContainer != null); + Debug.Assert(BufferedContainer != null); blurSigmaBacking = value; blurScale = new Vector2(calculateBlurDownscale(value.X), calculateBlurDownscale(value.Y)); - bufferedContainer.FrameBufferScale = blurScale; - bufferedContainer.BlurSigma = value * blurScale; // If the image is scaled down, the blur radius also needs to be reduced to cover the same pixel block. + BufferedContainer.FrameBufferScale = blurScale; + BufferedContainer.BlurSigma = value * blurScale; // If the image is scaled down, the blur radius also needs to be reduced to cover the same pixel block. } } diff --git a/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs b/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs index 397e4f5fa5a8..5a260b05ce50 100644 --- a/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs +++ b/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs @@ -3,18 +3,13 @@ #nullable disable -using System; -using System.Diagnostics; using System.Runtime.InteropServices; using osu.Framework.Allocation; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Rendering; using osu.Framework.Graphics.Shaders; using osu.Framework.Graphics.Shaders.Types; using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.Textures; -using osu.Framework.Graphics.Transforms; using osu.Game.Beatmaps; using osuTK; using osuTK.Graphics; @@ -24,34 +19,41 @@ namespace osu.Game.Graphics.Backgrounds /// /// A background which offers dimming using a custom shader with ability to change dim colour. /// - public partial class DimmableBeatmapBackground : BeatmapBackground { + public partial class DimmableBeatmapBackground : BeatmapBackground + { private float dimLevel; private Color4 dimColour; - public float DimLevel { + public float DimLevel + { get => dimLevel; - set { + set + { dimLevel = value; DimmableBeatmapBackgroundSprite sprite = (DimmableBeatmapBackgroundSprite)Sprite; sprite.DimLevel = dimLevel; - bufferedContainer?.ForceRedraw(); + BufferedContainer?.ForceRedraw(); } } - public Color4 DimColour { + public Color4 DimColour + { get => dimColour; - set { + set + { dimColour = value; DimmableBeatmapBackgroundSprite sprite = (DimmableBeatmapBackgroundSprite)Sprite; sprite.DimColour = dimColour; - bufferedContainer?.ForceRedraw(); + BufferedContainer?.ForceRedraw(); } } - public DimmableBeatmapBackground(WorkingBeatmap beatmap, string fallbackTextureName = @"Backgrounds/bg1") : base(beatmap, fallbackTextureName) { - Sprite = new DimmableBeatmapBackgroundSprite { + public DimmableBeatmapBackground(WorkingBeatmap beatmap, string fallbackTextureName = @"Backgrounds/bg1") : base(beatmap, fallbackTextureName) + { + Sprite = new DimmableBeatmapBackgroundSprite + { RelativeSizeAxes = Axes.Both, Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -59,21 +61,26 @@ public DimmableBeatmapBackground(WorkingBeatmap beatmap, string fallbackTextureN }; } - public partial class DimmableBeatmapBackgroundSprite : Sprite { + public partial class DimmableBeatmapBackgroundSprite : Sprite + { private float dimLevel; private Color4 dimColour; - public float DimLevel { + public float DimLevel + { get => dimLevel; - set { + set + { dimLevel = value; Invalidate(Invalidation.DrawNode); } } - public Color4 DimColour { + public Color4 DimColour + { get => dimColour; - set { + set + { dimColour = value; Invalidate(Invalidation.DrawNode); } @@ -87,7 +94,8 @@ private void load(ShaderManager shaders) protected override DrawNode CreateDrawNode() => new DimmableBeatmapBackgroundSpriteDrawNode(this); - public class DimmableBeatmapBackgroundSpriteDrawNode : SpriteDrawNode { + public class DimmableBeatmapBackgroundSpriteDrawNode : SpriteDrawNode + { public new DimmableBeatmapBackgroundSprite Source => (DimmableBeatmapBackgroundSprite)base.Source; public DimmableBeatmapBackgroundSpriteDrawNode(DimmableBeatmapBackgroundSprite source) @@ -95,8 +103,8 @@ public DimmableBeatmapBackgroundSpriteDrawNode(DimmableBeatmapBackgroundSprite s { } - private float DimLevel; - private Color4 DimColour; + private float dimLevel; + private Color4 dimColour; private IShader textureShader; @@ -104,22 +112,22 @@ public override void ApplyState() { base.ApplyState(); - DimLevel = Source.DimLevel; - DimColour = Source.DimColour; + dimLevel = Source.DimLevel; + dimColour = Source.DimColour; textureShader = Source.TextureShader; } private IUniformBuffer dimmableBeatmapBackgroundParametersBuffer; - private void BindParametersBuffer(IRenderer renderer) + private void bindParametersBuffer(IRenderer renderer) { dimmableBeatmapBackgroundParametersBuffer ??= renderer.CreateUniformBuffer(); dimmableBeatmapBackgroundParametersBuffer.Data = dimmableBeatmapBackgroundParametersBuffer.Data with { - DimColour = new Vector4(DimColour.R, DimColour.G, DimColour.B, DimColour.A), - DimLevel = DimLevel, + DimColour = new Vector4(dimColour.R, dimColour.G, dimColour.B, dimColour.A), + DimLevel = dimLevel, }; textureShader.BindUniformBlock("m_DimmableBeatmapBackgroundParameters", dimmableBeatmapBackgroundParametersBuffer); @@ -127,13 +135,13 @@ private void BindParametersBuffer(IRenderer renderer) protected override void Draw(IRenderer renderer) { - BindParametersBuffer(renderer); + bindParametersBuffer(renderer); base.Draw(renderer); } protected override void DrawOpaqueInterior(IRenderer renderer) { - BindParametersBuffer(renderer); + bindParametersBuffer(renderer); base.DrawOpaqueInterior(renderer); } diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index de77a1080fd1..ccb46221139a 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -202,7 +202,8 @@ protected override void LoadComplete() BlurAmount.ValueChanged += _ => UpdateVisuals(); StoryboardReplacesBackground.ValueChanged += _ => UpdateVisuals(); - if (background != null) { + if (background != null) + { background.DimLevel = DimLevel; background.DimColour = DimColour; } From 221ff9f138a9c643850e6c962905b79d083c1051 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Sat, 21 Sep 2024 14:45:19 +0300 Subject: [PATCH 16/47] Changed the way colour is reported in TestSceneUserDimBackgrounds.cs --- .../Background/TestSceneUserDimBackgrounds.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs index d8be57382f32..7ba556106aab 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs @@ -453,7 +453,22 @@ public FadeAccessibleBackground(WorkingBeatmap beatmap) private partial class TestDimmableBackground : BackgroundScreenBeatmap.DimmableBackground { - public Color4 CurrentColour => Content.Colour; + public Color4 CurrentColour + { + get + { + Color4 ContentColour = Content.Colour; + float DimLevel = DimmableBeatmapBackground.DimLevel; + Color4 DimColour = DimmableBeatmapBackground.DimColour; + + return new Color4( + ContentColour.R * (1 - DimLevel) + DimColour.R * DimLevel, + ContentColour.G * (1 - DimLevel) + DimColour.G * DimLevel, + ContentColour.B * (1 - DimLevel) + DimColour.B * DimLevel, + ContentColour.A + ); + } + } public float CurrentAlpha => Content.Alpha; public new float DimLevel => base.DimLevel; From 8b1264b1b8958fee4a1e77d502e6ea54d7700567 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Sat, 21 Sep 2024 16:31:13 +0300 Subject: [PATCH 17/47] Added DimColour to user settings in TestSceneUserDimBackgrounds.cs --- .../Visual/Background/TestSceneUserDimBackgrounds.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs index 7ba556106aab..8d1ed152a828 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs @@ -301,6 +301,7 @@ private void setupUserSettings() SelectedMods.Value = new[] { new OsuModNoFail() }; songSelect.DimLevel.Value = 0.7f; songSelect.BlurLevel.Value = 0.4f; + songSelect.DimColour.Value = 0.5f; }); } @@ -324,6 +325,7 @@ protected override BackgroundScreen CreateBackground() public readonly Bindable IgnoreUserSettings = new Bindable(); public readonly Bindable DimLevel = new BindableDouble(); public readonly Bindable BlurLevel = new BindableDouble(); + public readonly Bindable DimColour = new BindableDouble(); public new BeatmapCarousel Carousel => base.Carousel; @@ -332,6 +334,7 @@ private void load(OsuConfigManager config) { config.BindWith(OsuSetting.DimLevel, DimLevel); config.BindWith(OsuSetting.BlurLevel, BlurLevel); + config.BindWith(OsuSetting.DimColour, DimColour); } public bool IsBackgroundBlack() => background.CurrentColour == OsuColour.Gray(0); From 1d696ba90a977683d5512be2059e9ccf4cd2ee05 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Sat, 21 Sep 2024 16:58:11 +0300 Subject: [PATCH 18/47] Updated TestSceneUserDimBackgrounds.cs to test for colour offset caused by DimColour --- .../Background/TestSceneUserDimBackgrounds.cs | 57 +++++++++++++++---- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs index 8d1ed152a828..52629bb59ec6 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs @@ -101,10 +101,10 @@ public void TestPlayerLoaderSettingsHover() return songSelect.IsBackgroundCurrent(); }); - AddUntilStep("Screen is dimmed and blur applied", () => + AddUntilStep("Screen is dimmed, blur applied and dim colour adjusted", () => { InputManager.MoveMouseTo(playerLoader.VisualSettingsPos); - return songSelect.IsBackgroundDimmed() && songSelect.IsUserBlurApplied(); + return songSelect.IsBackgroundDimmed() && songSelect.IsUserBlurApplied() && songSelect.IsBackgroundColourOffset(); }); AddStep("Stop background preview", () => InputManager.MoveMouseTo(playerLoader.ScreenPos)); @@ -122,7 +122,7 @@ public void TestPlayerLoaderTransition() performFullSetup(); AddStep("Trigger hover event", () => playerLoader.TriggerOnHover()); AddAssert("Background retained from song select", () => songSelect.IsBackgroundCurrent()); - AddUntilStep("Screen is dimmed and blur applied", () => songSelect.IsBackgroundDimmed() && songSelect.IsUserBlurApplied()); + AddUntilStep("Screen is dimmed, blur applied and dim colour adjusted", () => songSelect.IsBackgroundDimmed() && songSelect.IsUserBlurApplied() && songSelect.IsBackgroundColourOffset()); } /// @@ -167,11 +167,11 @@ public void TestStoryboardTransition() public void TestDisableUserDimBackground() { performFullSetup(); - AddUntilStep("Screen is dimmed and blur applied", () => songSelect.IsBackgroundDimmed() && songSelect.IsUserBlurApplied()); + AddUntilStep("Screen is dimmed, blur applied and dim colour adjusted", () => songSelect.IsBackgroundDimmed() && songSelect.IsUserBlurApplied() && songSelect.IsBackgroundColourOffset()); AddStep("Disable user dim", () => songSelect.IgnoreUserSettings.Value = true); AddUntilStep("Screen is undimmed and user blur removed", () => songSelect.IsBackgroundUndimmed() && songSelect.IsUserBlurDisabled()); AddStep("Enable user dim", () => songSelect.IgnoreUserSettings.Value = false); - AddUntilStep("Screen is dimmed and blur applied", () => songSelect.IsBackgroundDimmed() && songSelect.IsUserBlurApplied()); + AddUntilStep("Screen is dimmed, blur applied and dim colour adjusted", () => songSelect.IsBackgroundDimmed() && songSelect.IsUserBlurApplied() && songSelect.IsBackgroundColourOffset()); } /// @@ -225,9 +225,9 @@ public void TestPause() { performFullSetup(true); AddStep("Pause", () => player.Pause()); - AddUntilStep("Screen is dimmed and blur applied", () => songSelect.IsBackgroundDimmed() && songSelect.IsUserBlurApplied()); + AddUntilStep("Screen is dimmed, blur applied and dim colour adjusted", () => songSelect.IsBackgroundDimmed() && songSelect.IsUserBlurApplied() && songSelect.IsBackgroundColourOffset()); AddStep("Unpause", () => player.Resume()); - AddUntilStep("Screen is dimmed and blur applied", () => songSelect.IsBackgroundDimmed() && songSelect.IsUserBlurApplied()); + AddUntilStep("Screen is dimmed, blur applied and dim colour adjusted", () => songSelect.IsBackgroundDimmed() && songSelect.IsUserBlurApplied() && songSelect.IsBackgroundColourOffset()); } /// @@ -260,7 +260,7 @@ public void TestResumeFromPlayer() playerLoader.VisualSettingsPos.ScreenSpaceDrawQuad.Height / 2 ))); AddStep("Resume PlayerLoader", () => player.Restart()); - AddUntilStep("Screen is dimmed and blur applied", () => songSelect.IsBackgroundDimmed() && songSelect.IsUserBlurApplied()); + AddUntilStep("Screen is dimmed, blur applied and dim colour adjusted", () => songSelect.IsBackgroundDimmed() && songSelect.IsUserBlurApplied() && songSelect.IsBackgroundColourOffset()); AddStep("Move mouse to center of screen", () => InputManager.MoveMouseTo(playerLoader.ScreenPos)); AddUntilStep("Screen is undimmed and user blur removed", () => songSelect.IsBackgroundUndimmed() && songSelect.CheckBackgroundBlur(playerLoader.ExpectedBackgroundBlur)); } @@ -343,6 +343,19 @@ private void load(OsuConfigManager config) public bool IsBackgroundUndimmed() => background.CurrentColour == Color4.White; + public bool IsBackgroundColourOffset() + { + Color4 CurrentDimColour = background.CurrentDimColour; + Color4 TargetColourOffset = new Color4( + CurrentDimColour.R * background.CurrentDim, + CurrentDimColour.G * background.CurrentDim, + CurrentDimColour.B * background.CurrentDim, + 1 + ); + + return background.CurrentColourOffset == TargetColourOffset; + } + public bool IsUserBlurApplied() => Precision.AlmostEquals(background.CurrentBlur, new Vector2((float)BlurLevel.Value * BackgroundScreenBeatmap.USER_BLUR_FACTOR), 0.1f); public bool IsUserBlurDisabled() => background.CurrentBlur == new Vector2(0); @@ -440,10 +453,14 @@ private partial class FadeAccessibleBackground : BackgroundScreenBeatmap public Color4 CurrentColour => dimmable.CurrentColour; + public Color4 CurrentColourOffset => dimmable.CurrentColourOffset; + public float CurrentAlpha => dimmable.CurrentAlpha; public float CurrentDim => dimmable.DimLevel; + public Color4 CurrentDimColour => dimmable.DimColour; + public Vector2 CurrentBlur => Background?.BlurSigma ?? Vector2.Zero; private TestDimmableBackground dimmable; @@ -462,19 +479,35 @@ public Color4 CurrentColour { Color4 ContentColour = Content.Colour; float DimLevel = DimmableBeatmapBackground.DimLevel; - Color4 DimColour = DimmableBeatmapBackground.DimColour; return new Color4( - ContentColour.R * (1 - DimLevel) + DimColour.R * DimLevel, - ContentColour.G * (1 - DimLevel) + DimColour.G * DimLevel, - ContentColour.B * (1 - DimLevel) + DimColour.B * DimLevel, + ContentColour.R * (1 - DimLevel), + ContentColour.G * (1 - DimLevel), + ContentColour.B * (1 - DimLevel), ContentColour.A ); } } + public Color4 CurrentColourOffset + { + get + { + float DimLevel = DimmableBeatmapBackground.DimLevel; + Color4 DimColour = DimmableBeatmapBackground.DimColour; + + return new Color4( + DimColour.R * DimLevel, + DimColour.G * DimLevel, + DimColour.B * DimLevel, + 1 + ); + } + } public float CurrentAlpha => Content.Alpha; public new float DimLevel => base.DimLevel; + + public new Color4 DimColour => base.DimColour; } } } From c99dd878363f28de7782564369bb19fb591f3909 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Sat, 21 Sep 2024 17:22:14 +0300 Subject: [PATCH 19/47] Handle IgnoreUserSettings for DimColour --- .../Screens/Backgrounds/BackgroundScreenBeatmap.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index ccb46221139a..49c905fd6276 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -220,7 +220,16 @@ protected override float DimLevel } } - protected virtual Color4 DimColour => OsuColour.Gray((float)userDimColour.Value); + protected virtual Color4 DimColour + { + get + { + if ((IgnoreUserSettings.Value || ShowStoryboard.Value) && StoryboardReplacesBackground.Value) + return Color4.Black; + + return OsuColour.Gray((float)userDimColour.Value); + } + } protected override void UpdateVisuals() { From b7531d1d7a35275603c0d0c211add0abaae1867b Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Sat, 21 Sep 2024 17:32:48 +0300 Subject: [PATCH 20/47] Updated the way TestSceneUserDimBackgrounds.cs checks if background is black --- osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs index 52629bb59ec6..3d9203bdfeea 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs @@ -337,7 +337,7 @@ private void load(OsuConfigManager config) config.BindWith(OsuSetting.DimColour, DimColour); } - public bool IsBackgroundBlack() => background.CurrentColour == OsuColour.Gray(0); + public bool IsBackgroundBlack() => background.CurrentColour == OsuColour.Gray(0) && background.CurrentColourOffset == OsuColour.Gray(0); public bool IsBackgroundDimmed() => background.CurrentColour == OsuColour.Gray(1f - background.CurrentDim); From e1b06d344312c6ca0f284aac2162b94a4c52eb79 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Sun, 22 Sep 2024 07:05:40 +0300 Subject: [PATCH 21/47] Integrated DimmableBeatmapBackground into BeatmapBackground --- .../Background/TestSceneUserDimBackgrounds.cs | 6 +- .../Graphics/Backgrounds/BeatmapBackground.cs | 152 ++++++++++++++++ .../Backgrounds/DimmableBeatmapBackground.cs | 164 ------------------ .../Backgrounds/BackgroundScreenBeatmap.cs | 20 +-- 4 files changed, 165 insertions(+), 177 deletions(-) delete mode 100644 osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs diff --git a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs index 3d9203bdfeea..c518261c200d 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs @@ -478,7 +478,7 @@ public Color4 CurrentColour get { Color4 ContentColour = Content.Colour; - float DimLevel = DimmableBeatmapBackground.DimLevel; + float DimLevel = BeatmapBackground.DimLevel; return new Color4( ContentColour.R * (1 - DimLevel), @@ -492,8 +492,8 @@ public Color4 CurrentColourOffset { get { - float DimLevel = DimmableBeatmapBackground.DimLevel; - Color4 DimColour = DimmableBeatmapBackground.DimColour; + float DimLevel = BeatmapBackground.DimLevel; + Color4 DimColour = BeatmapBackground.DimColour; return new Color4( DimColour.R * DimLevel, diff --git a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs index 685f03ae562d..d67242cb6598 100644 --- a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs +++ b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs @@ -3,22 +3,74 @@ #nullable disable + +using System.Runtime.InteropServices; using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Rendering; +using osu.Framework.Graphics.Shaders; +using osu.Framework.Graphics.Shaders.Types; +using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; using osu.Game.Beatmaps; +using osuTK; +using osuTK.Graphics; namespace osu.Game.Graphics.Backgrounds { + /// + /// A background which offers dimming using a custom shader with ability to change dim colour. + /// public partial class BeatmapBackground : Background { public readonly WorkingBeatmap Beatmap; private readonly string fallbackTextureName; + private float dimLevel; + private Color4 dimColour; + + public float DimLevel + { + get => dimLevel; + set + { + dimLevel = value; + BeatmapBackgroundSprite sprite = (BeatmapBackgroundSprite)Sprite; + sprite.DimLevel = dimLevel; + + BufferedContainer?.ForceRedraw(); + } + } + + public Color4 DimColour + { + get => dimColour; + set + { + dimColour = value; + BeatmapBackgroundSprite sprite = (BeatmapBackgroundSprite)Sprite; + sprite.DimColour = dimColour; + + BufferedContainer?.ForceRedraw(); + } + } + public BeatmapBackground(WorkingBeatmap beatmap, string fallbackTextureName = @"Backgrounds/bg1") { Beatmap = beatmap; this.fallbackTextureName = fallbackTextureName; + + Sprite = new BeatmapBackgroundSprite + { + RelativeSizeAxes = Axes.Both, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + FillMode = FillMode.Fill, + }; + + DimLevel = 0.0f; + DimColour = Color4.Black; } [BackgroundDependencyLoader] @@ -35,5 +87,105 @@ public override bool Equals(Background other) return other.GetType() == GetType() && ((BeatmapBackground)other).Beatmap == Beatmap; } + + public partial class BeatmapBackgroundSprite : Sprite + { + private float dimLevel; + private Color4 dimColour; + + public float DimLevel + { + get => dimLevel; + set + { + dimLevel = value; + Invalidate(Invalidation.DrawNode); + } + } + + public Color4 DimColour + { + get => dimColour; + set + { + dimColour = value; + Invalidate(Invalidation.DrawNode); + } + } + + [BackgroundDependencyLoader] + private void load(ShaderManager shaders) + { + TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "BeatmapBackground"); + } + + protected override DrawNode CreateDrawNode() => new BeatmapBackgroundSpriteDrawNode(this); + + public class BeatmapBackgroundSpriteDrawNode : SpriteDrawNode + { + public new BeatmapBackgroundSprite Source => (BeatmapBackgroundSprite)base.Source; + + public BeatmapBackgroundSpriteDrawNode(BeatmapBackgroundSprite source) + : base(source) + { + } + + private float dimLevel; + private Color4 dimColour; + + private IShader textureShader; + + public override void ApplyState() + { + base.ApplyState(); + + dimLevel = Source.DimLevel; + dimColour = Source.DimColour; + + textureShader = Source.TextureShader; + } + + private IUniformBuffer beatmapBackgroundParametersBuffer; + + private void bindParametersBuffer(IRenderer renderer) + { + beatmapBackgroundParametersBuffer ??= renderer.CreateUniformBuffer(); + + beatmapBackgroundParametersBuffer.Data = beatmapBackgroundParametersBuffer.Data with + { + DimColour = new Vector4(dimColour.R, dimColour.G, dimColour.B, dimColour.A), + DimLevel = dimLevel, + }; + + textureShader.BindUniformBlock("m_BeatmapBackgroundParameters", beatmapBackgroundParametersBuffer); + } + + protected override void Draw(IRenderer renderer) + { + bindParametersBuffer(renderer); + base.Draw(renderer); + } + + protected override void DrawOpaqueInterior(IRenderer renderer) + { + bindParametersBuffer(renderer); + base.DrawOpaqueInterior(renderer); + } + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + beatmapBackgroundParametersBuffer?.Dispose(); + } + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + private record struct BeatmapBackgroundParameters + { + public UniformVector4 DimColour; + public UniformFloat DimLevel; + private readonly UniformPadding12 pad1; + } + } + } } } diff --git a/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs b/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs deleted file mode 100644 index 5a260b05ce50..000000000000 --- a/osu.Game/Graphics/Backgrounds/DimmableBeatmapBackground.cs +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -#nullable disable - -using System.Runtime.InteropServices; -using osu.Framework.Allocation; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Rendering; -using osu.Framework.Graphics.Shaders; -using osu.Framework.Graphics.Shaders.Types; -using osu.Framework.Graphics.Sprites; -using osu.Game.Beatmaps; -using osuTK; -using osuTK.Graphics; - -namespace osu.Game.Graphics.Backgrounds -{ - /// - /// A background which offers dimming using a custom shader with ability to change dim colour. - /// - public partial class DimmableBeatmapBackground : BeatmapBackground - { - private float dimLevel; - private Color4 dimColour; - - public float DimLevel - { - get => dimLevel; - set - { - dimLevel = value; - DimmableBeatmapBackgroundSprite sprite = (DimmableBeatmapBackgroundSprite)Sprite; - sprite.DimLevel = dimLevel; - - BufferedContainer?.ForceRedraw(); - } - } - - public Color4 DimColour - { - get => dimColour; - set - { - dimColour = value; - DimmableBeatmapBackgroundSprite sprite = (DimmableBeatmapBackgroundSprite)Sprite; - sprite.DimColour = dimColour; - - BufferedContainer?.ForceRedraw(); - } - } - - public DimmableBeatmapBackground(WorkingBeatmap beatmap, string fallbackTextureName = @"Backgrounds/bg1") : base(beatmap, fallbackTextureName) - { - Sprite = new DimmableBeatmapBackgroundSprite - { - RelativeSizeAxes = Axes.Both, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - FillMode = FillMode.Fill, - }; - } - - public partial class DimmableBeatmapBackgroundSprite : Sprite - { - private float dimLevel; - private Color4 dimColour; - - public float DimLevel - { - get => dimLevel; - set - { - dimLevel = value; - Invalidate(Invalidation.DrawNode); - } - } - - public Color4 DimColour - { - get => dimColour; - set - { - dimColour = value; - Invalidate(Invalidation.DrawNode); - } - } - - [BackgroundDependencyLoader] - private void load(ShaderManager shaders) - { - TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "DimmableBeatmapBackground"); - } - - protected override DrawNode CreateDrawNode() => new DimmableBeatmapBackgroundSpriteDrawNode(this); - - public class DimmableBeatmapBackgroundSpriteDrawNode : SpriteDrawNode - { - public new DimmableBeatmapBackgroundSprite Source => (DimmableBeatmapBackgroundSprite)base.Source; - - public DimmableBeatmapBackgroundSpriteDrawNode(DimmableBeatmapBackgroundSprite source) - : base(source) - { - } - - private float dimLevel; - private Color4 dimColour; - - private IShader textureShader; - - public override void ApplyState() - { - base.ApplyState(); - - dimLevel = Source.DimLevel; - dimColour = Source.DimColour; - - textureShader = Source.TextureShader; - } - - private IUniformBuffer dimmableBeatmapBackgroundParametersBuffer; - - private void bindParametersBuffer(IRenderer renderer) - { - dimmableBeatmapBackgroundParametersBuffer ??= renderer.CreateUniformBuffer(); - - dimmableBeatmapBackgroundParametersBuffer.Data = dimmableBeatmapBackgroundParametersBuffer.Data with - { - DimColour = new Vector4(dimColour.R, dimColour.G, dimColour.B, dimColour.A), - DimLevel = dimLevel, - }; - - textureShader.BindUniformBlock("m_DimmableBeatmapBackgroundParameters", dimmableBeatmapBackgroundParametersBuffer); - } - - protected override void Draw(IRenderer renderer) - { - bindParametersBuffer(renderer); - base.Draw(renderer); - } - - protected override void DrawOpaqueInterior(IRenderer renderer) - { - bindParametersBuffer(renderer); - base.DrawOpaqueInterior(renderer); - } - - protected override void Dispose(bool isDisposing) - { - base.Dispose(isDisposing); - dimmableBeatmapBackgroundParametersBuffer?.Dispose(); - } - - [StructLayout(LayoutKind.Sequential, Pack = 1)] - private record struct DimmableBeatmapBackgroundParameters - { - public UniformVector4 DimColour; - public UniformFloat DimLevel; - private readonly UniformPadding12 pad1; - } - } - } - } -} diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 49c905fd6276..d6a8d32097d1 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -75,7 +75,7 @@ public BackgroundScreenBeatmap(WorkingBeatmap beatmap = null) [BackgroundDependencyLoader] private void load() { - var background = new DimmableBeatmapBackground(beatmap); + var background = new BeatmapBackground(beatmap); LoadComponent(background); switchBackground(background); } @@ -94,11 +94,11 @@ public WorkingBeatmap Beatmap Schedule(() => { - if ((Background as DimmableBeatmapBackground)?.Beatmap.BeatmapInfo.BackgroundEquals(beatmap?.BeatmapInfo) ?? false) + if ((Background as BeatmapBackground)?.Beatmap.BeatmapInfo.BackgroundEquals(beatmap?.BeatmapInfo) ?? false) return; cancellationSource?.Cancel(); - LoadComponentAsync(new DimmableBeatmapBackground(beatmap), switchBackground, (cancellationSource = new CancellationTokenSource()).Token); + LoadComponentAsync(new BeatmapBackground(beatmap), switchBackground, (cancellationSource = new CancellationTokenSource()).Token); }); } } @@ -111,11 +111,11 @@ public void RefreshBackground() Schedule(() => { cancellationSource?.Cancel(); - LoadComponentAsync(new DimmableBeatmapBackground(beatmap), switchBackground, (cancellationSource = new CancellationTokenSource()).Token); + LoadComponentAsync(new BeatmapBackground(beatmap), switchBackground, (cancellationSource = new CancellationTokenSource()).Token); }); } - private void switchBackground(DimmableBeatmapBackground b) + private void switchBackground(BeatmapBackground b) { float newDepth = 0; @@ -128,7 +128,7 @@ private void switchBackground(DimmableBeatmapBackground b) } b.Depth = newDepth; - Background = dimmable.DimmableBeatmapBackground = b; + Background = dimmable.BeatmapBackground = b; } public override bool Equals(BackgroundScreen other) @@ -152,7 +152,7 @@ public partial class DimmableBackground : UserDimContainer public Background Background => background; - public DimmableBeatmapBackground DimmableBeatmapBackground + public BeatmapBackground BeatmapBackground { get => background; set @@ -167,7 +167,7 @@ public DimmableBeatmapBackground DimmableBeatmapBackground private Bindable userBlurLevel { get; set; } private Bindable userDimColour { get; set; } - private DimmableBeatmapBackground background; + private BeatmapBackground background; public override void Add(Drawable drawable) { @@ -236,9 +236,9 @@ protected override void UpdateVisuals() ContentDisplayed = ShowDimContent; Content.FadeTo(ContentDisplayed ? 1 : 0, BACKGROUND_FADE_DURATION, Easing.OutQuint); - background?.TransformTo(nameof(DimmableBeatmapBackground.DimLevel), DimLevel, BACKGROUND_FADE_DURATION, Easing.OutQuint); + background?.TransformTo(nameof(BeatmapBackground.DimLevel), DimLevel, BACKGROUND_FADE_DURATION, Easing.OutQuint); - background?.TransformTo(nameof(DimmableBeatmapBackground.DimColour), DimColour, BACKGROUND_FADE_DURATION, Easing.OutQuint); + background?.TransformTo(nameof(BeatmapBackground.DimColour), DimColour, BACKGROUND_FADE_DURATION, Easing.OutQuint); Background?.BlurTo(blurTarget, BACKGROUND_FADE_DURATION, Easing.OutQuint); } From bab981e1b9c3cd368b2fc073a83e1804bab98c28 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Thu, 3 Oct 2024 20:50:21 +0300 Subject: [PATCH 22/47] Use existing methods to update shader variables --- .../Graphics/Backgrounds/BeatmapBackground.cs | 26 ++----------------- 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs index d67242cb6598..a5fe58d2eb86 100644 --- a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs +++ b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs @@ -133,21 +133,17 @@ public BeatmapBackgroundSpriteDrawNode(BeatmapBackgroundSprite source) private float dimLevel; private Color4 dimColour; - private IShader textureShader; - public override void ApplyState() { base.ApplyState(); dimLevel = Source.DimLevel; dimColour = Source.DimColour; - - textureShader = Source.TextureShader; } private IUniformBuffer beatmapBackgroundParametersBuffer; - private void bindParametersBuffer(IRenderer renderer) + protected override void BindUniformResources(IShader shader, IRenderer renderer) { beatmapBackgroundParametersBuffer ??= renderer.CreateUniformBuffer(); @@ -157,25 +153,7 @@ private void bindParametersBuffer(IRenderer renderer) DimLevel = dimLevel, }; - textureShader.BindUniformBlock("m_BeatmapBackgroundParameters", beatmapBackgroundParametersBuffer); - } - - protected override void Draw(IRenderer renderer) - { - bindParametersBuffer(renderer); - base.Draw(renderer); - } - - protected override void DrawOpaqueInterior(IRenderer renderer) - { - bindParametersBuffer(renderer); - base.DrawOpaqueInterior(renderer); - } - - protected override void Dispose(bool isDisposing) - { - base.Dispose(isDisposing); - beatmapBackgroundParametersBuffer?.Dispose(); + shader.BindUniformBlock("m_BeatmapBackgroundParameters", beatmapBackgroundParametersBuffer); } [StructLayout(LayoutKind.Sequential, Pack = 1)] From 8f95210beb7671da0d41c9dafbebc203120071d3 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Thu, 3 Oct 2024 21:37:38 +0300 Subject: [PATCH 23/47] Made background receive correct dim values when it's set --- osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index d6a8d32097d1..1303a31d0edd 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -160,6 +160,9 @@ public BeatmapBackground BeatmapBackground background?.Expire(); base.Add(background = value); + + background.DimLevel = DimLevel; + background.DimColour = DimColour; background.BlurTo(blurTarget, 0, Easing.OutQuint); } } From 3281b8881d625a1c2cd513b46583e723dc1d8a23 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Thu, 3 Oct 2024 21:46:31 +0300 Subject: [PATCH 24/47] Disable DimColour when user settings are ignored --- osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 1303a31d0edd..1fe082bace99 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -227,7 +227,7 @@ protected virtual Color4 DimColour { get { - if ((IgnoreUserSettings.Value || ShowStoryboard.Value) && StoryboardReplacesBackground.Value) + if (IgnoreUserSettings.Value || ShowStoryboard.Value && StoryboardReplacesBackground.Value) return Color4.Black; return OsuColour.Gray((float)userDimColour.Value); From d1fe76b62b9d03542af0e5f6ed39a6a09ccfe91d Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Wed, 9 Oct 2024 17:51:40 +0300 Subject: [PATCH 25/47] Made BufferedContainer handle dimming when it's present --- osu.Game/Graphics/Backgrounds/Background.cs | 4 +- .../Graphics/Backgrounds/BeatmapBackground.cs | 130 +++++++++++++++++- 2 files changed, 126 insertions(+), 8 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/Background.cs b/osu.Game/Graphics/Backgrounds/Background.cs index 259a868707e5..b94e0f273be8 100644 --- a/osu.Game/Graphics/Backgrounds/Background.cs +++ b/osu.Game/Graphics/Backgrounds/Background.cs @@ -42,7 +42,7 @@ protected set private readonly string textureName; - protected BufferedContainer BufferedContainer { get; private set; } + protected BufferedContainer BufferedContainer; public Background(string textureName = @"") { @@ -71,7 +71,7 @@ private void load(LargeTextureStore textures) /// Smoothly adjusts over time. /// /// A to which further transforms can be added. - public void BlurTo(Vector2 newBlurSigma, double duration = 0, Easing easing = Easing.None) + public virtual void BlurTo(Vector2 newBlurSigma, double duration = 0, Easing easing = Easing.None) { if (BufferedContainer == null && newBlurSigma != Vector2.Zero) { diff --git a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs index a5fe58d2eb86..38bc98d81040 100644 --- a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs +++ b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs @@ -7,6 +7,7 @@ using System.Runtime.InteropServices; using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Rendering; using osu.Framework.Graphics.Shaders; using osu.Framework.Graphics.Shaders.Types; @@ -36,10 +37,15 @@ public float DimLevel set { dimLevel = value; - BeatmapBackgroundSprite sprite = (BeatmapBackgroundSprite)Sprite; - sprite.DimLevel = dimLevel; - BufferedContainer?.ForceRedraw(); + if (BufferedContainer == null) + { + (Sprite as BeatmapBackgroundSprite).DimLevel = dimLevel; + } + else + { + (BufferedContainer as DimmableBufferedContainer).DimLevel = dimLevel; + } } } @@ -49,10 +55,15 @@ public Color4 DimColour set { dimColour = value; - BeatmapBackgroundSprite sprite = (BeatmapBackgroundSprite)Sprite; - sprite.DimColour = dimColour; - BufferedContainer?.ForceRedraw(); + if (BufferedContainer == null) + { + (Sprite as BeatmapBackgroundSprite).DimColour = dimColour; + } + else + { + (BufferedContainer as DimmableBufferedContainer).DimColour = dimColour; + } } } @@ -88,6 +99,113 @@ public override bool Equals(Background other) && ((BeatmapBackground)other).Beatmap == Beatmap; } + public override void BlurTo(Vector2 newBlurSigma, double duration = 0, Easing easing = Easing.None) + { + if (BufferedContainer == null && newBlurSigma != Vector2.Zero) + { + RemoveInternal(Sprite, false); + + BeatmapBackgroundSprite sprite = (BeatmapBackgroundSprite)Sprite; + sprite.DimColour = Color4.Black; + sprite.DimLevel = 0.0f; + + AddInternal(BufferedContainer = new DimmableBufferedContainer(cachedFrameBuffer: true) + { + RelativeSizeAxes = Axes.Both, + RedrawOnScale = false, + Child = Sprite, + DimColour = DimColour, + DimLevel = DimLevel + }); + } + base.BlurTo(newBlurSigma, duration, easing); + } + + public partial class DimmableBufferedContainer : BufferedContainer + { + private float dimLevel; + private Color4 dimColour; + + public float DimLevel + { + get => dimLevel; + set + { + dimLevel = value; + Invalidate(Invalidation.DrawNode); + } + } + + public Color4 DimColour + { + get => dimColour; + set + { + dimColour = value; + Invalidate(Invalidation.DrawNode); + } + } + + public DimmableBufferedContainer(RenderBufferFormat[] formats = null, bool pixelSnapping = false, bool cachedFrameBuffer = false) + : base(formats, pixelSnapping, cachedFrameBuffer) + { + DimLevel = 0.0f; + DimColour = Color4.Black; + } + + [BackgroundDependencyLoader] + private void load(ShaderManager shaders) + { + TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "BeatmapBackground"); + } + + protected override DrawNode CreateDrawNode() => new DimmableBufferedContainerDrawNode(this, SharedData); + + protected class DimmableBufferedContainerDrawNode : BufferedContainerDrawNode + { + public new DimmableBufferedContainer Source => (DimmableBufferedContainer)base.Source; + + public DimmableBufferedContainerDrawNode(DimmableBufferedContainer source, BufferedContainerDrawNodeSharedData sharedData) + : base(source, sharedData) + { + } + + private float dimLevel; + private Color4 dimColour; + + public override void ApplyState() + { + base.ApplyState(); + + dimLevel = Source.DimLevel; + dimColour = Source.DimColour; + } + + private IUniformBuffer beatmapBackgroundParametersBuffer; + + protected override void BindUniformResources(IShader shader, IRenderer renderer) + { + beatmapBackgroundParametersBuffer ??= renderer.CreateUniformBuffer(); + + beatmapBackgroundParametersBuffer.Data = beatmapBackgroundParametersBuffer.Data with + { + DimColour = new Vector4(dimColour.R, dimColour.G, dimColour.B, dimColour.A), + DimLevel = dimLevel, + }; + + shader.BindUniformBlock("m_BeatmapBackgroundParameters", beatmapBackgroundParametersBuffer); + } + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + private record struct BeatmapBackgroundParameters + { + public UniformVector4 DimColour; + public UniformFloat DimLevel; + private readonly UniformPadding12 pad1; + } + } + } + public partial class BeatmapBackgroundSprite : Sprite { private float dimLevel; From 20c26197db514e3d50ba64b7b1b5a6e90c021333 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Wed, 9 Oct 2024 18:17:23 +0300 Subject: [PATCH 26/47] Added default values for BeatmapBackgroundSprite --- osu.Game/Graphics/Backgrounds/BeatmapBackground.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs index 38bc98d81040..d24f64128819 100644 --- a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs +++ b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs @@ -231,6 +231,13 @@ public Color4 DimColour } } + public BeatmapBackgroundSprite() + : base() + { + DimLevel = 0.0f; + DimColour = Color4.Black; + } + [BackgroundDependencyLoader] private void load(ShaderManager shaders) { From eaa1476cd0d26dc44d064186444adc15dd6a8ca9 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Sun, 13 Oct 2024 21:24:14 +0300 Subject: [PATCH 27/47] Added explanations on why and how colour is split into two components --- .../Background/TestSceneUserDimBackgrounds.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs index c518261c200d..bb8781829e91 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs @@ -473,6 +473,20 @@ public FadeAccessibleBackground(WorkingBeatmap beatmap) private partial class TestDimmableBackground : BackgroundScreenBeatmap.DimmableBackground { + // BeatmapBackground shader uses mix function to apply dimming with colour, which can be extended as: + // mix(TextureColour, DimColour, DimLevel) = TextureColour * (1 - DimLevel) + DimColour * DimLevel + // The result is then multiplied by vertex colour (supplied by DrawColourInfo.Colour), + // which can apply some external dimming that shouldn't be affected by DimColour + // (for example - opening settings during replay, pausing, etc.): + // FinalColour = DrawColourInfo.Colour * mix(TextureColour, DimColour, DimLevel) + // FinalColour = DrawColourInfo.Colour * TextureColour * (1 - DimLevel) + DrawColourInfo.Colour * DimColour * DimLevel + // + // These two parts can be split into separate variables: + // CurrentColour = DrawColourInfo.Colour * TextureColour * (1 - DimLevel) + // CurrentColourOffset = DrawColourInfo.Colour * DimColour * DimLevel + // + // CurrentColour can be used to track how much the texture was dimmed, and + // CurrentColourOffset can be used to track how much brightness was added to resulting colour. public Color4 CurrentColour { get From e73efd787da1e605bacf05876f783abdfc51dfb3 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Sun, 13 Oct 2024 23:42:40 +0300 Subject: [PATCH 28/47] Updated the way colours are computed and checked in TestSceneUserDimBackgrounds --- .../Background/TestSceneUserDimBackgrounds.cs | 51 ++++++++++++++----- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs index bb8781829e91..113f28e9b738 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs @@ -339,17 +339,29 @@ private void load(OsuConfigManager config) public bool IsBackgroundBlack() => background.CurrentColour == OsuColour.Gray(0) && background.CurrentColourOffset == OsuColour.Gray(0); - public bool IsBackgroundDimmed() => background.CurrentColour == OsuColour.Gray(1f - background.CurrentDim); + public bool IsBackgroundDimmed() + { + Color4 ContentDrawColour = background.ContentDrawColour; + Color4 TargetColour = new Color4( + ContentDrawColour.R * (1f - background.CurrentDim), + ContentDrawColour.G * (1f - background.CurrentDim), + ContentDrawColour.B * (1f - background.CurrentDim), + ContentDrawColour.A + ); - public bool IsBackgroundUndimmed() => background.CurrentColour == Color4.White; + return background.CurrentColour == TargetColour; + } + + public bool IsBackgroundUndimmed() => background.CurrentColour == background.ParentDrawColour && background.CurrentColourOffset == Color4.Black; public bool IsBackgroundColourOffset() { Color4 CurrentDimColour = background.CurrentDimColour; + Color4 ContentDrawColour = background.ContentDrawColour; Color4 TargetColourOffset = new Color4( - CurrentDimColour.R * background.CurrentDim, - CurrentDimColour.G * background.CurrentDim, - CurrentDimColour.B * background.CurrentDim, + ContentDrawColour.R * CurrentDimColour.R * background.CurrentDim, + ContentDrawColour.G * CurrentDimColour.G * background.CurrentDim, + ContentDrawColour.B * CurrentDimColour.B * background.CurrentDim, 1 ); @@ -455,6 +467,10 @@ private partial class FadeAccessibleBackground : BackgroundScreenBeatmap public Color4 CurrentColourOffset => dimmable.CurrentColourOffset; + public Color4 ContentDrawColour => dimmable.ContentDrawColour; + + public Color4 ParentDrawColour => dimmable.ParentDrawColour; + public float CurrentAlpha => dimmable.CurrentAlpha; public float CurrentDim => dimmable.DimLevel; @@ -491,32 +507,39 @@ public Color4 CurrentColour { get { - Color4 ContentColour = Content.Colour; float DimLevel = BeatmapBackground.DimLevel; + Color4 BeatmapBackgroundDrawColour = BeatmapBackground.DrawColourInfo.Colour; return new Color4( - ContentColour.R * (1 - DimLevel), - ContentColour.G * (1 - DimLevel), - ContentColour.B * (1 - DimLevel), - ContentColour.A + BeatmapBackgroundDrawColour.R * (1 - DimLevel), + BeatmapBackgroundDrawColour.G * (1 - DimLevel), + BeatmapBackgroundDrawColour.B * (1 - DimLevel), + BeatmapBackgroundDrawColour.A ); } } + public Color4 CurrentColourOffset { get { float DimLevel = BeatmapBackground.DimLevel; Color4 DimColour = BeatmapBackground.DimColour; + Color4 BeatmapBackgroundDrawColour = BeatmapBackground.DrawColourInfo.Colour; return new Color4( - DimColour.R * DimLevel, - DimColour.G * DimLevel, - DimColour.B * DimLevel, - 1 + BeatmapBackgroundDrawColour.R * DimColour.R * DimLevel, + BeatmapBackgroundDrawColour.G * DimColour.G * DimLevel, + BeatmapBackgroundDrawColour.B * DimColour.B * DimLevel, + BeatmapBackgroundDrawColour.A ); } } + + public Color4 ContentDrawColour => Content.DrawColourInfo.Colour; + + public Color4 ParentDrawColour => Content.Parent.DrawColourInfo.Colour; + public float CurrentAlpha => Content.Alpha; public new float DimLevel => base.DimLevel; From b62a044a54e7a485ec05000d2cd482ef2e90d577 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Mon, 14 Oct 2024 01:08:29 +0300 Subject: [PATCH 29/47] Added forgotten Dispose's --- osu.Game/Graphics/Backgrounds/Background.cs | 1 + osu.Game/Graphics/Backgrounds/BeatmapBackground.cs | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/osu.Game/Graphics/Backgrounds/Background.cs b/osu.Game/Graphics/Backgrounds/Background.cs index b94e0f273be8..6ca77f519101 100644 --- a/osu.Game/Graphics/Backgrounds/Background.cs +++ b/osu.Game/Graphics/Backgrounds/Background.cs @@ -35,6 +35,7 @@ protected set } else { + sprite?.Dispose(); BufferedContainer.Child = sprite = value; } } diff --git a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs index d24f64128819..c5708867848c 100644 --- a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs +++ b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs @@ -196,6 +196,12 @@ protected override void BindUniformResources(IShader shader, IRenderer renderer) shader.BindUniformBlock("m_BeatmapBackgroundParameters", beatmapBackgroundParametersBuffer); } + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + beatmapBackgroundParametersBuffer?.Dispose(); + } + [StructLayout(LayoutKind.Sequential, Pack = 1)] private record struct BeatmapBackgroundParameters { @@ -281,6 +287,12 @@ protected override void BindUniformResources(IShader shader, IRenderer renderer) shader.BindUniformBlock("m_BeatmapBackgroundParameters", beatmapBackgroundParametersBuffer); } + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + beatmapBackgroundParametersBuffer?.Dispose(); + } + [StructLayout(LayoutKind.Sequential, Pack = 1)] private record struct BeatmapBackgroundParameters { From 983243f196d0a44dae316b5d604bc5df539f620e Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Mon, 14 Oct 2024 01:34:42 +0300 Subject: [PATCH 30/47] Moved BeatmapBackground creation into a virtual function to help with testing --- osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 1fe082bace99..34fc9228b849 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -72,10 +72,12 @@ public BackgroundScreenBeatmap(WorkingBeatmap beatmap = null) dimmable.DimWhenUserSettingsIgnored.BindTo(DimWhenUserSettingsIgnored); } + protected virtual BeatmapBackground CreateBeatmapBackground(WorkingBeatmap beatmap) => new BeatmapBackground(beatmap); + [BackgroundDependencyLoader] private void load() { - var background = new BeatmapBackground(beatmap); + var background = CreateBeatmapBackground(beatmap); LoadComponent(background); switchBackground(background); } @@ -98,7 +100,7 @@ public WorkingBeatmap Beatmap return; cancellationSource?.Cancel(); - LoadComponentAsync(new BeatmapBackground(beatmap), switchBackground, (cancellationSource = new CancellationTokenSource()).Token); + LoadComponentAsync(CreateBeatmapBackground(beatmap), switchBackground, (cancellationSource = new CancellationTokenSource()).Token); }); } } @@ -111,7 +113,7 @@ public void RefreshBackground() Schedule(() => { cancellationSource?.Cancel(); - LoadComponentAsync(new BeatmapBackground(beatmap), switchBackground, (cancellationSource = new CancellationTokenSource()).Token); + LoadComponentAsync(CreateBeatmapBackground(beatmap), switchBackground, (cancellationSource = new CancellationTokenSource()).Token); }); } From 892bd410632fba73fd321c6dd8bc0f8e7f4cb6b2 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Mon, 14 Oct 2024 19:45:05 +0300 Subject: [PATCH 31/47] Created TestBeatmapBackground class and moved colour computations into it --- .../Background/TestSceneUserDimBackgrounds.cs | 68 ++++++++++++------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs index 113f28e9b738..12e3a7dfff22 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs @@ -20,6 +20,7 @@ using osu.Game.Configuration; using osu.Game.Database; using osu.Game.Graphics; +using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; using osu.Game.Rulesets; @@ -463,9 +464,11 @@ private partial class FadeAccessibleBackground : BackgroundScreenBeatmap { protected override DimmableBackground CreateFadeContainer() => dimmable = new TestDimmableBackground { RelativeSizeAxes = Axes.Both }; - public Color4 CurrentColour => dimmable.CurrentColour; + protected override BeatmapBackground CreateBeatmapBackground(WorkingBeatmap beatmap) => beatmapBackground = new TestBeatmapBackground(beatmap); - public Color4 CurrentColourOffset => dimmable.CurrentColourOffset; + public Color4 CurrentColour => beatmapBackground.CurrentColour; + + public Color4 CurrentColourOffset => beatmapBackground.CurrentColourOffset; public Color4 ContentDrawColour => dimmable.ContentDrawColour; @@ -481,6 +484,8 @@ private partial class FadeAccessibleBackground : BackgroundScreenBeatmap private TestDimmableBackground dimmable; + private TestBeatmapBackground beatmapBackground; + public FadeAccessibleBackground(WorkingBeatmap beatmap) : base(beatmap) { @@ -489,6 +494,25 @@ public FadeAccessibleBackground(WorkingBeatmap beatmap) private partial class TestDimmableBackground : BackgroundScreenBeatmap.DimmableBackground { + public Color4 ContentDrawColour => Content.DrawColourInfo.Colour; + + public Color4 ParentDrawColour => Content.Parent.DrawColourInfo.Colour; + + public float CurrentAlpha => Content.Alpha; + + public new float DimLevel => base.DimLevel; + + public new Color4 DimColour => base.DimColour; + } + + private partial class TestBeatmapBackground : BeatmapBackground + { + public TestBeatmapBackground(WorkingBeatmap beatmap) + : base(beatmap) + { + + } + // BeatmapBackground shader uses mix function to apply dimming with colour, which can be extended as: // mix(TextureColour, DimColour, DimLevel) = TextureColour * (1 - DimLevel) + DimColour * DimLevel // The result is then multiplied by vertex colour (supplied by DrawColourInfo.Colour), @@ -502,19 +526,23 @@ private partial class TestDimmableBackground : BackgroundScreenBeatmap.DimmableB // CurrentColourOffset = DrawColourInfo.Colour * DimColour * DimLevel // // CurrentColour can be used to track how much the texture was dimmed, and - // CurrentColourOffset can be used to track how much brightness was added to resulting colour. + // CurrentColourOffset can be used to track how much colour was added as an offset. + // + // Two separate variables are needed because just one Colour variable would be ambiguous, for example: + // if Colour == Color4.White, that could mean either that + // DimLevel == 0.0, or + // DimLevel == 1.0 and DimColour == Color4.White. public Color4 CurrentColour { get { - float DimLevel = BeatmapBackground.DimLevel; - Color4 BeatmapBackgroundDrawColour = BeatmapBackground.DrawColourInfo.Colour; + Color4 DrawColour = DrawColourInfo.Colour; return new Color4( - BeatmapBackgroundDrawColour.R * (1 - DimLevel), - BeatmapBackgroundDrawColour.G * (1 - DimLevel), - BeatmapBackgroundDrawColour.B * (1 - DimLevel), - BeatmapBackgroundDrawColour.A + DrawColour.R * (1 - DimLevel), + DrawColour.G * (1 - DimLevel), + DrawColour.B * (1 - DimLevel), + DrawColour.A ); } } @@ -523,28 +551,16 @@ public Color4 CurrentColourOffset { get { - float DimLevel = BeatmapBackground.DimLevel; - Color4 DimColour = BeatmapBackground.DimColour; - Color4 BeatmapBackgroundDrawColour = BeatmapBackground.DrawColourInfo.Colour; + Color4 DrawColour = DrawColourInfo.Colour; return new Color4( - BeatmapBackgroundDrawColour.R * DimColour.R * DimLevel, - BeatmapBackgroundDrawColour.G * DimColour.G * DimLevel, - BeatmapBackgroundDrawColour.B * DimColour.B * DimLevel, - BeatmapBackgroundDrawColour.A + DrawColour.R * DimColour.R * DimLevel, + DrawColour.G * DimColour.G * DimLevel, + DrawColour.B * DimColour.B * DimLevel, + DrawColour.A ); } } - - public Color4 ContentDrawColour => Content.DrawColourInfo.Colour; - - public Color4 ParentDrawColour => Content.Parent.DrawColourInfo.Colour; - - public float CurrentAlpha => Content.Alpha; - - public new float DimLevel => base.DimLevel; - - public new Color4 DimColour => base.DimColour; } } } From 20c1141c0d01e325e16ed29e10d2d90de65531dd Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Mon, 14 Oct 2024 20:24:14 +0300 Subject: [PATCH 32/47] Added an interface to simplify access to current dimmable object in BeatmapBackground --- .../Graphics/Backgrounds/BeatmapBackground.cs | 41 ++++++------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs index c5708867848c..3f9a8b4da988 100644 --- a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs +++ b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs @@ -34,39 +34,17 @@ public partial class BeatmapBackground : Background public float DimLevel { get => dimLevel; - set - { - dimLevel = value; - - if (BufferedContainer == null) - { - (Sprite as BeatmapBackgroundSprite).DimLevel = dimLevel; - } - else - { - (BufferedContainer as DimmableBufferedContainer).DimLevel = dimLevel; - } - } + set => ColouredDimmable.DimLevel = dimLevel = value; } public Color4 DimColour { get => dimColour; - set - { - dimColour = value; - - if (BufferedContainer == null) - { - (Sprite as BeatmapBackgroundSprite).DimColour = dimColour; - } - else - { - (BufferedContainer as DimmableBufferedContainer).DimColour = dimColour; - } - } + set => ColouredDimmable.DimColour = dimColour = value; } + protected IColouredDimmable ColouredDimmable => BufferedContainer != null ? (BufferedContainer as DimmableBufferedContainer) : (Sprite as BeatmapBackgroundSprite); + public BeatmapBackground(WorkingBeatmap beatmap, string fallbackTextureName = @"Backgrounds/bg1") { Beatmap = beatmap; @@ -121,7 +99,14 @@ public override void BlurTo(Vector2 newBlurSigma, double duration = 0, Easing ea base.BlurTo(newBlurSigma, duration, easing); } - public partial class DimmableBufferedContainer : BufferedContainer + public interface IColouredDimmable : IDrawable + { + float DimLevel { get; set; } + + Color4 DimColour { get; set; } + } + + public partial class DimmableBufferedContainer : BufferedContainer, IColouredDimmable { private float dimLevel; private Color4 dimColour; @@ -212,7 +197,7 @@ private record struct BeatmapBackgroundParameters } } - public partial class BeatmapBackgroundSprite : Sprite + public partial class BeatmapBackgroundSprite : Sprite, IColouredDimmable { private float dimLevel; private Color4 dimColour; From cf88f97118b2f8352248a90365c1e31a49cb33a5 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Mon, 14 Oct 2024 21:04:13 +0300 Subject: [PATCH 33/47] Formatting fixes --- .../Graphics/Backgrounds/BeatmapBackground.cs | 63 ++++++++++--------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs index 3f9a8b4da988..5712cd77c651 100644 --- a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs +++ b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs @@ -28,14 +28,9 @@ public partial class BeatmapBackground : Background private readonly string fallbackTextureName; - private float dimLevel; private Color4 dimColour; - public float DimLevel - { - get => dimLevel; - set => ColouredDimmable.DimLevel = dimLevel = value; - } + private float dimLevel; public Color4 DimColour { @@ -43,6 +38,12 @@ public Color4 DimColour set => ColouredDimmable.DimColour = dimColour = value; } + public float DimLevel + { + get => dimLevel; + set => ColouredDimmable.DimLevel = dimLevel = value; + } + protected IColouredDimmable ColouredDimmable => BufferedContainer != null ? (BufferedContainer as DimmableBufferedContainer) : (Sprite as BeatmapBackgroundSprite); public BeatmapBackground(WorkingBeatmap beatmap, string fallbackTextureName = @"Backgrounds/bg1") @@ -58,8 +59,8 @@ public BeatmapBackground(WorkingBeatmap beatmap, string fallbackTextureName = @" FillMode = FillMode.Fill, }; - DimLevel = 0.0f; DimColour = Color4.Black; + DimLevel = 0.0f; } [BackgroundDependencyLoader] @@ -101,32 +102,33 @@ public override void BlurTo(Vector2 newBlurSigma, double duration = 0, Easing ea public interface IColouredDimmable : IDrawable { - float DimLevel { get; set; } - Color4 DimColour { get; set; } + + float DimLevel { get; set; } } public partial class DimmableBufferedContainer : BufferedContainer, IColouredDimmable { - private float dimLevel; private Color4 dimColour; - public float DimLevel + private float dimLevel; + + public Color4 DimColour { - get => dimLevel; + get => dimColour; set { - dimLevel = value; + dimColour = value; Invalidate(Invalidation.DrawNode); } } - public Color4 DimColour + public float DimLevel { - get => dimColour; + get => dimLevel; set { - dimColour = value; + dimLevel = value; Invalidate(Invalidation.DrawNode); } } @@ -134,8 +136,8 @@ public Color4 DimColour public DimmableBufferedContainer(RenderBufferFormat[] formats = null, bool pixelSnapping = false, bool cachedFrameBuffer = false) : base(formats, pixelSnapping, cachedFrameBuffer) { - DimLevel = 0.0f; DimColour = Color4.Black; + DimLevel = 0.0f; } [BackgroundDependencyLoader] @@ -155,15 +157,16 @@ public DimmableBufferedContainerDrawNode(DimmableBufferedContainer source, Buffe { } - private float dimLevel; private Color4 dimColour; + private float dimLevel; + public override void ApplyState() { base.ApplyState(); - dimLevel = Source.DimLevel; dimColour = Source.DimColour; + dimLevel = Source.DimLevel; } private IUniformBuffer beatmapBackgroundParametersBuffer; @@ -199,25 +202,26 @@ private record struct BeatmapBackgroundParameters public partial class BeatmapBackgroundSprite : Sprite, IColouredDimmable { - private float dimLevel; private Color4 dimColour; - public float DimLevel + private float dimLevel; + + public Color4 DimColour { - get => dimLevel; + get => dimColour; set { - dimLevel = value; + dimColour = value; Invalidate(Invalidation.DrawNode); } } - public Color4 DimColour + public float DimLevel { - get => dimColour; + get => dimLevel; set { - dimColour = value; + dimLevel = value; Invalidate(Invalidation.DrawNode); } } @@ -225,8 +229,8 @@ public Color4 DimColour public BeatmapBackgroundSprite() : base() { - DimLevel = 0.0f; DimColour = Color4.Black; + DimLevel = 0.0f; } [BackgroundDependencyLoader] @@ -246,15 +250,16 @@ public BeatmapBackgroundSpriteDrawNode(BeatmapBackgroundSprite source) { } - private float dimLevel; private Color4 dimColour; + private float dimLevel; + public override void ApplyState() { base.ApplyState(); - dimLevel = Source.DimLevel; dimColour = Source.DimColour; + dimLevel = Source.DimLevel; } private IUniformBuffer beatmapBackgroundParametersBuffer; From eada1209960468fae072553f2270d2087153b1bb Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Mon, 14 Oct 2024 21:30:43 +0300 Subject: [PATCH 34/47] Get DrawColour directly from object drawing the BG in TestSceneUserDimBackgrounds --- .../Visual/Background/TestSceneUserDimBackgrounds.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs index 12e3a7dfff22..9dae6a1d1bfc 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs @@ -470,7 +470,7 @@ private partial class FadeAccessibleBackground : BackgroundScreenBeatmap public Color4 CurrentColourOffset => beatmapBackground.CurrentColourOffset; - public Color4 ContentDrawColour => dimmable.ContentDrawColour; + public Color4 ContentDrawColour => beatmapBackground.ContentDrawColour; public Color4 ParentDrawColour => dimmable.ParentDrawColour; @@ -494,8 +494,6 @@ public FadeAccessibleBackground(WorkingBeatmap beatmap) private partial class TestDimmableBackground : BackgroundScreenBeatmap.DimmableBackground { - public Color4 ContentDrawColour => Content.DrawColourInfo.Colour; - public Color4 ParentDrawColour => Content.Parent.DrawColourInfo.Colour; public float CurrentAlpha => Content.Alpha; @@ -561,6 +559,8 @@ public Color4 CurrentColourOffset ); } } + + public Color4 ContentDrawColour => ColouredDimmable.DrawColourInfo.Colour; } } } From a4a43a94c82ae62bd683629677cc01e2c09d0ba1 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Mon, 14 Oct 2024 21:43:20 +0300 Subject: [PATCH 35/47] Changed the way Background.Sprite is replaced by BeatmapBackground --- osu.Game/Graphics/Backgrounds/Background.cs | 37 +++++-------------- .../Graphics/Backgrounds/BeatmapBackground.cs | 25 +++++++------ 2 files changed, 23 insertions(+), 39 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/Background.cs b/osu.Game/Graphics/Backgrounds/Background.cs index 6ca77f519101..7c074eda047b 100644 --- a/osu.Game/Graphics/Backgrounds/Background.cs +++ b/osu.Game/Graphics/Backgrounds/Background.cs @@ -20,26 +20,7 @@ namespace osu.Game.Graphics.Backgrounds /// public partial class Background : CompositeDrawable, IEquatable { - private Sprite sprite; - - public Sprite Sprite - { - get => sprite; - protected set - { - if (BufferedContainer == null) - { - if (sprite != null) - RemoveInternal(sprite, true); - AddInternal(sprite = value); - } - else - { - sprite?.Dispose(); - BufferedContainer.Child = sprite = value; - } - } - } + public readonly Sprite Sprite; private readonly string textureName; @@ -50,13 +31,7 @@ public Background(string textureName = @"") this.textureName = textureName; RelativeSizeAxes = Axes.Both; - Sprite = new Sprite - { - RelativeSizeAxes = Axes.Both, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - FillMode = FillMode.Fill, - }; + AddInternal(Sprite = CreateSprite()); } [BackgroundDependencyLoader] @@ -66,6 +41,14 @@ private void load(LargeTextureStore textures) Sprite.Texture = textures.Get(textureName); } + protected virtual Sprite CreateSprite() => new Sprite + { + RelativeSizeAxes = Axes.Both, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + FillMode = FillMode.Fill, + }; + public Vector2 BlurSigma => Vector2.Divide(BufferedContainer?.BlurSigma ?? Vector2.Zero, blurScale); /// diff --git a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs index 5712cd77c651..23e26030bb73 100644 --- a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs +++ b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs @@ -28,6 +28,8 @@ public partial class BeatmapBackground : Background private readonly string fallbackTextureName; + protected BeatmapBackgroundSprite ColouredDimmableSprite { get; private set; } + private Color4 dimColour; private float dimLevel; @@ -44,21 +46,13 @@ public float DimLevel set => ColouredDimmable.DimLevel = dimLevel = value; } - protected IColouredDimmable ColouredDimmable => BufferedContainer != null ? (BufferedContainer as DimmableBufferedContainer) : (Sprite as BeatmapBackgroundSprite); + protected IColouredDimmable ColouredDimmable => BufferedContainer != null ? (BufferedContainer as DimmableBufferedContainer) : ColouredDimmableSprite; public BeatmapBackground(WorkingBeatmap beatmap, string fallbackTextureName = @"Backgrounds/bg1") { Beatmap = beatmap; this.fallbackTextureName = fallbackTextureName; - Sprite = new BeatmapBackgroundSprite - { - RelativeSizeAxes = Axes.Both, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - FillMode = FillMode.Fill, - }; - DimColour = Color4.Black; DimLevel = 0.0f; } @@ -69,6 +63,14 @@ private void load(LargeTextureStore textures) Sprite.Texture = Beatmap?.GetBackground() ?? textures.Get(fallbackTextureName); } + protected override Sprite CreateSprite() => ColouredDimmableSprite = new BeatmapBackgroundSprite + { + RelativeSizeAxes = Axes.Both, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + FillMode = FillMode.Fill, + }; + public override bool Equals(Background other) { if (ReferenceEquals(null, other)) return false; @@ -84,9 +86,8 @@ public override void BlurTo(Vector2 newBlurSigma, double duration = 0, Easing ea { RemoveInternal(Sprite, false); - BeatmapBackgroundSprite sprite = (BeatmapBackgroundSprite)Sprite; - sprite.DimColour = Color4.Black; - sprite.DimLevel = 0.0f; + ColouredDimmableSprite.DimColour = Color4.Black; + ColouredDimmableSprite.DimLevel = 0.0f; AddInternal(BufferedContainer = new DimmableBufferedContainer(cachedFrameBuffer: true) { From 031249053612c68b28dbed82ad18fcabc0343b8a Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Mon, 14 Oct 2024 22:43:45 +0300 Subject: [PATCH 36/47] Changed the way Background.bufferedContainer is replaced by BeatmapBackground --- osu.Game/Graphics/Backgrounds/Background.cs | 32 ++++++++------- .../Graphics/Backgrounds/BeatmapBackground.cs | 40 +++++++++---------- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/Background.cs b/osu.Game/Graphics/Backgrounds/Background.cs index 7c074eda047b..f04318eb19b4 100644 --- a/osu.Game/Graphics/Backgrounds/Background.cs +++ b/osu.Game/Graphics/Backgrounds/Background.cs @@ -16,7 +16,7 @@ namespace osu.Game.Graphics.Backgrounds { /// - /// A background which offers blurring via a on demand. + /// A background which offers blurring via a on demand. /// public partial class Background : CompositeDrawable, IEquatable { @@ -24,7 +24,7 @@ public partial class Background : CompositeDrawable, IEquatable private readonly string textureName; - protected BufferedContainer BufferedContainer; + private BufferedContainer bufferedContainer; public Background(string textureName = @"") { @@ -49,27 +49,29 @@ private void load(LargeTextureStore textures) FillMode = FillMode.Fill, }; - public Vector2 BlurSigma => Vector2.Divide(BufferedContainer?.BlurSigma ?? Vector2.Zero, blurScale); + protected virtual BufferedContainer CreateBufferedContainer() => new BufferedContainer(cachedFrameBuffer: true) + { + RelativeSizeAxes = Axes.Both, + RedrawOnScale = false, + Child = Sprite + }; + + public Vector2 BlurSigma => Vector2.Divide(bufferedContainer?.BlurSigma ?? Vector2.Zero, blurScale); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. - public virtual void BlurTo(Vector2 newBlurSigma, double duration = 0, Easing easing = Easing.None) + public void BlurTo(Vector2 newBlurSigma, double duration = 0, Easing easing = Easing.None) { - if (BufferedContainer == null && newBlurSigma != Vector2.Zero) + if (bufferedContainer == null && newBlurSigma != Vector2.Zero) { RemoveInternal(Sprite, false); - AddInternal(BufferedContainer = new BufferedContainer(cachedFrameBuffer: true) - { - RelativeSizeAxes = Axes.Both, - RedrawOnScale = false, - Child = Sprite - }); + AddInternal(bufferedContainer = CreateBufferedContainer()); } - if (BufferedContainer != null) + if (bufferedContainer != null) transformBlurSigma(newBlurSigma, duration, easing); } @@ -84,13 +86,13 @@ private Vector2 blurSigma get => blurSigmaBacking; set { - Debug.Assert(BufferedContainer != null); + Debug.Assert(bufferedContainer != null); blurSigmaBacking = value; blurScale = new Vector2(calculateBlurDownscale(value.X), calculateBlurDownscale(value.Y)); - BufferedContainer.FrameBufferScale = blurScale; - BufferedContainer.BlurSigma = value * blurScale; // If the image is scaled down, the blur radius also needs to be reduced to cover the same pixel block. + bufferedContainer.FrameBufferScale = blurScale; + bufferedContainer.BlurSigma = value * blurScale; // If the image is scaled down, the blur radius also needs to be reduced to cover the same pixel block. } } diff --git a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs index 23e26030bb73..db3aa057bdc9 100644 --- a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs +++ b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs @@ -30,6 +30,8 @@ public partial class BeatmapBackground : Background protected BeatmapBackgroundSprite ColouredDimmableSprite { get; private set; } + protected DimmableBufferedContainer ColouredDimmableBufferedContainer { get; private set; } + private Color4 dimColour; private float dimLevel; @@ -46,7 +48,7 @@ public float DimLevel set => ColouredDimmable.DimLevel = dimLevel = value; } - protected IColouredDimmable ColouredDimmable => BufferedContainer != null ? (BufferedContainer as DimmableBufferedContainer) : ColouredDimmableSprite; + protected IColouredDimmable ColouredDimmable => ColouredDimmableBufferedContainer != null ? ColouredDimmableBufferedContainer : ColouredDimmableSprite; public BeatmapBackground(WorkingBeatmap beatmap, string fallbackTextureName = @"Backgrounds/bg1") { @@ -71,6 +73,21 @@ private void load(LargeTextureStore textures) FillMode = FillMode.Fill, }; + protected override BufferedContainer CreateBufferedContainer() + { + ColouredDimmableSprite.DimColour = Color4.Black; + ColouredDimmableSprite.DimLevel = 0.0f; + + return ColouredDimmableBufferedContainer = new DimmableBufferedContainer(cachedFrameBuffer: true) + { + RelativeSizeAxes = Axes.Both, + RedrawOnScale = false, + Child = Sprite, + DimColour = DimColour, + DimLevel = DimLevel + }; + } + public override bool Equals(Background other) { if (ReferenceEquals(null, other)) return false; @@ -80,27 +97,6 @@ public override bool Equals(Background other) && ((BeatmapBackground)other).Beatmap == Beatmap; } - public override void BlurTo(Vector2 newBlurSigma, double duration = 0, Easing easing = Easing.None) - { - if (BufferedContainer == null && newBlurSigma != Vector2.Zero) - { - RemoveInternal(Sprite, false); - - ColouredDimmableSprite.DimColour = Color4.Black; - ColouredDimmableSprite.DimLevel = 0.0f; - - AddInternal(BufferedContainer = new DimmableBufferedContainer(cachedFrameBuffer: true) - { - RelativeSizeAxes = Axes.Both, - RedrawOnScale = false, - Child = Sprite, - DimColour = DimColour, - DimLevel = DimLevel - }); - } - base.BlurTo(newBlurSigma, duration, easing); - } - public interface IColouredDimmable : IDrawable { Color4 DimColour { get; set; } From ec22de74a5fbd1f5d1e657de3a41d1911dc568c4 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Tue, 15 Oct 2024 00:00:13 +0300 Subject: [PATCH 37/47] Added test to verify that both dimming handlers work as intended --- .../Background/TestSceneUserDimBackgrounds.cs | 65 +++++++++++++++++-- osu.Game/Graphics/Backgrounds/Background.cs | 2 +- 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs index 9dae6a1d1bfc..15083974b407 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs @@ -266,6 +266,34 @@ public void TestResumeFromPlayer() AddUntilStep("Screen is undimmed and user blur removed", () => songSelect.IsBackgroundUndimmed() && songSelect.CheckBackgroundBlur(playerLoader.ExpectedBackgroundBlur)); } + /// + /// Check if both the Sprite and BufferedContainer can handle dimming and don't handle it at the same time. + /// + [Test] + public void TestDimmingHandlers() + { + AddStep("Disallow blurring", () => TestBeatmapBackground.AllowBlur = false); + + SetUpSteps(); + + performFullSetup(); + + AddUntilStep("Screen is dimmed and dim colour adjusted", () => songSelect.IsBackgroundDimmed() && songSelect.IsBackgroundColourOffset()); + AddUntilStep("BufferedContainer is not initialized", () => songSelect.IsBufferedContainerNull()); + AddUntilStep("Sprite is dimmed", () => songSelect.IsSpriteDimmed()); + + AddStep("Allow blurring", () => TestBeatmapBackground.AllowBlur = true); + + SetUpSteps(); + + performFullSetup(); + + AddUntilStep("Screen is dimmed, blur applied and dim colour adjusted", () => songSelect.IsBackgroundDimmed() && songSelect.IsUserBlurApplied() && songSelect.IsBackgroundColourOffset()); + AddUntilStep("BufferedContainer is initialized", () => !songSelect.IsBufferedContainerNull()); + AddUntilStep("BufferedContainer is dimmed", () => songSelect.IsBufferedContainerDimmed()); + AddUntilStep("Sprite is not dimmed", () => !songSelect.IsSpriteDimmed()); + } + private void createFakeStoryboard() => AddStep("Create storyboard", () => { player.StoryboardEnabled.Value = false; @@ -384,6 +412,12 @@ public bool IsBackgroundColourOffset() /// /// Whether or not the original background (The one created in DummySongSelect) is still the current background public bool IsBackgroundCurrent() => background?.IsCurrentScreen() == true; + + public bool IsSpriteDimmed() => background.IsSpriteDimmed; + + public bool IsBufferedContainerDimmed() => background.IsBufferedContainerDimmed; + + public bool IsBufferedContainerNull() => background.IsBufferedContainerNull; } private partial class FadeAccessibleResults : ResultsScreen @@ -472,6 +506,12 @@ private partial class FadeAccessibleBackground : BackgroundScreenBeatmap public Color4 ContentDrawColour => beatmapBackground.ContentDrawColour; + public bool IsSpriteDimmed => beatmapBackground.IsSpriteDimmed; + + public bool IsBufferedContainerDimmed => beatmapBackground.IsBufferedContainerDimmed; + + public bool IsBufferedContainerNull => beatmapBackground.IsBufferedContainerNull; + public Color4 ParentDrawColour => dimmable.ParentDrawColour; public float CurrentAlpha => dimmable.CurrentAlpha; @@ -505,11 +545,7 @@ private partial class TestDimmableBackground : BackgroundScreenBeatmap.DimmableB private partial class TestBeatmapBackground : BeatmapBackground { - public TestBeatmapBackground(WorkingBeatmap beatmap) - : base(beatmap) - { - - } + public static bool AllowBlur = true; // BeatmapBackground shader uses mix function to apply dimming with colour, which can be extended as: // mix(TextureColour, DimColour, DimLevel) = TextureColour * (1 - DimLevel) + DimColour * DimLevel @@ -561,6 +597,25 @@ public Color4 CurrentColourOffset } public Color4 ContentDrawColour => ColouredDimmable.DrawColourInfo.Colour; + + public bool IsSpriteDimmed => ColouredDimmableSprite.DimLevel != 0.0f; + + public bool IsBufferedContainerDimmed => ColouredDimmableBufferedContainer != null ? ColouredDimmableBufferedContainer.DimLevel != 0.0f : false; + + public bool IsBufferedContainerNull => ColouredDimmableBufferedContainer == null; + + public TestBeatmapBackground(WorkingBeatmap beatmap) + : base(beatmap) + { + } + + public override void BlurTo(Vector2 newBlurSigma, double duration = 0, Easing easing = Easing.None) + { + if (AllowBlur) + { + base.BlurTo(newBlurSigma, duration, easing); + } + } } } } diff --git a/osu.Game/Graphics/Backgrounds/Background.cs b/osu.Game/Graphics/Backgrounds/Background.cs index f04318eb19b4..dfa017563292 100644 --- a/osu.Game/Graphics/Backgrounds/Background.cs +++ b/osu.Game/Graphics/Backgrounds/Background.cs @@ -62,7 +62,7 @@ private void load(LargeTextureStore textures) /// Smoothly adjusts over time. /// /// A to which further transforms can be added. - public void BlurTo(Vector2 newBlurSigma, double duration = 0, Easing easing = Easing.None) + public virtual void BlurTo(Vector2 newBlurSigma, double duration = 0, Easing easing = Easing.None) { if (bufferedContainer == null && newBlurSigma != Vector2.Zero) { From 07122304de62e1afbb426a6e5aeab1eab5752416 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Wed, 16 Oct 2024 20:36:04 +0300 Subject: [PATCH 38/47] Made TestSceneUserDimBackgrounds compute current colour using ColoredDimmable's DimLevel and DimColour --- .../Visual/Background/TestSceneUserDimBackgrounds.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs index 15083974b407..6fedaca64ea6 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs @@ -571,6 +571,7 @@ public Color4 CurrentColour get { Color4 DrawColour = DrawColourInfo.Colour; + float DimLevel = ColouredDimmable.DimLevel; return new Color4( DrawColour.R * (1 - DimLevel), @@ -586,6 +587,8 @@ public Color4 CurrentColourOffset get { Color4 DrawColour = DrawColourInfo.Colour; + Color4 DimColour = ColouredDimmable.DimColour; + float DimLevel = ColouredDimmable.DimLevel; return new Color4( DrawColour.R * DimColour.R * DimLevel, From 356a0f3733669190f7059ce0810ff751bcca3348 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Wed, 16 Oct 2024 20:45:52 +0300 Subject: [PATCH 39/47] Added Background colour to visual settings --- osu.Game/Screens/Play/PlayerSettings/VisualSettings.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/osu.Game/Screens/Play/PlayerSettings/VisualSettings.cs b/osu.Game/Screens/Play/PlayerSettings/VisualSettings.cs index ff857ddb12b7..4496ae6f81ef 100644 --- a/osu.Game/Screens/Play/PlayerSettings/VisualSettings.cs +++ b/osu.Game/Screens/Play/PlayerSettings/VisualSettings.cs @@ -12,6 +12,7 @@ public partial class VisualSettings : PlayerSettingsGroup { private readonly PlayerSliderBar dimSliderBar; private readonly PlayerSliderBar blurSliderBar; + private readonly PlayerSliderBar dimColourSliderBar; private readonly PlayerSliderBar comboColourNormalisationSliderBar; private readonly PlayerCheckbox showStoryboardToggle; private readonly PlayerCheckbox beatmapSkinsToggle; @@ -32,6 +33,11 @@ public VisualSettings() LabelText = GameplaySettingsStrings.BackgroundBlur, DisplayAsPercentage = true }, + dimColourSliderBar = new PlayerSliderBar + { + LabelText = GameplaySettingsStrings.BackgroundColour, + DisplayAsPercentage = true + }, showStoryboardToggle = new PlayerCheckbox { LabelText = GraphicsSettingsStrings.StoryboardVideo }, beatmapSkinsToggle = new PlayerCheckbox { LabelText = SkinSettingsStrings.BeatmapSkins }, beatmapColorsToggle = new PlayerCheckbox { LabelText = SkinSettingsStrings.BeatmapColours }, @@ -48,6 +54,7 @@ private void load(OsuConfigManager config) { dimSliderBar.Current = config.GetBindable(OsuSetting.DimLevel); blurSliderBar.Current = config.GetBindable(OsuSetting.BlurLevel); + dimColourSliderBar.Current = config.GetBindable(OsuSetting.DimColour); showStoryboardToggle.Current = config.GetBindable(OsuSetting.ShowStoryboard); beatmapSkinsToggle.Current = config.GetBindable(OsuSetting.BeatmapSkins); beatmapColorsToggle.Current = config.GetBindable(OsuSetting.BeatmapColours); From 62567f23f39a6a79d098b9a10bea4bb14f7bfa08 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Wed, 16 Oct 2024 20:53:21 +0300 Subject: [PATCH 40/47] Changed BackgroundColour localisable string into BackgroundDimColour --- osu.Game/Localisation/GameplaySettingsStrings.cs | 4 ++-- .../Overlays/Settings/Sections/Gameplay/BackgroundSettings.cs | 2 +- osu.Game/Screens/Play/PlayerSettings/VisualSettings.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game/Localisation/GameplaySettingsStrings.cs b/osu.Game/Localisation/GameplaySettingsStrings.cs index 3acbb4c6aaf1..d5a0b339720e 100644 --- a/osu.Game/Localisation/GameplaySettingsStrings.cs +++ b/osu.Game/Localisation/GameplaySettingsStrings.cs @@ -50,9 +50,9 @@ public static class GameplaySettingsStrings public static LocalisableString BackgroundBlur => new TranslatableString(getKey(@"blur"), @"Background blur"); /// - /// "Background colour" + /// "Background dim colour" /// - public static LocalisableString BackgroundColour => new TranslatableString(getKey(@"bg_colour"), @"Background colour"); + public static LocalisableString BackgroundDimColour => new TranslatableString(getKey(@"dim_colour"), @"Background dim colour"); /// /// "Lighten playfield during breaks" diff --git a/osu.Game/Overlays/Settings/Sections/Gameplay/BackgroundSettings.cs b/osu.Game/Overlays/Settings/Sections/Gameplay/BackgroundSettings.cs index 041821b60ff9..fdb03273c4a2 100644 --- a/osu.Game/Overlays/Settings/Sections/Gameplay/BackgroundSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Gameplay/BackgroundSettings.cs @@ -34,7 +34,7 @@ private void load(OsuConfigManager config) }, new SettingsSlider { - LabelText = GameplaySettingsStrings.BackgroundColour, + LabelText = GameplaySettingsStrings.BackgroundDimColour, Current = config.GetBindable(OsuSetting.DimColour), KeyboardStep = 0.01f, DisplayAsPercentage = true diff --git a/osu.Game/Screens/Play/PlayerSettings/VisualSettings.cs b/osu.Game/Screens/Play/PlayerSettings/VisualSettings.cs index 4496ae6f81ef..fcaa5e7be766 100644 --- a/osu.Game/Screens/Play/PlayerSettings/VisualSettings.cs +++ b/osu.Game/Screens/Play/PlayerSettings/VisualSettings.cs @@ -35,7 +35,7 @@ public VisualSettings() }, dimColourSliderBar = new PlayerSliderBar { - LabelText = GameplaySettingsStrings.BackgroundColour, + LabelText = GameplaySettingsStrings.BackgroundDimColour, DisplayAsPercentage = true }, showStoryboardToggle = new PlayerCheckbox { LabelText = GraphicsSettingsStrings.StoryboardVideo }, From c8d4dac0b1e03a90e54db7413d536aef04b0890a Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Wed, 16 Oct 2024 22:25:53 +0300 Subject: [PATCH 41/47] Changed the way ParentDrawColour is computed --- .../Visual/Background/TestSceneUserDimBackgrounds.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs index 6fedaca64ea6..813ea34451c3 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs @@ -512,7 +512,7 @@ private partial class FadeAccessibleBackground : BackgroundScreenBeatmap public bool IsBufferedContainerNull => beatmapBackground.IsBufferedContainerNull; - public Color4 ParentDrawColour => dimmable.ParentDrawColour; + public Color4 ParentDrawColour => DrawColourInfo.Colour; public float CurrentAlpha => dimmable.CurrentAlpha; @@ -534,8 +534,6 @@ public FadeAccessibleBackground(WorkingBeatmap beatmap) private partial class TestDimmableBackground : BackgroundScreenBeatmap.DimmableBackground { - public Color4 ParentDrawColour => Content.Parent.DrawColourInfo.Colour; - public float CurrentAlpha => Content.Alpha; public new float DimLevel => base.DimLevel; From fbe05ea099e930aa94f3a8cfb645ae74e97fe9f2 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Thu, 17 Oct 2024 19:33:13 +0300 Subject: [PATCH 42/47] Updated the source of DrawColour when computing expected/target colour --- .../Background/TestSceneUserDimBackgrounds.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs index 813ea34451c3..953f6fc908d5 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs @@ -370,12 +370,12 @@ private void load(OsuConfigManager config) public bool IsBackgroundDimmed() { - Color4 ContentDrawColour = background.ContentDrawColour; + Color4 ParentDrawColour = background.ParentDrawColour; Color4 TargetColour = new Color4( - ContentDrawColour.R * (1f - background.CurrentDim), - ContentDrawColour.G * (1f - background.CurrentDim), - ContentDrawColour.B * (1f - background.CurrentDim), - ContentDrawColour.A + ParentDrawColour.R * (1f - background.CurrentDim), + ParentDrawColour.G * (1f - background.CurrentDim), + ParentDrawColour.B * (1f - background.CurrentDim), + ParentDrawColour.A ); return background.CurrentColour == TargetColour; @@ -386,11 +386,11 @@ public bool IsBackgroundDimmed() public bool IsBackgroundColourOffset() { Color4 CurrentDimColour = background.CurrentDimColour; - Color4 ContentDrawColour = background.ContentDrawColour; + Color4 ParentDrawColour = background.ParentDrawColour; Color4 TargetColourOffset = new Color4( - ContentDrawColour.R * CurrentDimColour.R * background.CurrentDim, - ContentDrawColour.G * CurrentDimColour.G * background.CurrentDim, - ContentDrawColour.B * CurrentDimColour.B * background.CurrentDim, + ParentDrawColour.R * CurrentDimColour.R * background.CurrentDim, + ParentDrawColour.G * CurrentDimColour.G * background.CurrentDim, + ParentDrawColour.B * CurrentDimColour.B * background.CurrentDim, 1 ); From 65d9dbe14a344ab07f333ccaf35f6a18948ce526 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Thu, 17 Oct 2024 22:56:08 +0300 Subject: [PATCH 43/47] Formatting fixes --- .../Background/TestSceneUserDimBackgrounds.cs | 58 +++++++++---------- .../Graphics/Backgrounds/BeatmapBackground.cs | 6 +- .../Backgrounds/BackgroundScreenBeatmap.cs | 2 +- 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs index 953f6fc908d5..dcafb7a76a69 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs @@ -370,31 +370,31 @@ private void load(OsuConfigManager config) public bool IsBackgroundDimmed() { - Color4 ParentDrawColour = background.ParentDrawColour; - Color4 TargetColour = new Color4( - ParentDrawColour.R * (1f - background.CurrentDim), - ParentDrawColour.G * (1f - background.CurrentDim), - ParentDrawColour.B * (1f - background.CurrentDim), - ParentDrawColour.A + Color4 parentDrawColour = background.ParentDrawColour; + Color4 targetColour = new Color4( + parentDrawColour.R * (1f - background.CurrentDim), + parentDrawColour.G * (1f - background.CurrentDim), + parentDrawColour.B * (1f - background.CurrentDim), + parentDrawColour.A ); - return background.CurrentColour == TargetColour; + return background.CurrentColour == targetColour; } public bool IsBackgroundUndimmed() => background.CurrentColour == background.ParentDrawColour && background.CurrentColourOffset == Color4.Black; public bool IsBackgroundColourOffset() { - Color4 CurrentDimColour = background.CurrentDimColour; - Color4 ParentDrawColour = background.ParentDrawColour; - Color4 TargetColourOffset = new Color4( - ParentDrawColour.R * CurrentDimColour.R * background.CurrentDim, - ParentDrawColour.G * CurrentDimColour.G * background.CurrentDim, - ParentDrawColour.B * CurrentDimColour.B * background.CurrentDim, + Color4 currentDimColour = background.CurrentDimColour; + Color4 parentDrawColour = background.ParentDrawColour; + Color4 targetColourOffset = new Color4( + parentDrawColour.R * currentDimColour.R * background.CurrentDim, + parentDrawColour.G * currentDimColour.G * background.CurrentDim, + parentDrawColour.B * currentDimColour.B * background.CurrentDim, 1 ); - return background.CurrentColourOffset == TargetColourOffset; + return background.CurrentColourOffset == targetColourOffset; } public bool IsUserBlurApplied() => Precision.AlmostEquals(background.CurrentBlur, new Vector2((float)BlurLevel.Value * BackgroundScreenBeatmap.USER_BLUR_FACTOR), 0.1f); @@ -568,14 +568,14 @@ public Color4 CurrentColour { get { - Color4 DrawColour = DrawColourInfo.Colour; - float DimLevel = ColouredDimmable.DimLevel; + Color4 drawColour = DrawColourInfo.Colour; + float dimLevel = ColouredDimmable.DimLevel; return new Color4( - DrawColour.R * (1 - DimLevel), - DrawColour.G * (1 - DimLevel), - DrawColour.B * (1 - DimLevel), - DrawColour.A + drawColour.R * (1 - dimLevel), + drawColour.G * (1 - dimLevel), + drawColour.B * (1 - dimLevel), + drawColour.A ); } } @@ -584,15 +584,15 @@ public Color4 CurrentColourOffset { get { - Color4 DrawColour = DrawColourInfo.Colour; - Color4 DimColour = ColouredDimmable.DimColour; - float DimLevel = ColouredDimmable.DimLevel; + Color4 drawColour = DrawColourInfo.Colour; + Color4 dimColour = ColouredDimmable.DimColour; + float dimLevel = ColouredDimmable.DimLevel; return new Color4( - DrawColour.R * DimColour.R * DimLevel, - DrawColour.G * DimColour.G * DimLevel, - DrawColour.B * DimColour.B * DimLevel, - DrawColour.A + drawColour.R * dimColour.R * dimLevel, + drawColour.G * dimColour.G * dimLevel, + drawColour.B * dimColour.B * dimLevel, + drawColour.A ); } } @@ -601,12 +601,12 @@ public Color4 CurrentColourOffset public bool IsSpriteDimmed => ColouredDimmableSprite.DimLevel != 0.0f; - public bool IsBufferedContainerDimmed => ColouredDimmableBufferedContainer != null ? ColouredDimmableBufferedContainer.DimLevel != 0.0f : false; + public bool IsBufferedContainerDimmed => ColouredDimmableBufferedContainer != null && ColouredDimmableBufferedContainer.DimLevel != 0.0f; public bool IsBufferedContainerNull => ColouredDimmableBufferedContainer == null; public TestBeatmapBackground(WorkingBeatmap beatmap) - : base(beatmap) + : base(beatmap) { } diff --git a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs index db3aa057bdc9..6e0962ee4f32 100644 --- a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs +++ b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs @@ -3,7 +3,6 @@ #nullable disable - using System.Runtime.InteropServices; using osu.Framework.Allocation; using osu.Framework.Graphics; @@ -131,7 +130,7 @@ public float DimLevel } public DimmableBufferedContainer(RenderBufferFormat[] formats = null, bool pixelSnapping = false, bool cachedFrameBuffer = false) - : base(formats, pixelSnapping, cachedFrameBuffer) + : base(formats, pixelSnapping, cachedFrameBuffer) { DimColour = Color4.Black; DimLevel = 0.0f; @@ -150,7 +149,7 @@ protected class DimmableBufferedContainerDrawNode : BufferedContainerDrawNode public new DimmableBufferedContainer Source => (DimmableBufferedContainer)base.Source; public DimmableBufferedContainerDrawNode(DimmableBufferedContainer source, BufferedContainerDrawNodeSharedData sharedData) - : base(source, sharedData) + : base(source, sharedData) { } @@ -224,7 +223,6 @@ public float DimLevel } public BeatmapBackgroundSprite() - : base() { DimColour = Color4.Black; DimLevel = 0.0f; diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index 34fc9228b849..baebfe190cc3 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -229,7 +229,7 @@ protected virtual Color4 DimColour { get { - if (IgnoreUserSettings.Value || ShowStoryboard.Value && StoryboardReplacesBackground.Value) + if (IgnoreUserSettings.Value || (ShowStoryboard.Value && StoryboardReplacesBackground.Value)) return Color4.Black; return OsuColour.Gray((float)userDimColour.Value); From f04c4b04e4bc591daf005894e0fdbc957dccd8db Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Tue, 22 Oct 2024 00:20:16 +0300 Subject: [PATCH 44/47] Removed dependency on osuTK --- .../Background/TestSceneUserDimBackgrounds.cs | 50 +++++++++---------- .../Graphics/Backgrounds/BeatmapBackground.cs | 44 +++++++++------- .../Backgrounds/BackgroundScreenBeatmap.cs | 8 ++- 3 files changed, 54 insertions(+), 48 deletions(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs index dcafb7a76a69..31593cfd8878 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs @@ -19,7 +19,6 @@ using osu.Game.Beatmaps; using osu.Game.Configuration; using osu.Game.Database; -using osu.Game.Graphics; using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; @@ -34,7 +33,6 @@ using osu.Game.Screens.Select; using osu.Game.Tests.Resources; using osuTK; -using osuTK.Graphics; namespace osu.Game.Tests.Visual.Background { @@ -302,7 +300,7 @@ private void createFakeStoryboard() => AddStep("Create storyboard", () => { Size = new Vector2(500, 50), Alpha = 1, - Colour = Color4.White, + Colour = Colour4.White, Anchor = Anchor.Centre, Origin = Anchor.Centre, Text = "THIS IS A STORYBOARD", @@ -366,12 +364,12 @@ private void load(OsuConfigManager config) config.BindWith(OsuSetting.DimColour, DimColour); } - public bool IsBackgroundBlack() => background.CurrentColour == OsuColour.Gray(0) && background.CurrentColourOffset == OsuColour.Gray(0); + public bool IsBackgroundBlack() => background.CurrentColour == Colour4.Black && background.CurrentColourOffset == Colour4.Black; public bool IsBackgroundDimmed() { - Color4 parentDrawColour = background.ParentDrawColour; - Color4 targetColour = new Color4( + Colour4 parentDrawColour = background.ParentDrawColour; + Colour4 targetColour = new Colour4( parentDrawColour.R * (1f - background.CurrentDim), parentDrawColour.G * (1f - background.CurrentDim), parentDrawColour.B * (1f - background.CurrentDim), @@ -381,13 +379,13 @@ public bool IsBackgroundDimmed() return background.CurrentColour == targetColour; } - public bool IsBackgroundUndimmed() => background.CurrentColour == background.ParentDrawColour && background.CurrentColourOffset == Color4.Black; + public bool IsBackgroundUndimmed() => background.CurrentColour == background.ParentDrawColour && background.CurrentColourOffset == Colour4.Black; public bool IsBackgroundColourOffset() { - Color4 currentDimColour = background.CurrentDimColour; - Color4 parentDrawColour = background.ParentDrawColour; - Color4 targetColourOffset = new Color4( + Colour4 currentDimColour = background.CurrentDimColour; + Colour4 parentDrawColour = background.ParentDrawColour; + Colour4 targetColourOffset = new Colour4( parentDrawColour.R * currentDimColour.R * background.CurrentDim, parentDrawColour.G * currentDimColour.G * background.CurrentDim, parentDrawColour.B * currentDimColour.B * background.CurrentDim, @@ -500,11 +498,11 @@ private partial class FadeAccessibleBackground : BackgroundScreenBeatmap protected override BeatmapBackground CreateBeatmapBackground(WorkingBeatmap beatmap) => beatmapBackground = new TestBeatmapBackground(beatmap); - public Color4 CurrentColour => beatmapBackground.CurrentColour; + public Colour4 CurrentColour => beatmapBackground.CurrentColour; - public Color4 CurrentColourOffset => beatmapBackground.CurrentColourOffset; + public Colour4 CurrentColourOffset => beatmapBackground.CurrentColourOffset; - public Color4 ContentDrawColour => beatmapBackground.ContentDrawColour; + public Colour4 ContentDrawColour => beatmapBackground.ContentDrawColour; public bool IsSpriteDimmed => beatmapBackground.IsSpriteDimmed; @@ -512,13 +510,13 @@ private partial class FadeAccessibleBackground : BackgroundScreenBeatmap public bool IsBufferedContainerNull => beatmapBackground.IsBufferedContainerNull; - public Color4 ParentDrawColour => DrawColourInfo.Colour; + public Colour4 ParentDrawColour => DrawColourInfo.Colour; public float CurrentAlpha => dimmable.CurrentAlpha; public float CurrentDim => dimmable.DimLevel; - public Color4 CurrentDimColour => dimmable.DimColour; + public Colour4 CurrentDimColour => dimmable.DimColour; public Vector2 CurrentBlur => Background?.BlurSigma ?? Vector2.Zero; @@ -538,7 +536,7 @@ private partial class TestDimmableBackground : BackgroundScreenBeatmap.DimmableB public new float DimLevel => base.DimLevel; - public new Color4 DimColour => base.DimColour; + public new Colour4 DimColour => base.DimColour; } private partial class TestBeatmapBackground : BeatmapBackground @@ -561,17 +559,17 @@ private partial class TestBeatmapBackground : BeatmapBackground // CurrentColourOffset can be used to track how much colour was added as an offset. // // Two separate variables are needed because just one Colour variable would be ambiguous, for example: - // if Colour == Color4.White, that could mean either that + // if Colour == Colour4.White, that could mean either that // DimLevel == 0.0, or - // DimLevel == 1.0 and DimColour == Color4.White. - public Color4 CurrentColour + // DimLevel == 1.0 and DimColour == Colour4.White. + public Colour4 CurrentColour { get { - Color4 drawColour = DrawColourInfo.Colour; + Colour4 drawColour = DrawColourInfo.Colour; float dimLevel = ColouredDimmable.DimLevel; - return new Color4( + return new Colour4( drawColour.R * (1 - dimLevel), drawColour.G * (1 - dimLevel), drawColour.B * (1 - dimLevel), @@ -580,15 +578,15 @@ public Color4 CurrentColour } } - public Color4 CurrentColourOffset + public Colour4 CurrentColourOffset { get { - Color4 drawColour = DrawColourInfo.Colour; - Color4 dimColour = ColouredDimmable.DimColour; + Colour4 drawColour = DrawColourInfo.Colour; + Colour4 dimColour = ColouredDimmable.DimColour; float dimLevel = ColouredDimmable.DimLevel; - return new Color4( + return new Colour4( drawColour.R * dimColour.R * dimLevel, drawColour.G * dimColour.G * dimLevel, drawColour.B * dimColour.B * dimLevel, @@ -597,7 +595,7 @@ public Color4 CurrentColourOffset } } - public Color4 ContentDrawColour => ColouredDimmable.DrawColourInfo.Colour; + public Colour4 ContentDrawColour => ColouredDimmable.DrawColourInfo.Colour; public bool IsSpriteDimmed => ColouredDimmableSprite.DimLevel != 0.0f; diff --git a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs index 6e0962ee4f32..515c3022b216 100644 --- a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs +++ b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs @@ -13,8 +13,6 @@ using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; using osu.Game.Beatmaps; -using osuTK; -using osuTK.Graphics; namespace osu.Game.Graphics.Backgrounds { @@ -31,11 +29,11 @@ public partial class BeatmapBackground : Background protected DimmableBufferedContainer ColouredDimmableBufferedContainer { get; private set; } - private Color4 dimColour; + private Colour4 dimColour; private float dimLevel; - public Color4 DimColour + public Colour4 DimColour { get => dimColour; set => ColouredDimmable.DimColour = dimColour = value; @@ -54,7 +52,7 @@ public BeatmapBackground(WorkingBeatmap beatmap, string fallbackTextureName = @" Beatmap = beatmap; this.fallbackTextureName = fallbackTextureName; - DimColour = Color4.Black; + DimColour = Colour4.Black; DimLevel = 0.0f; } @@ -74,7 +72,7 @@ private void load(LargeTextureStore textures) protected override BufferedContainer CreateBufferedContainer() { - ColouredDimmableSprite.DimColour = Color4.Black; + ColouredDimmableSprite.DimColour = Colour4.Black; ColouredDimmableSprite.DimLevel = 0.0f; return ColouredDimmableBufferedContainer = new DimmableBufferedContainer(cachedFrameBuffer: true) @@ -98,18 +96,18 @@ public override bool Equals(Background other) public interface IColouredDimmable : IDrawable { - Color4 DimColour { get; set; } + Colour4 DimColour { get; set; } float DimLevel { get; set; } } public partial class DimmableBufferedContainer : BufferedContainer, IColouredDimmable { - private Color4 dimColour; + private Colour4 dimColour; private float dimLevel; - public Color4 DimColour + public Colour4 DimColour { get => dimColour; set @@ -132,7 +130,7 @@ public float DimLevel public DimmableBufferedContainer(RenderBufferFormat[] formats = null, bool pixelSnapping = false, bool cachedFrameBuffer = false) : base(formats, pixelSnapping, cachedFrameBuffer) { - DimColour = Color4.Black; + DimColour = Colour4.Black; DimLevel = 0.0f; } @@ -153,7 +151,7 @@ public DimmableBufferedContainerDrawNode(DimmableBufferedContainer source, Buffe { } - private Color4 dimColour; + private Colour4 dimColour; private float dimLevel; @@ -173,7 +171,13 @@ protected override void BindUniformResources(IShader shader, IRenderer renderer) beatmapBackgroundParametersBuffer.Data = beatmapBackgroundParametersBuffer.Data with { - DimColour = new Vector4(dimColour.R, dimColour.G, dimColour.B, dimColour.A), + DimColour = new UniformVector4 + { + X = dimColour.R, + Y = dimColour.G, + Z = dimColour.B, + W = dimColour.A + }, DimLevel = dimLevel, }; @@ -198,11 +202,11 @@ private record struct BeatmapBackgroundParameters public partial class BeatmapBackgroundSprite : Sprite, IColouredDimmable { - private Color4 dimColour; + private Colour4 dimColour; private float dimLevel; - public Color4 DimColour + public Colour4 DimColour { get => dimColour; set @@ -224,7 +228,7 @@ public float DimLevel public BeatmapBackgroundSprite() { - DimColour = Color4.Black; + DimColour = Colour4.Black; DimLevel = 0.0f; } @@ -245,7 +249,7 @@ public BeatmapBackgroundSpriteDrawNode(BeatmapBackgroundSprite source) { } - private Color4 dimColour; + private Colour4 dimColour; private float dimLevel; @@ -265,7 +269,13 @@ protected override void BindUniformResources(IShader shader, IRenderer renderer) beatmapBackgroundParametersBuffer.Data = beatmapBackgroundParametersBuffer.Data with { - DimColour = new Vector4(dimColour.R, dimColour.G, dimColour.B, dimColour.A), + DimColour = new UniformVector4 + { + X = dimColour.R, + Y = dimColour.G, + Z = dimColour.B, + W = dimColour.A + }, DimLevel = dimLevel, }; diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index baebfe190cc3..f3c69095a32f 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -10,12 +10,10 @@ using osu.Framework.Graphics; using osu.Game.Beatmaps; using osu.Game.Configuration; -using osu.Game.Graphics; using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Containers; using osu.Game.Screens.Play; using osuTK; -using osuTK.Graphics; namespace osu.Game.Screens.Backgrounds { @@ -225,14 +223,14 @@ protected override float DimLevel } } - protected virtual Color4 DimColour + protected virtual Colour4 DimColour { get { if (IgnoreUserSettings.Value || (ShowStoryboard.Value && StoryboardReplacesBackground.Value)) - return Color4.Black; + return Colour4.Black; - return OsuColour.Gray((float)userDimColour.Value); + return new Colour4((float)userDimColour.Value, (float)userDimColour.Value, (float)userDimColour.Value, 1.0f); } } From 96b7d97f16c92c9f8deeb796315f310e95ad623d Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Tue, 22 Oct 2024 14:36:22 +0300 Subject: [PATCH 45/47] Preload BeatmapBackground shader --- osu.Game/Screens/Loader.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game/Screens/Loader.cs b/osu.Game/Screens/Loader.cs index d71ee05b2753..6366c355bffd 100644 --- a/osu.Game/Screens/Loader.cs +++ b/osu.Game/Screens/Loader.cs @@ -127,6 +127,7 @@ private void load(ShaderManager manager) loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_2, @"ArgonBarPathBackground")); loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_2, @"SaturationSelectorBackground")); loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_2, @"HueSelectorBackground")); + loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_2, @"BeatmapBackground")); loadTargets.Add(manager.Load(@"LogoAnimation", @"LogoAnimation")); // Ruleset local shader usage (should probably move somewhere else). From c5867b6dd9db22935e574cb2d8e7755125ece597 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Mon, 21 Oct 2024 00:21:44 +0300 Subject: [PATCH 46/47] Small formatting fixes --- osu.Game/Configuration/OsuConfigManager.cs | 2 +- osu.Game/Graphics/Backgrounds/Background.cs | 2 +- osu.Game/Graphics/Backgrounds/BeatmapBackground.cs | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index ed8301471175..ae489647e42e 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -133,7 +133,7 @@ protected override void InitialiseDefaults() // Gameplay SetDefault(OsuSetting.PositionalHitsoundsLevel, 0.2f, 0, 1); SetDefault(OsuSetting.DimLevel, 0.7, 0, 1, 0.01); - SetDefault(OsuSetting.DimColour, 0.0, 0, 1, 0.01); + SetDefault(OsuSetting.DimColour, 0, 0, 1, 0.01); SetDefault(OsuSetting.BlurLevel, 0, 0, 1, 0.01); SetDefault(OsuSetting.LightenDuringBreaks, true); diff --git a/osu.Game/Graphics/Backgrounds/Background.cs b/osu.Game/Graphics/Backgrounds/Background.cs index dfa017563292..6edeea31274b 100644 --- a/osu.Game/Graphics/Backgrounds/Background.cs +++ b/osu.Game/Graphics/Backgrounds/Background.cs @@ -16,7 +16,7 @@ namespace osu.Game.Graphics.Backgrounds { /// - /// A background which offers blurring via a on demand. + /// A background which offers blurring via a on demand. /// public partial class Background : CompositeDrawable, IEquatable { diff --git a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs index 515c3022b216..3af88e07330e 100644 --- a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs +++ b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs @@ -45,6 +45,9 @@ public float DimLevel set => ColouredDimmable.DimLevel = dimLevel = value; } + /// + /// A drawable that currently handles dimming. + /// protected IColouredDimmable ColouredDimmable => ColouredDimmableBufferedContainer != null ? ColouredDimmableBufferedContainer : ColouredDimmableSprite; public BeatmapBackground(WorkingBeatmap beatmap, string fallbackTextureName = @"Backgrounds/bg1") From 93c3fac26e55f90f34ff625afa0aec0e4e9f9080 Mon Sep 17 00:00:00 2001 From: Uncomfy Date: Tue, 29 Oct 2024 22:36:46 +0200 Subject: [PATCH 47/47] Test if BufferedContainer's framebuffer is redrawn on dim changes --- .../Background/TestSceneUserDimBackgrounds.cs | 91 +++++++++++++++++++ .../Graphics/Backgrounds/BeatmapBackground.cs | 2 +- 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs index 31593cfd8878..0f7a9792a9d9 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneUserDimBackgrounds.cs @@ -10,6 +10,8 @@ using osu.Framework.Bindables; using osu.Framework.Extensions; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Rendering; using osu.Framework.Graphics.Sprites; using osu.Framework.Input.Events; using osu.Framework.Input.States; @@ -292,6 +294,36 @@ public void TestDimmingHandlers() AddUntilStep("Sprite is not dimmed", () => !songSelect.IsSpriteDimmed()); } + /// + /// Check if BufferedContainer redraws the framebuffer on dim changes. + /// + [Test] + public void TestNoBufferRedrawOnDimChange() + { + performFullSetup(); + + AddUntilStep("Screen is dimmed, blur applied and dim colour adjusted", () => songSelect.IsBackgroundDimmed() && songSelect.IsUserBlurApplied() && songSelect.IsBackgroundColourOffset()); + AddUntilStep("BufferedContainer is initialized", () => !songSelect.IsBufferedContainerNull()); + + AddStep("Start tracking redraws", () => songSelect.RequiredRedraw = false); + + AddStep("Undim the screen", () => + { + songSelect.DimLevel.Value = 0.0; + songSelect.DimColour.Value = 0.0; + }); + AddUntilStep("Screen is undimmed and blur applied", () => songSelect.IsBackgroundUndimmed() && songSelect.IsUserBlurApplied()); + AddUntilStep("Redraw wasn't required", () => !songSelect.RequiredRedraw); + + AddStep("Dim the screen", () => + { + songSelect.DimLevel.Value = 0.7; + songSelect.DimColour.Value = 0.5; + }); + AddUntilStep("Screen is dimmed, blur applied and dim colour adjusted", () => songSelect.IsBackgroundDimmed() && songSelect.IsUserBlurApplied() && songSelect.IsBackgroundColourOffset()); + AddUntilStep("Redraw wasn't required", () => !songSelect.RequiredRedraw); + } + private void createFakeStoryboard() => AddStep("Create storyboard", () => { player.StoryboardEnabled.Value = false; @@ -416,6 +448,12 @@ public bool IsBackgroundColourOffset() public bool IsBufferedContainerDimmed() => background.IsBufferedContainerDimmed; public bool IsBufferedContainerNull() => background.IsBufferedContainerNull; + + public bool RequiredRedraw + { + get => background.RequiredRedraw; + set => background.RequiredRedraw = value; + } } private partial class FadeAccessibleResults : ResultsScreen @@ -520,6 +558,12 @@ private partial class FadeAccessibleBackground : BackgroundScreenBeatmap public Vector2 CurrentBlur => Background?.BlurSigma ?? Vector2.Zero; + public bool RequiredRedraw + { + get => beatmapBackground.RequiredRedraw; + set => beatmapBackground.RequiredRedraw = value; + } + private TestDimmableBackground dimmable; private TestBeatmapBackground beatmapBackground; @@ -603,6 +647,14 @@ public Colour4 CurrentColourOffset public bool IsBufferedContainerNull => ColouredDimmableBufferedContainer == null; + public bool RequiredRedraw + { + get => dimmableBufferedContainer.RequiredRedraw; + set => dimmableBufferedContainer.RequiredRedraw = value; + } + + private TestDimmableBufferedContainer dimmableBufferedContainer; + public TestBeatmapBackground(WorkingBeatmap beatmap) : base(beatmap) { @@ -615,6 +667,45 @@ public override void BlurTo(Vector2 newBlurSigma, double duration = 0, Easing ea base.BlurTo(newBlurSigma, duration, easing); } } + + protected override BufferedContainer CreateBufferedContainer() + { + ColouredDimmableSprite.DimColour = Colour4.Black; + ColouredDimmableSprite.DimLevel = 0.0f; + + return ColouredDimmableBufferedContainer = dimmableBufferedContainer = new TestDimmableBufferedContainer(cachedFrameBuffer: true) + { + RelativeSizeAxes = Axes.Both, + RedrawOnScale = false, + Child = Sprite, + DimColour = DimColour, + DimLevel = DimLevel + }; + } + } + + private partial class TestDimmableBufferedContainer : BeatmapBackground.DimmableBufferedContainer + { + // Ideally this one would be tracked inside of the DrawNode and set to true + // when framebuffer is redrawn, but DrawNode's are a bit broken in the + // headless testing mode, so an indirect check is used (see RequiresChildrenUpdate). + public bool RequiredRedraw; + + public TestDimmableBufferedContainer(RenderBufferFormat[] formats = null, bool pixelSnapping = false, bool cachedFrameBuffer = false) + : base(formats, pixelSnapping, cachedFrameBuffer) + { + } + + protected override bool RequiresChildrenUpdate + { + get + { + // A bit hacky, but at least it doesn't require exposing BufferedContainer.updateVersion + bool requiresChildrenUpdate = base.RequiresChildrenUpdate; + RequiredRedraw |= requiresChildrenUpdate; + return requiresChildrenUpdate; + } + } } } } diff --git a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs index 3af88e07330e..64a6247625a5 100644 --- a/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs +++ b/osu.Game/Graphics/Backgrounds/BeatmapBackground.cs @@ -27,7 +27,7 @@ public partial class BeatmapBackground : Background protected BeatmapBackgroundSprite ColouredDimmableSprite { get; private set; } - protected DimmableBufferedContainer ColouredDimmableBufferedContainer { get; private set; } + protected DimmableBufferedContainer ColouredDimmableBufferedContainer; private Colour4 dimColour;