From cb1e0aa0a7b41181ed0ed490cd5f85283d14119c Mon Sep 17 00:00:00 2001 From: Syntriax Date: Tue, 31 Mar 2026 22:51:59 +0300 Subject: [PATCH] fix: triangle batch not drawing transparent colors properly --- .../Engine.Integration.MonoGame/MonoGameTriangleBatch.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Engine.Integration/Engine.Integration.MonoGame/MonoGameTriangleBatch.cs b/Engine.Integration/Engine.Integration.MonoGame/MonoGameTriangleBatch.cs index da575f6..73cf212 100644 --- a/Engine.Integration/Engine.Integration.MonoGame/MonoGameTriangleBatch.cs +++ b/Engine.Integration/Engine.Integration.MonoGame/MonoGameTriangleBatch.cs @@ -39,7 +39,7 @@ public class MonoGameTriangleBatch : Behaviour, ITriangleBatch, IFirstFrameUpdat Vector2 A = triangle.A.ToVector2(); Vector2 B = triangle.B.ToVector2(); Vector2 C = triangle.C.ToVector2(); - Color color = colorRGBA.ToColor(); + Color color = colorRGBA.ToPreMultipliedColor(); vertices[verticesIndex++] = new(new(A.X, A.Y, 0f), color); vertices[verticesIndex++] = new(new(B.X, B.Y, 0f), color); @@ -60,6 +60,8 @@ public class MonoGameTriangleBatch : Behaviour, ITriangleBatch, IFirstFrameUpdat return; graphicsDevice.RasterizerState = rasterizerState; + graphicsDevice.BlendState = BlendState.AlphaBlend; + basicEffect.Projection = projection; basicEffect.View = view; vertexBuffer.SetData(vertices); @@ -67,8 +69,10 @@ public class MonoGameTriangleBatch : Behaviour, ITriangleBatch, IFirstFrameUpdat graphicsDevice.SetVertexBuffer(vertexBuffer); foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes) + { pass.Apply(); - graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, verticesIndex / 3); + graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, verticesIndex / 3); + } verticesIndex = 0; }