mirror of
https://github.com/ppy/osu.git
synced 2025-01-06 08:22:56 +08:00
Implement Masking property for TrianglesBackground
This commit is contained in:
parent
67e9de43be
commit
d09d6f31d7
@ -15,6 +15,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default
|
|||||||
{
|
{
|
||||||
TriangleScale = 1.2f;
|
TriangleScale = 1.2f;
|
||||||
HideAlphaDiscrepancies = false;
|
HideAlphaDiscrepancies = false;
|
||||||
|
Masking = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
|
@ -5,6 +5,7 @@ using osu.Game.Graphics.Backgrounds;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Background
|
namespace osu.Game.Tests.Visual.Background
|
||||||
{
|
{
|
||||||
@ -25,7 +26,10 @@ namespace osu.Game.Tests.Visual.Background
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
ColourLight = Color4.White,
|
ColourLight = Color4.White,
|
||||||
ColourDark = Color4.Gray
|
ColourDark = Color4.Gray,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Size = new Vector2(0.9f)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -36,6 +40,7 @@ namespace osu.Game.Tests.Visual.Background
|
|||||||
|
|
||||||
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));
|
AddSliderStep("Seed", 0, 1000, 0, s => triangles.Reset(s));
|
||||||
|
AddToggleStep("Masking", m => triangles.Masking = m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,6 +77,12 @@ namespace osu.Game.Graphics.Backgrounds
|
|||||||
set => triangleScale.Value = value;
|
set => triangleScale.Value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If enabled, only the portion of triangles that falls within this <see cref="Drawable"/>'s
|
||||||
|
/// shape is drawn to the screen.
|
||||||
|
/// </summary>
|
||||||
|
public bool Masking { get; set; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether we should drop-off alpha values of triangles more quickly to improve
|
/// Whether we should drop-off alpha values of triangles more quickly to improve
|
||||||
/// the visual appearance of fading. This defaults to on as it is generally more
|
/// the visual appearance of fading. This defaults to on as it is generally more
|
||||||
@ -252,6 +258,7 @@ namespace osu.Game.Graphics.Backgrounds
|
|||||||
|
|
||||||
private IShader shader;
|
private IShader shader;
|
||||||
private Texture texture;
|
private Texture texture;
|
||||||
|
private bool masking;
|
||||||
|
|
||||||
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 readonly Vector2 triangleSize = new Vector2(1f, equilateral_triangle_ratio) * triangle_size;
|
||||||
@ -271,6 +278,7 @@ namespace osu.Game.Graphics.Backgrounds
|
|||||||
shader = Source.shader;
|
shader = Source.shader;
|
||||||
texture = Source.texture;
|
texture = Source.texture;
|
||||||
size = Source.DrawSize;
|
size = Source.DrawSize;
|
||||||
|
masking = Source.Masking;
|
||||||
|
|
||||||
parts.Clear();
|
parts.Clear();
|
||||||
parts.AddRange(Source.parts);
|
parts.AddRange(Source.parts);
|
||||||
@ -294,26 +302,45 @@ namespace osu.Game.Graphics.Backgrounds
|
|||||||
Vector2 relativeSize = Vector2.Divide(triangleSize * particle.Scale, size);
|
Vector2 relativeSize = Vector2.Divide(triangleSize * particle.Scale, size);
|
||||||
|
|
||||||
Vector2 topLeft = particle.Position - new Vector2(relativeSize.X * 0.5f, 0f);
|
Vector2 topLeft = particle.Position - new Vector2(relativeSize.X * 0.5f, 0f);
|
||||||
Vector2 topRight = topLeft + new Vector2(relativeSize.X, 0f);
|
|
||||||
Vector2 bottomLeft = topLeft + new Vector2(0f, relativeSize.Y);
|
Quad triangleQuad = masking ? clampToDrawable(topLeft, relativeSize) : new Quad(topLeft.X, topLeft.Y, relativeSize.X, relativeSize.Y);
|
||||||
Vector2 bottomRight = bottomLeft + new Vector2(relativeSize.X, 0f);
|
|
||||||
|
|
||||||
var drawQuad = new Quad(
|
var drawQuad = new Quad(
|
||||||
Vector2Extensions.Transform(topLeft * size, DrawInfo.Matrix),
|
Vector2Extensions.Transform(triangleQuad.TopLeft * size, DrawInfo.Matrix),
|
||||||
Vector2Extensions.Transform(topRight * size, DrawInfo.Matrix),
|
Vector2Extensions.Transform(triangleQuad.TopRight * size, DrawInfo.Matrix),
|
||||||
Vector2Extensions.Transform(bottomLeft * size, DrawInfo.Matrix),
|
Vector2Extensions.Transform(triangleQuad.BottomLeft * size, DrawInfo.Matrix),
|
||||||
Vector2Extensions.Transform(bottomRight * size, DrawInfo.Matrix)
|
Vector2Extensions.Transform(triangleQuad.BottomRight * size, DrawInfo.Matrix)
|
||||||
);
|
);
|
||||||
|
|
||||||
ColourInfo colourInfo = DrawColourInfo.Colour;
|
ColourInfo colourInfo = DrawColourInfo.Colour;
|
||||||
colourInfo.ApplyChild(particle.Colour);
|
colourInfo.ApplyChild(particle.Colour);
|
||||||
|
|
||||||
renderer.DrawQuad(texture, drawQuad, colourInfo, vertexAction: vertexBatch.AddAction);
|
RectangleF textureCoords = new RectangleF(
|
||||||
|
triangleQuad.TopLeft.X - topLeft.X,
|
||||||
|
triangleQuad.TopLeft.Y - topLeft.Y,
|
||||||
|
triangleQuad.Width,
|
||||||
|
triangleQuad.Height
|
||||||
|
) / relativeSize;
|
||||||
|
|
||||||
|
renderer.DrawQuad(texture, drawQuad, colourInfo, new RectangleF(0, 0, 1, 1), vertexBatch.AddAction, textureCoords: textureCoords);
|
||||||
}
|
}
|
||||||
|
|
||||||
shader.Unbind();
|
shader.Unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Quad clampToDrawable(Vector2 topLeft, Vector2 size)
|
||||||
|
{
|
||||||
|
float leftClamped = Math.Clamp(topLeft.X, 0f, 1f);
|
||||||
|
float topClamped = Math.Clamp(topLeft.Y, 0f, 1f);
|
||||||
|
|
||||||
|
return new Quad(
|
||||||
|
leftClamped,
|
||||||
|
topClamped,
|
||||||
|
Math.Clamp(topLeft.X + size.X, 0f, 1f) - leftClamped,
|
||||||
|
Math.Clamp(topLeft.Y + size.Y, 0f, 1f) - topClamped
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
|
Loading…
Reference in New Issue
Block a user