Update NukePaletteEffect for premultiplied alpha.

This commit is contained in:
Paul Chote
2015-05-24 17:41:08 +01:00
parent 2cc125a3fa
commit 322285ef66
2 changed files with 16 additions and 2 deletions

View File

@@ -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);

View File

@@ -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<NukePaletteEffect> { }
@@ -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);
}
}
}