1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 16:42:57 +08:00

Merge pull request #879 from Tom94/fix-triangle-smoothness

Fix triangle smoothness and optimize further
This commit is contained in:
Dean Herbert 2017-05-30 09:15:09 +09:00 committed by GitHub
commit 751e954735

View File

@ -23,6 +23,13 @@ namespace osu.Game.Graphics.Backgrounds
public class Triangles : Drawable
{
private const float triangle_size = 100;
private const float base_velocity = 50;
/// <summary>
/// How many screen-space pixels are smoothed over.
/// Same behavior as Sprite's EdgeSmoothness.
/// </summary>
private const float edge_smoothness = 1;
public override bool HandleInput => false;
@ -103,31 +110,34 @@ namespace osu.Game.Graphics.Backgrounds
Invalidate(Invalidation.DrawNode, shallPropagate: false);
for (int i = 0; i < parts.Count; i++)
{
TriangleParticle newParticle = parts[i];
if (CreateNewTriangles)
addTriangles(false);
float adjustedAlpha = HideAlphaDiscrepancies ?
// Cubically scale alpha to make it drop off more sharply.
(float)Math.Pow(DrawInfo.Colour.AverageColour.Linear.A, 3) :
1;
float elapsedSeconds = (float)Time.Elapsed / 1000;
// Since position is relative, the velocity needs to scale inversely with DrawHeight.
// Since we will later multiply by the scale of individual triangles we normalize by
// dividing by triangleScale.
float movedDistance = -elapsedSeconds * Velocity * base_velocity / (DrawHeight * triangleScale);
newParticle.Position += new Vector2(0, -(parts[i].Scale * (50 / DrawHeight)) / triangleScale * Velocity) * ((float)Time.Elapsed / 950);
for (int i = 0; i < parts.Count; i++)
{
TriangleParticle newParticle = parts[i];
// Scale moved distance by the size of the triangle. Smaller triangles should move more slowly.
newParticle.Position.Y += parts[i].Scale * movedDistance;
newParticle.Colour.A = adjustedAlpha;
parts[i] = newParticle;
if (!CreateNewTriangles)
continue;
float bottomPos = parts[i].Position.Y + triangle_size * parts[i].Scale * 0.866f / DrawHeight;
if (bottomPos < 0)
parts.RemoveAt(i);
}
addTriangles(false);
}
private void addTriangles(bool randomY)
@ -211,20 +221,28 @@ namespace osu.Game.Graphics.Backgrounds
Shader.Bind();
Texture.TextureGL.Bind();
Vector2 localInflationAmount = edge_smoothness * DrawInfo.MatrixInverse.ExtractScale().Xy;
foreach (TriangleParticle particle in Parts)
{
var offset = new Vector2(particle.Scale * 0.5f, particle.Scale * 0.866f);
var offset = triangle_size * new Vector2(particle.Scale * 0.5f, particle.Scale * 0.866f);
var size = new Vector2(2 * offset.X, offset.Y);
var triangle = new Triangle(
particle.Position * Size * DrawInfo.Matrix,
(particle.Position * Size + offset * triangle_size) * DrawInfo.Matrix,
(particle.Position * Size + new Vector2(-offset.X, offset.Y) * triangle_size) * DrawInfo.Matrix
(particle.Position * Size + offset) * DrawInfo.Matrix,
(particle.Position * Size + new Vector2(-offset.X, offset.Y)) * DrawInfo.Matrix
);
ColourInfo colourInfo = DrawInfo.Colour;
colourInfo.ApplyChild(particle.Colour);
Texture.DrawTriangle(triangle, colourInfo, null, Shared.VertexBatch.Add);
Texture.DrawTriangle(
triangle,
colourInfo,
null,
Shared.VertexBatch.Add,
Vector2.Divide(localInflationAmount, size));
}
Shader.Unbind();