Merge pull request #21446 from EVAST9919/trianglesV2-fix

Improve TrianglesV2 antialiasing
This commit is contained in:
Dan Balasescu
2022-11-29 13:44:17 +09:00
committed by GitHub

View File

@ -227,6 +227,9 @@ namespace osu.Game.Graphics.Backgrounds
private Texture texture = null!; private Texture texture = null!;
private readonly List<TriangleParticle> parts = new List<TriangleParticle>(); private readonly List<TriangleParticle> parts = new List<TriangleParticle>();
private readonly Vector2 triangleSize = new Vector2(1f, equilateral_triangle_ratio) * triangle_size;
private Vector2 size; private Vector2 size;
private float thickness; private float thickness;
private float texelSize; private float texelSize;
@ -246,7 +249,15 @@ namespace osu.Game.Graphics.Backgrounds
texture = Source.texture; texture = Source.texture;
size = Source.DrawSize; size = Source.DrawSize;
thickness = Source.Thickness; thickness = Source.Thickness;
texelSize = Math.Max(1.5f / Source.ScreenSpaceDrawQuad.Size.X, 1.5f / Source.ScreenSpaceDrawQuad.Size.Y);
Quad triangleQuad = new Quad(
Vector2Extensions.Transform(Vector2.Zero, DrawInfo.Matrix),
Vector2Extensions.Transform(new Vector2(triangle_size, 0f), DrawInfo.Matrix),
Vector2Extensions.Transform(new Vector2(0f, triangleSize.Y), DrawInfo.Matrix),
Vector2Extensions.Transform(triangleSize, DrawInfo.Matrix)
);
texelSize = 1.5f / triangleQuad.Height;
parts.Clear(); parts.Clear();
parts.AddRange(Source.parts); parts.AddRange(Source.parts);
@ -256,7 +267,7 @@ namespace osu.Game.Graphics.Backgrounds
{ {
base.Draw(renderer); base.Draw(renderer);
if (Source.AimCount == 0) if (Source.AimCount == 0 || thickness == 0)
return; return;
if (vertexBatch == null || vertexBatch.Size != Source.AimCount) if (vertexBatch == null || vertexBatch.Size != Source.AimCount)
@ -269,14 +280,15 @@ namespace osu.Game.Graphics.Backgrounds
shader.GetUniform<float>("thickness").UpdateValue(ref thickness); shader.GetUniform<float>("thickness").UpdateValue(ref thickness);
shader.GetUniform<float>("texelSize").UpdateValue(ref texelSize); shader.GetUniform<float>("texelSize").UpdateValue(ref texelSize);
float texturePartWidth = triangleSize.X / size.X;
float texturePartHeight = triangleSize.Y / size.Y * texture_height;
foreach (TriangleParticle particle in parts) foreach (TriangleParticle particle in parts)
{ {
var offset = triangle_size * new Vector2(0.5f, equilateral_triangle_ratio); Vector2 topLeft = particle.Position * size - new Vector2(triangleSize.X * 0.5f, 0f);
Vector2 topRight = topLeft + new Vector2(triangleSize.X, 0f);
Vector2 topLeft = particle.Position * size + new Vector2(-offset.X, 0f); Vector2 bottomLeft = topLeft + new Vector2(0f, triangleSize.Y);
Vector2 topRight = particle.Position * size + new Vector2(offset.X, 0); Vector2 bottomRight = topLeft + triangleSize;
Vector2 bottomLeft = particle.Position * size + new Vector2(-offset.X, offset.Y);
Vector2 bottomRight = particle.Position * size + new Vector2(offset.X, offset.Y);
var drawQuad = new Quad( var drawQuad = new Quad(
Vector2Extensions.Transform(topLeft, DrawInfo.Matrix), Vector2Extensions.Transform(topLeft, DrawInfo.Matrix),
@ -288,8 +300,8 @@ namespace osu.Game.Graphics.Backgrounds
var tRect = new Quad( var tRect = new Quad(
topLeft.X / size.X, topLeft.X / size.X,
topLeft.Y / size.Y * texture_height, topLeft.Y / size.Y * texture_height,
(topRight.X - topLeft.X) / size.X, texturePartWidth,
(bottomRight.Y - topRight.Y) / size.Y * texture_height texturePartHeight
).AABBFloat; ).AABBFloat;
renderer.DrawQuad(texture, drawQuad, DrawColourInfo.Colour, tRect, vertexBatch.AddAction, textureCoords: tRect); renderer.DrawQuad(texture, drawQuad, DrawColourInfo.Colour, tRect, vertexBatch.AddAction, textureCoords: tRect);