diff --git a/OpenRA.Game/Graphics/Util.cs b/OpenRA.Game/Graphics/Util.cs index 166f117cea..b61ee0f1e4 100644 --- a/OpenRA.Game/Graphics/Util.cs +++ b/OpenRA.Game/Graphics/Util.cs @@ -118,6 +118,18 @@ namespace OpenRA.Graphics return Color.FromArgb(c.A, (byte)(c.R * a + 0.5f), (byte)(c.G * a + 0.5f), (byte)(c.B * a + 0.5f)); } + public static Color PremultipliedColorLerp(float t, Color c1, Color c2) + { + // Colors must be lerped in a non-multiplied color space + var a1 = 255f / c1.A; + var a2 = 255f / c2.A; + return PremultiplyAlpha(Color.FromArgb( + (int)(t * c2.A + (1 - t) * c1.A), + (int)((byte)(t * a2 * c2.R + 0.5f) + (1 - t) * (byte)(a1 * c1.R + 0.5f)), + (int)((byte)(t * a2 * c2.G + 0.5f) + (1 - t) * (byte)(a1 * c1.G + 0.5f)), + (int)((byte)(t * a2 * c2.B + 0.5f) + (1 - t) * (byte)(a1 * c1.B + 0.5f)))); + } + public static float[] IdentityMatrix() { return Exts.MakeArray(16, j => (j % 5 == 0) ? 1.0f : 0); diff --git a/OpenRA.Mods.Common/Traits/PaletteEffects/NukePaletteEffect.cs b/OpenRA.Mods.Common/Traits/PaletteEffects/NukePaletteEffect.cs index 7dce462679..05199a1f97 100644 --- a/OpenRA.Mods.Common/Traits/PaletteEffects/NukePaletteEffect.cs +++ b/OpenRA.Mods.Common/Traits/PaletteEffects/NukePaletteEffect.cs @@ -15,6 +15,8 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { + using GUtil = OpenRA.Graphics.Util; + [Desc("Apply palette full screen rotations during atom bomb explosions. Add this to the world actor.")] class NukePaletteEffectInfo : TraitInfo { } @@ -46,8 +48,8 @@ namespace OpenRA.Mods.Common.Traits for (var x = 0; x < Palette.Size; x++) { var orig = pal.Value.GetColor(x); - var white = Color.FromArgb(orig.A, 255, 255, 255); - pal.Value.SetColor(x, Exts.ColorLerp(frac, orig, white)); + var final = GUtil.PremultipliedColorLerp(frac, orig, GUtil.PremultiplyAlpha(Color.FromArgb(orig.A, Color.White))); + pal.Value.SetColor(x, final); } } }