Add blend space drawing in Multi Blend 2D editor

#1980
This commit is contained in:
Wojtek Figat
2024-12-10 10:42:40 +01:00
parent 3e5cb09381
commit 09414f9002
4 changed files with 395 additions and 94 deletions

View File

@@ -301,12 +301,12 @@ void WriteTri(const Float2& p0, const Float2& p1, const Float2& p2, const Float2
IBIndex += 3;
}
void WriteTri(const Float2& p0, const Float2& p1, const Float2& p2, const Color& color0, const Color& color1, const Color& color2)
FORCE_INLINE void WriteTri(const Float2& p0, const Float2& p1, const Float2& p2, const Color& color0, const Color& color1, const Color& color2)
{
WriteTri(p0, p1, p2, Float2::Zero, Float2::Zero, Float2::Zero, color0, color1, color2);
}
void WriteTri(const Float2& p0, const Float2& p1, const Float2& p2, const Float2& uv0, const Float2& uv1, const Float2& uv2)
FORCE_INLINE void WriteTri(const Float2& p0, const Float2& p1, const Float2& p2, const Float2& uv0, const Float2& uv1, const Float2& uv2)
{
WriteTri(p0, p1, p2, uv0, uv1, uv2, Color::Black, Color::Black, Color::Black);
}
@@ -1816,8 +1816,8 @@ void DrawLines(const Float2* points, int32 pointsCount, const Color& color1, con
// Ending cap
{
ApplyTransform(points[0], p1t);
ApplyTransform(points[1], p2t);
ApplyTransform(points[pointsCount - 2], p1t);
//ApplyTransform(points[pointsCount - 1], p2t);
const Float2 capDirection = thicknessHalf * Float2::Normalize(p2t - p1t);
@@ -1962,9 +1962,56 @@ void Render2D::DrawBlur(const Rectangle& rect, float blurStrength)
WriteRect(rect, Color::White);
}
void Render2D::DrawTriangles(const Span<Float2>& vertices, const Color& color, float thickness)
{
RENDER2D_CHECK_RENDERING_STATE;
CHECK(vertices.Length() % 3 == 0);
Float2 points[2];
for (int32 i = 0; i < vertices.Length(); i += 3)
{
#if 0
// TODO: fix this
DrawLines(&vertices.Get()[i], 3, color, color, thickness);
#else
points[0] = vertices.Get()[i + 0];
points[1] = vertices.Get()[i + 1];
DrawLines(points, 2, color, color, thickness);
points[0] = vertices.Get()[i + 2];
DrawLines(points, 2, color, color, thickness);
points[1] = vertices.Get()[i + 0];
DrawLines(points, 2, color, color, thickness);
#endif
}
}
void Render2D::DrawTriangles(const Span<Float2>& vertices, const Span<Color>& colors, float thickness)
{
RENDER2D_CHECK_RENDERING_STATE;
CHECK(vertices.Length() % 3 == 0);
Float2 points[2];
Color cols[2];
for (int32 i = 0; i < vertices.Length(); i += 3)
{
points[0] = vertices.Get()[i + 0];
points[1] = vertices.Get()[i + 1];
cols[0] = colors.Get()[i + 0];
cols[1] = colors.Get()[i + 1];
DrawLines(points, 2, cols[0], cols[1], thickness);
points[0] = vertices.Get()[i + 2];
cols[0] = colors.Get()[i + 2];
DrawLines(points, 2, cols[0], cols[1], thickness);
points[1] = vertices.Get()[i + 0];
cols[1] = colors.Get()[i + 0];
DrawLines(points, 2, cols[0], cols[1], thickness);
}
}
void Render2D::DrawTexturedTriangles(GPUTexture* t, const Span<Float2>& vertices, const Span<Float2>& uvs)
{
RENDER2D_CHECK_RENDERING_STATE;
CHECK(vertices.Length() % 3 == 0);
CHECK(vertices.Length() == uvs.Length());
Render2DDrawCall& drawCall = DrawCalls.AddOne();
@@ -1979,14 +2026,24 @@ void Render2D::DrawTexturedTriangles(GPUTexture* t, const Span<Float2>& vertices
void Render2D::DrawTexturedTriangles(GPUTexture* t, const Span<Float2>& vertices, const Span<Float2>& uvs, const Color& color)
{
Color colors[3] = { (Color)color, (Color)color, (Color)color };
Span<Color> spancolor(colors, 3);
DrawTexturedTriangles(t, vertices, uvs, spancolor);
RENDER2D_CHECK_RENDERING_STATE;
CHECK(vertices.Length() % 3 == 0);
CHECK(vertices.Length() == uvs.Length());
Render2DDrawCall& drawCall = DrawCalls.AddOne();
drawCall.Type = DrawCallType::FillTexture;
drawCall.StartIB = IBIndex;
drawCall.CountIB = vertices.Length();
drawCall.AsTexture.Ptr = t;
for (int32 i = 0; i < vertices.Length(); i += 3)
WriteTri(vertices[i], vertices[i + 1], vertices[i + 2], uvs[i], uvs[i + 1], uvs[i + 2], color, color, color);
}
void Render2D::DrawTexturedTriangles(GPUTexture* t, const Span<Float2>& vertices, const Span<Float2>& uvs, const Span<Color>& colors)
{
RENDER2D_CHECK_RENDERING_STATE;
CHECK(vertices.Length() % 3 == 0);
CHECK(vertices.Length() == uvs.Length());
CHECK(vertices.Length() == colors.Length());
@@ -2021,6 +2078,19 @@ void Render2D::DrawTexturedTriangles(GPUTexture* t, const Span<uint16>& indices,
}
}
void Render2D::FillTriangles(const Span<Float2>& vertices, const Color& color)
{
RENDER2D_CHECK_RENDERING_STATE;
Render2DDrawCall& drawCall = DrawCalls.AddOne();
drawCall.Type = NeedAlphaWithTint(color) ? DrawCallType::FillRect : DrawCallType::FillRectNoAlpha;
drawCall.StartIB = IBIndex;
drawCall.CountIB = vertices.Length();
for (int32 i = 0; i < vertices.Length(); i += 3)
WriteTri(vertices[i], vertices[i + 1], vertices[i + 2], color, color, color);
}
void Render2D::FillTriangles(const Span<Float2>& vertices, const Span<Color>& colors, bool useAlpha)
{
CHECK(vertices.Length() == colors.Length());

View File

@@ -415,6 +415,22 @@ public:
/// <param name="blurStrength">The blur strength defines how blurry the background is. Larger numbers increase blur, resulting in a larger runtime cost on the GPU.</param>
API_FUNCTION() static void DrawBlur(const Rectangle& rect, float blurStrength);
/// <summary>
/// Draws vertices array.
/// </summary>
/// <param name="vertices">The vertices array.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The line thickness.</param>
API_FUNCTION() static void DrawTriangles(const Span<Float2>& vertices, const Color& color, float thickness = 1.0f);
/// <summary>
/// Draws vertices array.
/// </summary>
/// <param name="vertices">The vertices array.</param>
/// <param name="colors">The colors array.</param>
/// <param name="thickness">The line thickness.</param>
API_FUNCTION() static void DrawTriangles(const Span<Float2>& vertices, const Span<Color>& colors, float thickness = 1.0f);
/// <summary>
/// Draws vertices array.
/// </summary>
@@ -451,13 +467,20 @@ public:
/// <param name="colors">The colors array.</param>
API_FUNCTION() static void DrawTexturedTriangles(GPUTexture* t, const Span<uint16>& indices, const Span<Float2>& vertices, const Span<Float2>& uvs, const Span<Color>& colors);
/// <summary>
/// Draws vertices array.
/// </summary>
/// <param name="vertices">The vertices array.</param>
/// <param name="color">The color.</param>
API_FUNCTION() static void FillTriangles(const Span<Float2>& vertices, const Color& color);
/// <summary>
/// Draws vertices array.
/// </summary>
/// <param name="vertices">The vertices array.</param>
/// <param name="colors">The colors array.</param>
/// <param name="useAlpha">If true alpha blending will be enabled.</param>
API_FUNCTION() static void FillTriangles(const Span<Float2>& vertices, const Span<Color>& colors, bool useAlpha);
API_FUNCTION() static void FillTriangles(const Span<Float2>& vertices, const Span<Color>& colors, bool useAlpha = true);
/// <summary>
/// Fills a triangular area.