1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-22 17:12:54 +08:00

Merge pull request #22386 from EVAST9919/triangles-og-shhader

Use `TriangleBorder` shader in `Triangles` background
This commit is contained in:
Dean Herbert 2023-01-25 17:25:18 +09:00 committed by GitHub
commit 67e9de43be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 22 deletions

View File

@ -35,6 +35,7 @@ namespace osu.Game.Tests.Visual.Background
base.LoadComplete(); base.LoadComplete();
AddSliderStep("Triangle scale", 0f, 10f, 1f, s => triangles.TriangleScale = s); AddSliderStep("Triangle scale", 0f, 10f, 1f, s => triangles.TriangleScale = s);
AddSliderStep("Seed", 0, 1000, 0, s => triangles.Reset(s));
} }
} }
} }

View File

@ -31,12 +31,6 @@ namespace osu.Game.Graphics.Backgrounds
/// </summary> /// </summary>
private const float equilateral_triangle_ratio = 0.866f; private const float equilateral_triangle_ratio = 0.866f;
/// <summary>
/// How many screen-space pixels are smoothed over.
/// Same behavior as Sprite's EdgeSmoothness.
/// </summary>
private const float edge_smoothness = 1;
private Color4 colourLight = Color4.White; private Color4 colourLight = Color4.White;
public Color4 ColourLight public Color4 ColourLight
@ -115,7 +109,7 @@ namespace osu.Game.Graphics.Backgrounds
private void load(IRenderer renderer, ShaderManager shaders) private void load(IRenderer renderer, ShaderManager shaders)
{ {
texture = renderer.WhitePixel; texture = renderer.WhitePixel;
shader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.TEXTURE); shader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "TriangleBorder");
} }
protected override void LoadComplete() protected override void LoadComplete()
@ -252,14 +246,17 @@ namespace osu.Game.Graphics.Backgrounds
private class TrianglesDrawNode : DrawNode private class TrianglesDrawNode : DrawNode
{ {
private float fill = 1f;
protected new Triangles Source => (Triangles)base.Source; protected new Triangles Source => (Triangles)base.Source;
private IShader shader; private IShader shader;
private Texture texture; private Texture texture;
private readonly List<TriangleParticle> parts = new List<TriangleParticle>(); private readonly List<TriangleParticle> parts = new List<TriangleParticle>();
private Vector2 size; private readonly Vector2 triangleSize = new Vector2(1f, equilateral_triangle_ratio) * triangle_size;
private Vector2 size;
private IVertexBatch<TexturedVertex2D> vertexBatch; private IVertexBatch<TexturedVertex2D> vertexBatch;
public TrianglesDrawNode(Triangles source) public TrianglesDrawNode(Triangles source)
@ -290,29 +287,28 @@ namespace osu.Game.Graphics.Backgrounds
} }
shader.Bind(); shader.Bind();
shader.GetUniform<float>("thickness").UpdateValue(ref fill);
Vector2 localInflationAmount = edge_smoothness * DrawInfo.MatrixInverse.ExtractScale().Xy;
foreach (TriangleParticle particle in parts) foreach (TriangleParticle particle in parts)
{ {
var offset = triangle_size * new Vector2(particle.Scale * 0.5f, particle.Scale * equilateral_triangle_ratio); Vector2 relativeSize = Vector2.Divide(triangleSize * particle.Scale, size);
var triangle = new Triangle( Vector2 topLeft = particle.Position - new Vector2(relativeSize.X * 0.5f, 0f);
Vector2Extensions.Transform(particle.Position * size, DrawInfo.Matrix), Vector2 topRight = topLeft + new Vector2(relativeSize.X, 0f);
Vector2Extensions.Transform(particle.Position * size + offset, DrawInfo.Matrix), Vector2 bottomLeft = topLeft + new Vector2(0f, relativeSize.Y);
Vector2Extensions.Transform(particle.Position * size + new Vector2(-offset.X, offset.Y), DrawInfo.Matrix) Vector2 bottomRight = bottomLeft + new Vector2(relativeSize.X, 0f);
var drawQuad = new Quad(
Vector2Extensions.Transform(topLeft * size, DrawInfo.Matrix),
Vector2Extensions.Transform(topRight * size, DrawInfo.Matrix),
Vector2Extensions.Transform(bottomLeft * size, DrawInfo.Matrix),
Vector2Extensions.Transform(bottomRight * size, DrawInfo.Matrix)
); );
ColourInfo colourInfo = DrawColourInfo.Colour; ColourInfo colourInfo = DrawColourInfo.Colour;
colourInfo.ApplyChild(particle.Colour); colourInfo.ApplyChild(particle.Colour);
renderer.DrawTriangle( renderer.DrawQuad(texture, drawQuad, colourInfo, vertexAction: vertexBatch.AddAction);
texture,
triangle,
colourInfo,
null,
vertexBatch.AddAction,
Vector2.Divide(localInflationAmount, new Vector2(2 * offset.X, offset.Y)));
} }
shader.Unbind(); shader.Unbind();