1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 15:03:13 +08:00

Merge pull request #22883 from smoogipoo/fix-logo-animation

Use custom vertex shader for logo animation
This commit is contained in:
Dean Herbert 2023-03-20 16:36:43 +09:00 committed by GitHub
commit bec28cc7f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 3 deletions

View File

@ -3,13 +3,18 @@
#nullable disable
using System;
using System.Runtime.InteropServices;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Rendering.Vertices;
using osu.Framework.Graphics.Shaders;
using osu.Framework.Graphics.Shaders.Types;
using osu.Framework.Graphics.Sprites;
using osuTK;
using osuTK.Graphics;
using osuTK.Graphics.ES30;
namespace osu.Game.Graphics.Sprites
{
@ -18,7 +23,7 @@ namespace osu.Game.Graphics.Sprites
[BackgroundDependencyLoader]
private void load(ShaderManager shaders)
{
TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, @"LogoAnimation");
TextureShader = shaders.Load(@"LogoAnimation", @"LogoAnimation");
}
private float animationProgress;
@ -43,11 +48,22 @@ namespace osu.Game.Graphics.Sprites
{
private LogoAnimation source => (LogoAnimation)Source;
private readonly Action<TexturedVertex2D> addVertexAction;
private float progress;
public LogoAnimationDrawNode(LogoAnimation source)
: base(source)
{
addVertexAction = v =>
{
animationVertexBatch!.Add(new LogoAnimationVertex
{
Position = v.Position,
Colour = v.Colour,
TexturePosition = v.TexturePosition,
});
};
}
public override void ApplyState()
@ -58,15 +74,27 @@ namespace osu.Game.Graphics.Sprites
}
private IUniformBuffer<AnimationData> animationDataBuffer;
private IVertexBatch<LogoAnimationVertex> animationVertexBatch;
protected override void Blit(IRenderer renderer)
{
if (DrawRectangle.Width == 0 || DrawRectangle.Height == 0)
return;
animationDataBuffer ??= renderer.CreateUniformBuffer<AnimationData>();
animationVertexBatch ??= renderer.CreateQuadBatch<LogoAnimationVertex>(1, 2);
animationDataBuffer.Data = animationDataBuffer.Data with { Progress = progress };
TextureShader.BindUniformBlock("m_AnimationData", animationDataBuffer);
base.Blit(renderer);
renderer.DrawQuad(
Texture,
ScreenSpaceDrawQuad,
DrawColourInfo.Colour,
inflationPercentage: new Vector2(InflationAmount.X / DrawRectangle.Width, InflationAmount.Y / DrawRectangle.Height),
textureCoords: TextureCoords,
vertexAction: addVertexAction);
}
protected override bool CanDrawOpaqueInterior => false;
@ -83,6 +111,24 @@ namespace osu.Game.Graphics.Sprites
public UniformFloat Progress;
private readonly UniformPadding12 pad1;
}
[StructLayout(LayoutKind.Sequential)]
private struct LogoAnimationVertex : IEquatable<LogoAnimationVertex>, IVertex
{
[VertexMember(2, VertexAttribPointerType.Float)]
public Vector2 Position;
[VertexMember(4, VertexAttribPointerType.Float)]
public Color4 Colour;
[VertexMember(2, VertexAttribPointerType.Float)]
public Vector2 TexturePosition;
public readonly bool Equals(LogoAnimationVertex other) =>
Position.Equals(other.Position)
&& TexturePosition.Equals(other.TexturePosition)
&& Colour.Equals(other.Colour);
}
}
}
}

View File

@ -37,7 +37,7 @@
</PackageReference>
<PackageReference Include="Realm" Version="10.20.0" />
<PackageReference Include="ppy.osu.Framework" Version="2023.314.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2023.314.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2023.320.0" />
<PackageReference Include="Sentry" Version="3.28.1" />
<PackageReference Include="SharpCompress" Version="0.32.2" />
<PackageReference Include="NUnit" Version="3.13.3" />