diff --git a/OpenRA.Game/Graphics/IGraphicsDevice.cs b/OpenRA.Game/Graphics/IGraphicsDevice.cs index 2fdafe30d2..87d79cd7cd 100755 --- a/OpenRA.Game/Graphics/IGraphicsDevice.cs +++ b/OpenRA.Game/Graphics/IGraphicsDevice.cs @@ -42,9 +42,7 @@ namespace OpenRA Subtractive, Multiply, SoftAdditive, - Translucency25, - Translucency50, - Translucency75, + Translucency, Multiplicative, DoubleMultiplicative } @@ -72,7 +70,7 @@ namespace OpenRA void EnableDepthBuffer(); void DisableDepthBuffer(); - void SetBlendMode(BlendMode mode); + void SetBlendMode(BlendMode mode, float alpha = 1f); void GrabWindowMouseFocus(); void ReleaseWindowMouseFocus(); diff --git a/OpenRA.Game/Graphics/Sprite.cs b/OpenRA.Game/Graphics/Sprite.cs index 6c2c09df75..7da65692e7 100644 --- a/OpenRA.Game/Graphics/Sprite.cs +++ b/OpenRA.Game/Graphics/Sprite.cs @@ -17,6 +17,7 @@ namespace OpenRA.Graphics public readonly Rectangle Bounds; public readonly Sheet Sheet; public readonly BlendMode BlendMode; + public readonly float Alpha; public readonly TextureChannel Channel; public readonly float2 Size; public readonly float2 Offset; @@ -24,12 +25,9 @@ namespace OpenRA.Graphics public readonly float Top, Left, Bottom, Right; public Sprite(Sheet sheet, Rectangle bounds, TextureChannel channel) - : this(sheet, bounds, float2.Zero, channel, BlendMode.Alpha) { } + : this(sheet, bounds, float2.Zero, channel) { } - public Sprite(Sheet sheet, Rectangle bounds, TextureChannel channel, BlendMode blendMode) - : this(sheet, bounds, float2.Zero, channel, blendMode) { } - - public Sprite(Sheet sheet, Rectangle bounds, float2 offset, TextureChannel channel, BlendMode blendMode) + public Sprite(Sheet sheet, Rectangle bounds, float2 offset, TextureChannel channel, BlendMode blendMode = BlendMode.Alpha, float alpha = 1f) { Sheet = sheet; Bounds = bounds; @@ -37,6 +35,7 @@ namespace OpenRA.Graphics Channel = channel; Size = new float2(bounds.Size); BlendMode = blendMode; + Alpha = alpha; FractionalOffset = offset / Size; diff --git a/OpenRA.Game/Graphics/SpriteRenderer.cs b/OpenRA.Game/Graphics/SpriteRenderer.cs index 356819eb2f..941201082a 100644 --- a/OpenRA.Game/Graphics/SpriteRenderer.cs +++ b/OpenRA.Game/Graphics/SpriteRenderer.cs @@ -21,6 +21,7 @@ namespace OpenRA.Graphics readonly Vertex[] vertices; Sheet currentSheet; BlendMode currentBlend = BlendMode.Alpha; + float currentAlpha = 1f; int nv = 0; public SpriteRenderer(Renderer renderer, IShader shader) @@ -36,14 +37,14 @@ namespace OpenRA.Graphics { shader.SetTexture("DiffuseTexture", currentSheet.GetTexture()); - renderer.Device.SetBlendMode(currentBlend); + renderer.Device.SetBlendMode(currentBlend, currentAlpha); shader.Render(() => { var vb = renderer.GetTempVertexBuffer(); vb.SetData(vertices, nv); renderer.DrawBatch(vb, 0, nv, PrimitiveType.QuadList); }); - renderer.Device.SetBlendMode(BlendMode.None); + renderer.Device.SetBlendMode(BlendMode.None, currentAlpha); nv = 0; currentSheet = null; @@ -54,9 +55,10 @@ namespace OpenRA.Graphics { renderer.CurrentBatchRenderer = this; - if (s.Sheet != currentSheet || s.BlendMode != currentBlend || nv + 4 > renderer.TempBufferSize) + if (s.Alpha != currentAlpha || s.BlendMode != currentBlend || s.Sheet != currentSheet || nv + 4 > renderer.TempBufferSize) Flush(); + currentAlpha = s.Alpha; currentBlend = s.BlendMode; currentSheet = s.Sheet; } diff --git a/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs b/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs index 89cbdcdad2..f89937090e 100644 --- a/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs +++ b/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs @@ -119,12 +119,13 @@ namespace OpenRA.Mods.Common.Graphics var offset = LoadField(d, "Offset", float2.Zero); var blendMode = LoadField(d, "BlendMode", BlendMode.Alpha); + var alpha = LoadField(d, "Alpha", 1f); // Apply offset to each sprite in the sequence // Different sequences may apply different offsets to the same frame var src = GetSpriteSrc(modData, tileSet, sequence, animation, info.Value, d); sprites = cache[src].Select( - s => new Sprite(s.Sheet, s.Bounds, s.Offset + offset, s.Channel, blendMode)).ToArray(); + s => new Sprite(s.Sheet, s.Bounds, s.Offset + offset, s.Channel, blendMode, alpha)).ToArray(); MiniYaml length; if (d.TryGetValue("Length", out length) && length.Value == "*") diff --git a/OpenRA.Renderer.Null/NullGraphicsDevice.cs b/OpenRA.Renderer.Null/NullGraphicsDevice.cs index c69b7bf36e..d121b9fe22 100644 --- a/OpenRA.Renderer.Null/NullGraphicsDevice.cs +++ b/OpenRA.Renderer.Null/NullGraphicsDevice.cs @@ -43,7 +43,7 @@ namespace OpenRA.Renderer.Null public void EnableDepthBuffer() { } public void DisableDepthBuffer() { } - public void SetBlendMode(BlendMode mode) { } + public void SetBlendMode(BlendMode mode, float alpha = 1f) { } public void GrabWindowMouseFocus() { } public void ReleaseWindowMouseFocus() { } diff --git a/OpenRA.Renderer.Sdl2/Sdl2GraphicsDevice.cs b/OpenRA.Renderer.Sdl2/Sdl2GraphicsDevice.cs index a5b749aa23..2786da9b27 100755 --- a/OpenRA.Renderer.Sdl2/Sdl2GraphicsDevice.cs +++ b/OpenRA.Renderer.Sdl2/Sdl2GraphicsDevice.cs @@ -208,7 +208,7 @@ namespace OpenRA.Renderer.Sdl2 ErrorHandler.CheckGlError(); } - public void SetBlendMode(BlendMode mode) + public void SetBlendMode(BlendMode mode, float alpha = 1f) { GL.BlendEquation(BlendEquationMode.FuncAdd); ErrorHandler.CheckGlError(); @@ -246,26 +246,11 @@ namespace OpenRA.Renderer.Sdl2 ErrorHandler.CheckGlError(); GL.BlendFunc(BlendingFactorSrc.OneMinusDstColor, BlendingFactorDest.One); break; - case BlendMode.Translucency25: + case BlendMode.Translucency: GL.Enable(EnableCap.Blend); ErrorHandler.CheckGlError(); GL.BlendFunc(BlendingFactorSrc.OneMinusConstantAlpha, BlendingFactorDest.One); ErrorHandler.CheckGlError(); - GL.BlendColor(1f, 1f, 1f, 0.25f); - break; - case BlendMode.Translucency50: - GL.Enable(EnableCap.Blend); - ErrorHandler.CheckGlError(); - GL.BlendFunc(BlendingFactorSrc.OneMinusConstantAlpha, BlendingFactorDest.One); - ErrorHandler.CheckGlError(); - GL.BlendColor(1f, 1f, 1f, 0.5f); - break; - case BlendMode.Translucency75: - GL.Enable(EnableCap.Blend); - ErrorHandler.CheckGlError(); - GL.BlendFunc(BlendingFactorSrc.OneMinusConstantAlpha, BlendingFactorDest.One); - ErrorHandler.CheckGlError(); - GL.BlendColor(1f, 1f, 1f, 0.75f); break; case BlendMode.Multiplicative: GL.Enable(EnableCap.Blend); @@ -279,6 +264,9 @@ namespace OpenRA.Renderer.Sdl2 break; } + if (alpha != 1f) + GL.BlendColor(1f, 1f, 1f, alpha); + ErrorHandler.CheckGlError(); } diff --git a/mods/d2k/sequences/misc.yaml b/mods/d2k/sequences/misc.yaml index 3b7c17adbb..60bcf69669 100644 --- a/mods/d2k/sequences/misc.yaml +++ b/mods/d2k/sequences/misc.yaml @@ -85,14 +85,16 @@ bazooka_trail: Start: 3381 Length: 4 Tick: 80 - BlendMode: Translucency75 + BlendMode: Translucency + Alpha: 0.75 bazooka_trail2: idle: DATA.R8 Start: 3544 Length: 4 Tick: 80 - BlendMode: Translucency75 + BlendMode: Translucency + Alpha: 0.75 deviator_trail: idle: DATA.R8 diff --git a/mods/ts/sequences/misc.yaml b/mods/ts/sequences/misc.yaml index 227705aef2..678e141e28 100644 --- a/mods/ts/sequences/misc.yaml +++ b/mods/ts/sequences/misc.yaml @@ -1,7 +1,8 @@ overlay: Defaults: place Offset: 0, -12 - BlendMode: Translucency75 + BlendMode: Translucency + Alpha: 0.75 build-valid-snow: build-valid-temperat: build-invalid: