Add support for dark player colors

This commit is contained in:
Gustas
2023-03-01 15:05:14 +02:00
committed by Pavel Penev
parent 939f715e3c
commit dab3ca0025
4 changed files with 20 additions and 16 deletions

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Graphics
{ {
Height = Exts.NextPowerOf2(index + 1); Height = Exts.NextPowerOf2(index + 1);
Array.Resize(ref buffer, Height * Palette.Size * 4); Array.Resize(ref buffer, Height * Palette.Size * 4);
Array.Resize(ref colorShiftBuffer, Height * 4); Array.Resize(ref colorShiftBuffer, Height * 8);
} }
if (allowModifiers) if (allowModifiers)
@@ -90,19 +90,20 @@ namespace OpenRA.Graphics
CopyBufferToTexture(); CopyBufferToTexture();
} }
public void SetColorShift(string name, float hueOffset, float satOffset, float minHue, float maxHue) public void SetColorShift(string name, float hueOffset, float satOffset, float valueMultiplier, float minHue, float maxHue)
{ {
var index = GetPaletteIndex(name); var index = GetPaletteIndex(name);
colorShiftBuffer[4 * index + 0] = hueOffset; colorShiftBuffer[8 * index + 0] = minHue;
colorShiftBuffer[4 * index + 1] = satOffset; colorShiftBuffer[8 * index + 1] = maxHue;
colorShiftBuffer[4 * index + 2] = minHue; colorShiftBuffer[8 * index + 4] = hueOffset;
colorShiftBuffer[4 * index + 3] = maxHue; colorShiftBuffer[8 * index + 5] = satOffset;
colorShiftBuffer[8 * index + 6] = valueMultiplier;
} }
public bool HasColorShift(string name) public bool HasColorShift(string name)
{ {
var index = GetPaletteIndex(name); var index = GetPaletteIndex(name);
return colorShiftBuffer[4 * index + 2] != 0 || colorShiftBuffer[4 * index + 3] != 0; return colorShiftBuffer[8 * index] != 0 || colorShiftBuffer[8 * index + 1] != 0;
} }
public void Initialize() public void Initialize()
@@ -125,7 +126,7 @@ namespace OpenRA.Graphics
void CopyBufferToTexture() void CopyBufferToTexture()
{ {
Texture.SetData(buffer, Palette.Size, Height); Texture.SetData(buffer, Palette.Size, Height);
ColorShifts.SetFloatData(colorShiftBuffer, 1, Height); ColorShifts.SetFloatData(colorShiftBuffer, 2, Height);
} }
public void ApplyModifiers(IEnumerable<IPaletteModifier> paletteMods) public void ApplyModifiers(IEnumerable<IPaletteModifier> paletteMods)

View File

@@ -20,13 +20,14 @@ namespace OpenRA.Graphics
readonly int[] remapIndices; readonly int[] remapIndices;
readonly float hue; readonly float hue;
readonly float saturation; readonly float saturation;
readonly float value;
public PlayerColorRemap(int[] remapIndices, Color color) public PlayerColorRemap(int[] remapIndices, Color color)
{ {
this.remapIndices = remapIndices; this.remapIndices = remapIndices;
var (r, g, b) = color.ToLinear(); var (r, g, b) = color.ToLinear();
(hue, saturation, _) = Color.RgbToHsv(r, g, b); (hue, saturation, value) = Color.RgbToHsv(r, g, b);
} }
public Color GetRemappedColor(Color original, int index) public Color GetRemappedColor(Color original, int index)
@@ -43,7 +44,7 @@ namespace OpenRA.Graphics
var value = Math.Max(Math.Max(r, g), b); var value = Math.Max(Math.Max(r, g), b);
// Construct the new RGB color // Construct the new RGB color
(r, g, b) = Color.HsvToRgb(hue, saturation, value); (r, g, b) = Color.HsvToRgb(hue, saturation, value * this.value);
// Convert linear back to SRGB and pre-multiply by the alpha // Convert linear back to SRGB and pre-multiply by the alpha
return Color.FromLinear(original.A, r, g, b); return Color.FromLinear(original.A, r, g, b);

View File

@@ -113,9 +113,9 @@ namespace OpenRA.Graphics
palettes[name].Palette = pal; palettes[name].Palette = pal;
} }
public void SetPaletteColorShift(string name, float hueOffset, float satOffset, float minHue, float maxHue) public void SetPaletteColorShift(string name, float hueOffset, float satOffset, float valueModifier, float minHue, float maxHue)
{ {
palette.SetColorShift(name, hueOffset, satOffset, minHue, maxHue); palette.SetColorShift(name, hueOffset, satOffset, valueModifier, minHue, maxHue);
} }
// PERF: Avoid LINQ. // PERF: Avoid LINQ.

View File

@@ -211,14 +211,16 @@ vec4 SamplePalettedBilinear(float samplerIndex, vec2 coords, vec2 textureSize)
vec4 ColorShift(vec4 c, float p) vec4 ColorShift(vec4 c, float p)
{ {
#if __VERSION__ == 120 #if __VERSION__ == 120
vec4 shift = texture2D(ColorShifts, vec2(0.5, p)); vec4 range = texture2D(ColorShifts, vec2(0.25, p));
vec4 shift = texture2D(ColorShifts, vec2(0.75, p));
#else #else
vec4 shift = texture(ColorShifts, vec2(0.5, p)); vec4 range = texture(ColorShifts, vec2(0.25, p));
vec4 shift = texture(ColorShifts, vec2(0.75, p));
#endif #endif
vec3 hsv = rgb2hsv(srgb2linear(c).rgb); vec3 hsv = rgb2hsv(srgb2linear(c).rgb);
if (hsv.r >= shift.b && shift.a >= hsv.r) if (hsv.r > range.r && range.g >= hsv.r)
c = linear2srgb(vec4(hsv2rgb(vec3(hsv.r + shift.r, clamp(hsv.g + shift.g, 0.0, 1.0), hsv.b)), c.a)); c = linear2srgb(vec4(hsv2rgb(vec3(hsv.r + shift.r, clamp(hsv.g + shift.g, 0.0, 1.0), hsv.b * clamp(shift.b, 0.0, 1.0))), c.a));
return c; return c;
} }