Skip to content

Commit

Permalink
Merge pull request #5987 from smoogipoo/fix-broken-path-masking
Browse files Browse the repository at this point in the history
Fix masking broken with TexturedVertex3D
  • Loading branch information
peppy authored Sep 11, 2023
2 parents fc5cd7e + 59b1002 commit 3f83dc3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
46 changes: 23 additions & 23 deletions osu.Framework/Graphics/Lines/Path_DrawNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public override void Draw(IRenderer renderer)

texture.Bind();

updateVertexBuffer();
updateVertexBuffer(renderer);

pathShader.Unbind();

Expand All @@ -88,7 +88,7 @@ private Color4 colourAt(Vector2 localPos) => DrawColourInfo.Colour.TryExtractSin
? colour.SRGB
: DrawColourInfo.Colour.Interpolate(relativePosition(localPos)).SRGB;

private void addSegmentQuads(Line segment, Line segmentLeft, Line segmentRight, RectangleF texRect)
private void addSegmentQuads(IRenderer renderer, Line segment, Line segmentLeft, Line segmentRight, RectangleF texRect)
{
Debug.Assert(triangleBatch != null);

Expand All @@ -101,87 +101,87 @@ private void addSegmentQuads(Line segment, Line segmentLeft, Line segmentRight,

// Each of the quads (mentioned above) is rendered as 2 triangles:
// Outer quad, triangle 1
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = new Vector3(segmentRight.EndPoint.X, segmentRight.EndPoint.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Colour = colourAt(segmentRight.EndPoint)
});
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = new Vector3(segmentRight.StartPoint.X, segmentRight.StartPoint.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Colour = colourAt(segmentRight.StartPoint)
});
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = firstMiddlePoint,
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = firstMiddleColour
});

// Outer quad, triangle 2
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = firstMiddlePoint,
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = firstMiddleColour
});
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = secondMiddlePoint,
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = secondMiddleColour
});
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = new Vector3(segmentRight.EndPoint.X, segmentRight.EndPoint.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Colour = colourAt(segmentRight.EndPoint)
});

// Inner quad, triangle 1
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = firstMiddlePoint,
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = firstMiddleColour
});
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = secondMiddlePoint,
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = secondMiddleColour
});
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = new Vector3(segmentLeft.EndPoint.X, segmentLeft.EndPoint.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Colour = colourAt(segmentLeft.EndPoint)
});

// Inner quad, triangle 2
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = new Vector3(segmentLeft.EndPoint.X, segmentLeft.EndPoint.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Colour = colourAt(segmentLeft.EndPoint)
});
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = new Vector3(segmentLeft.StartPoint.X, segmentLeft.StartPoint.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Colour = colourAt(segmentLeft.StartPoint)
});
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = firstMiddlePoint,
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = firstMiddleColour
});
}

private void addSegmentCaps(float thetaDiff, Line segmentLeft, Line segmentRight, Line prevSegmentLeft, Line prevSegmentRight, RectangleF texRect)
private void addSegmentCaps(IRenderer renderer, float thetaDiff, Line segmentLeft, Line segmentRight, Line prevSegmentLeft, Line prevSegmentRight, RectangleF texRect)
{
Debug.Assert(triangleBatch != null);

Expand Down Expand Up @@ -210,15 +210,15 @@ private void addSegmentCaps(float thetaDiff, Line segmentLeft, Line segmentRight
for (int i = 1; i <= stepCount; i++)
{
// Center point
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = new Vector3(origin.X, origin.Y, 1),
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = originColour
});

// First outer point
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = new Vector3(current.X, current.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Expand All @@ -229,7 +229,7 @@ private void addSegmentCaps(float thetaDiff, Line segmentLeft, Line segmentRight
currentColour = colourAt(current);

// Second outer point
triangleBatch.Add(new TexturedVertex3D
triangleBatch.Add(new TexturedVertex3D(renderer)
{
Position = new Vector3(current.X, current.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Expand All @@ -238,7 +238,7 @@ private void addSegmentCaps(float thetaDiff, Line segmentLeft, Line segmentRight
}
}

private void updateVertexBuffer()
private void updateVertexBuffer(IRenderer renderer)
{
// Explanation of the terms "left" and "right":
// "Left" and "right" are used here in terms of a typical (Cartesian) coordinate system.
Expand Down Expand Up @@ -277,15 +277,15 @@ private void updateVertexBuffer()
Line currSegmentLeft = new Line(currSegment.StartPoint + ortho * radius, currSegment.EndPoint + ortho * radius);
Line currSegmentRight = new Line(currSegment.StartPoint - ortho * radius, currSegment.EndPoint - ortho * radius);

addSegmentQuads(currSegment, currSegmentLeft, currSegmentRight, texRect);
addSegmentQuads(renderer, currSegment, currSegmentLeft, currSegmentRight, texRect);

if (prevSegmentLeft is Line psLeft && prevSegmentRight is Line psRight)
{
Debug.Assert(i > 0);

// Connection/filler caps between segment quads
float thetaDiff = currSegment.Theta - segments[i - 1].Theta;
addSegmentCaps(thetaDiff, currSegmentLeft, currSegmentRight, psLeft, psRight, texRect);
addSegmentCaps(renderer, thetaDiff, currSegmentLeft, currSegmentRight, psLeft, psRight, texRect);
}

// Explanation of semi-circle caps:
Expand All @@ -300,7 +300,7 @@ private void updateVertexBuffer()
Line flippedLeft = new Line(currSegmentRight.EndPoint, currSegmentRight.StartPoint);
Line flippedRight = new Line(currSegmentLeft.EndPoint, currSegmentLeft.StartPoint);

addSegmentCaps(MathF.PI, currSegmentLeft, currSegmentRight, flippedLeft, flippedRight, texRect);
addSegmentCaps(renderer, MathF.PI, currSegmentLeft, currSegmentRight, flippedLeft, flippedRight, texRect);
}

if (i == segments.Count - 1)
Expand All @@ -309,7 +309,7 @@ private void updateVertexBuffer()
Line flippedLeft = new Line(currSegmentRight.EndPoint, currSegmentRight.StartPoint);
Line flippedRight = new Line(currSegmentLeft.EndPoint, currSegmentLeft.StartPoint);

addSegmentCaps(MathF.PI, flippedLeft, flippedRight, currSegmentLeft, currSegmentRight, texRect);
addSegmentCaps(renderer, MathF.PI, flippedLeft, flippedRight, currSegmentLeft, currSegmentRight, texRect);
}

prevSegmentLeft = currSegmentLeft;
Expand Down
12 changes: 12 additions & 0 deletions osu.Framework/Graphics/Rendering/Vertices/TexturedVertex3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ public struct TexturedVertex3D : IEquatable<TexturedVertex3D>, IVertex
[VertexMember(1, VertexAttribPointerType.Int)]
private readonly int maskingIndex;

[Obsolete("Initialise this type with an IRenderer instead", true)]
public TexturedVertex3D()
{
this = default; // explicitly initialise all members to default values
}

public TexturedVertex3D(IRenderer renderer)
{
this = default; // explicitly initialise all members to default values
maskingIndex = renderer.CurrentMaskingIndex;
}

public readonly bool Equals(TexturedVertex3D other)
=> Position.Equals(other.Position)
&& TexturePosition.Equals(other.TexturePosition)
Expand Down

0 comments on commit 3f83dc3

Please sign in to comment.