Fix Render2D.DrawRectangle to avoid alpha overdraw on the corners when thickness is large
This commit is contained in:
@@ -1440,8 +1440,28 @@ void Render2D::DrawRectangle(const Rectangle& rect, const Color& color1, const C
|
||||
RENDER2D_CHECK_RENDERING_STATE;
|
||||
|
||||
const auto& mask = ClipLayersStack.Peek().Mask;
|
||||
float thick = thickness;
|
||||
thickness *= (TransformCached.M11 + TransformCached.M22 + TransformCached.M33) * 0.3333333f;
|
||||
|
||||
// When lines thickness is very large, don't use corner caps and place line ends to not overlap
|
||||
if (thickness > 4.0f)
|
||||
{
|
||||
thick *= Math::Lerp(0.6f, 1.0f, Math::Saturate(thick - 4.0f)); // Smooth transition between soft LineAA and harsh FillRect
|
||||
Float2 totalMin = rect.GetUpperLeft() - Float2(thick * 0.5f);
|
||||
Float2 totalMax = rect.GetBottomRight() + Float2(thick * 0.5f);
|
||||
Float2 size = totalMax - totalMin;
|
||||
Render2DDrawCall& drawCall = DrawCalls.AddOne();
|
||||
drawCall.Type = NeedAlphaWithTint(color1, color2, color3, color4) ? DrawCallType::FillRect : DrawCallType::FillRectNoAlpha;
|
||||
drawCall.StartIB = IBIndex;
|
||||
drawCall.CountIB = 6 * 4;
|
||||
// TODO: interpolate colors from corners to extended rectangle edges properly
|
||||
WriteRect(Rectangle(totalMin.X, totalMin.Y, size.X, thick), color1, color2, color2, color1);
|
||||
WriteRect(Rectangle(totalMin.X, totalMin.Y + rect.Size.Y, size.X, thick), color4, color3, color3, color4);
|
||||
WriteRect(Rectangle(totalMin.X, totalMin.Y + thick, thick, rect.Size.Y - thick), color1, color1, color4, color4);
|
||||
WriteRect(Rectangle(totalMax.X - thick, totalMin.Y + thick, thick, rect.Size.Y - thick), color2, color2, color3, color3);
|
||||
return;
|
||||
}
|
||||
|
||||
Float2 points[5];
|
||||
ApplyTransform(rect.GetUpperLeft(), points[0]);
|
||||
ApplyTransform(rect.GetUpperRight(), points[1]);
|
||||
|
||||
Reference in New Issue
Block a user