Skip to content

Commit

Permalink
Merge pull request #25562 from EVAST9919/spinner-glow
Browse files Browse the repository at this point in the history
Implement spinner glow
  • Loading branch information
bdach authored Nov 27, 2023
2 parents e2d5197 + 874a370 commit 418dde9
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 6 deletions.
2 changes: 1 addition & 1 deletion osu.Android.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ppy.osu.Framework.Android" Version="2023.1124.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2023.1127.0" />
</ItemGroup>
<PropertyGroup>
<!-- Fody does not handle Android build well, and warns when unchanged.
Expand Down
122 changes: 120 additions & 2 deletions osu.Game.Rulesets.Osu/Skinning/Argon/ArgonSpinnerProgressArc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Runtime.InteropServices;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Shaders;
using osu.Framework.Graphics.Shaders.Types;
using osu.Framework.Graphics.Textures;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Utils;
using osu.Game.Rulesets.Objects.Drawables;
Expand All @@ -19,7 +26,7 @@ public partial class ArgonSpinnerProgressArc : CompositeDrawable
private const float arc_fill = 0.15f;
private const float arc_radius = 0.12f;

private CircularProgress fill = null!;
private ProgressFill fill = null!;

private DrawableSpinner spinner = null!;

Expand All @@ -45,13 +52,14 @@ private void load(DrawableHitObject drawableHitObject)
InnerRadius = arc_radius,
RoundedCaps = true,
},
fill = new CircularProgress
fill = new ProgressFill
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
InnerRadius = arc_radius,
RoundedCaps = true,
GlowColour = new Color4(171, 255, 255, 255)
}
};
}
Expand All @@ -67,5 +75,115 @@ protected override void Update()

fill.Rotation = (float)(90 - fill.Current.Value * 180);
}

private partial class ProgressFill : CircularProgress
{
private Color4 glowColour = Color4.White;

public Color4 GlowColour
{
get => glowColour;
set
{
glowColour = value;
Invalidate(Invalidation.DrawNode);
}
}

private Texture glowTexture = null!;
private IShader glowShader = null!;
private float glowSize;

[BackgroundDependencyLoader]
private void load(TextureStore textures, ShaderManager shaders)
{
glowTexture = textures.Get("Gameplay/osu/spinner-glow");
glowShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "SpinnerGlow");
glowSize = Blur.KernelSize(50); // Half of the maximum blur sigma in the design (which is 100)
}

protected override DrawNode CreateDrawNode() => new ProgressFillDrawNode(this);

private class ProgressFillDrawNode : CircularProgressDrawNode
{
protected new ProgressFill Source => (ProgressFill)base.Source;

public ProgressFillDrawNode(CircularProgress source)
: base(source)
{
}

private Texture glowTexture = null!;
private IShader glowShader = null!;
private Quad glowQuad;
private float relativeGlowSize;
private Color4 glowColour;

public override void ApplyState()
{
base.ApplyState();

glowTexture = Source.glowTexture;
glowShader = Source.glowShader;
glowColour = Source.glowColour;

// Inflated draw quad by the size of the blur.
glowQuad = Source.ToScreenSpace(DrawRectangle.Inflate(Source.glowSize));
relativeGlowSize = Source.glowSize / Source.DrawSize.X;
}

public override void Draw(IRenderer renderer)
{
base.Draw(renderer);
drawGlow(renderer);
}

private void drawGlow(IRenderer renderer)
{
renderer.SetBlend(BlendingParameters.Additive);

glowShader.Bind();
bindGlowUniformResources(glowShader, renderer);

ColourInfo col = DrawColourInfo.Colour;
col.ApplyChild(glowColour);

renderer.DrawQuad(glowTexture, glowQuad, col);

glowShader.Unbind();
}

private IUniformBuffer<ProgressGlowParameters>? progressGlowParametersBuffer;

private void bindGlowUniformResources(IShader shader, IRenderer renderer)
{
progressGlowParametersBuffer ??= renderer.CreateUniformBuffer<ProgressGlowParameters>();
progressGlowParametersBuffer.Data = new ProgressGlowParameters
{
InnerRadius = InnerRadius,
Progress = Progress,
TexelSize = TexelSize,
GlowSize = relativeGlowSize
};

shader.BindUniformBlock("m_ProgressGlowParameters", progressGlowParametersBuffer);
}

protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
progressGlowParametersBuffer?.Dispose();
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
private record struct ProgressGlowParameters
{
public UniformFloat InnerRadius;
public UniformFloat Progress;
public UniformFloat TexelSize;
public UniformFloat GlowSize;
}
}
}
}
}
4 changes: 2 additions & 2 deletions osu.Game/osu.Game.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Realm" Version="11.5.0" />
<PackageReference Include="ppy.osu.Framework" Version="2023.1124.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2023.1114.0" />
<PackageReference Include="ppy.osu.Framework" Version="2023.1127.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2023.1127.0" />
<PackageReference Include="Sentry" Version="3.40.0" />
<!-- Held back due to 0.34.0 failing AOT compilation on ZstdSharp.dll dependency. -->
<PackageReference Include="SharpCompress" Version="0.33.0" />
Expand Down
2 changes: 1 addition & 1 deletion osu.iOS.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
<RuntimeIdentifier>iossimulator-x64</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ppy.osu.Framework.iOS" Version="2023.1124.0" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2023.1127.0" />
</ItemGroup>
</Project>

0 comments on commit 418dde9

Please sign in to comment.