Implements blend modes (#3740)

Closes https://github.com/space-wizards/RobustToolbox/issues/3739
This commit is contained in:
deathride58
2023-01-28 06:56:31 -05:00
committed by GitHub
parent b8a254db3b
commit 0cb1cd4896
2 changed files with 23 additions and 1 deletions

View File

@@ -243,6 +243,8 @@ namespace Robust.Client.Graphics.Clyde
program.SetUniformMaybe(UniITexturePixelSize, Vector2.One / loadedTexture.Size);
SetBlendFunc(loaded.BlendMode);
var primitiveType = MapPrimitiveType(command.PrimitiveType);
if (command.Indexed)
{
@@ -256,6 +258,9 @@ namespace Robust.Client.Graphics.Clyde
CheckGlError();
}
ResetBlendFunc();
GL.BlendEquation(BlendEquationMode.FuncAdd);
_debugStats.LastGLDrawCalls += 1;
}
@@ -869,6 +874,23 @@ namespace Robust.Client.Graphics.Clyde
GL.Viewport(0, 0, _mainWindow!.FramebufferSize.X, _mainWindow!.FramebufferSize.Y);
}
private void SetBlendFunc(ShaderBlendMode blend)
{
switch (blend)
{
case ShaderBlendMode.Add:
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.DstAlpha);
break;
case ShaderBlendMode.Subtract:
GL.BlendFuncSeparate(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.DstAlpha, BlendingFactorSrc.Zero, BlendingFactorDest.DstAlpha);
GL.BlendEquation(BlendEquationMode.FuncReverseSubtract);
break;
case ShaderBlendMode.Multiply:
GL.BlendFunc(BlendingFactor.DstColor, BlendingFactor.OneMinusSrcAlpha);
break;
}
}
private void ResetBlendFunc()
{
GL.BlendFuncSeparate(

View File

@@ -90,7 +90,7 @@ namespace Robust.Client.Graphics
}
else if (word.Word == "blend_mode")
{
if (lightMode != null)
if (blendMode != null)
{
throw new ShaderParseException("Already specified 'blend_mode' before!");
}