Rewrite TS minimap rendering:

* Rename LeftColor and RightColor to MinColor and MaxColor
  These are mapped from LowRadarColor and HighRadarColor in
  the original inis, and appear to be used to set the bounding
  values for selecting a random colour, NOT for left/right
  pixels (which caused noticeably wrong banding).

* Adjust brightness based on terrain height.
  MinHeightColorBrightness and MaxHeightColorBrightness
  were chosen by trial/error to match the original
  map preview rendering.
This commit is contained in:
Paul Chote
2020-06-18 21:48:59 +01:00
committed by Oliver Brakmann
parent 83c53e17e0
commit 5f588561b6
29 changed files with 11931 additions and 11843 deletions

View File

@@ -702,6 +702,11 @@ namespace OpenRA
var pxStride = 4; var pxStride = 4;
var minimapData = new byte[stride * height]; var minimapData = new byte[stride * height];
Color leftColor, rightColor; Color leftColor, rightColor;
var useHeightModifiers = tileset.MinHeightColorBrightness != 1.0f || tileset.MaxHeightColorBrightness != 1.0f;
var minHeightBrightness = tileset.MinHeightColorBrightness;
var maxHeightBrightness = tileset.MaxHeightColorBrightness;
var heightModifier = 1f / Grid.MaximumTerrainHeight;
for (var y = 0; y < height; y++) for (var y = 0; y < height; y++)
{ {
for (var x = 0; x < width; x++) for (var x = 0; x < width; x++)
@@ -716,8 +721,21 @@ namespace OpenRA
{ {
// Cell contains terrain // Cell contains terrain
var type = tileset.GetTileInfo(Tiles[uv]); var type = tileset.GetTileInfo(Tiles[uv]);
leftColor = type != null ? type.LeftColor : Color.Black; if (type != null)
rightColor = type != null ? type.RightColor : Color.Black; {
if (useHeightModifiers)
{
var left = Exts.ColorLerp(Game.CosmeticRandom.NextFloat(), type.MinColor, type.MaxColor);
var right = Exts.ColorLerp(Game.CosmeticRandom.NextFloat(), type.MinColor, type.MaxColor);
var scale = float2.Lerp(minHeightBrightness, maxHeightBrightness, heightModifier * Height[uv]);
leftColor = Color.FromArgb((int)(scale * left.R).Clamp(0, 255), (int)(scale * left.G).Clamp(0, 255), (int)(scale * left.B).Clamp(0, 255));
rightColor = Color.FromArgb((int)(scale * right.R).Clamp(0, 255), (int)(scale * right.G).Clamp(0, 255), (int)(scale * right.B).Clamp(0, 255));
}
else
leftColor = rightColor = type.MinColor;
}
else
leftColor = rightColor = Color.Black;
} }
if (isRectangularIsometric) if (isRectangularIsometric)

View File

@@ -24,9 +24,8 @@ namespace OpenRA
public readonly byte TerrainType = byte.MaxValue; public readonly byte TerrainType = byte.MaxValue;
public readonly byte Height; public readonly byte Height;
public readonly byte RampType; public readonly byte RampType;
public readonly Color LeftColor; public readonly Color MinColor;
public readonly Color RightColor; public readonly Color MaxColor;
public readonly float ZOffset = 0.0f; public readonly float ZOffset = 0.0f;
public readonly float ZRamp = 1.0f; public readonly float ZRamp = 1.0f;
} }
@@ -106,11 +105,11 @@ namespace OpenRA
// Fall back to the terrain-type color if necessary // Fall back to the terrain-type color if necessary
var overrideColor = tileSet.TerrainInfo[tile.TerrainType].Color; var overrideColor = tileSet.TerrainInfo[tile.TerrainType].Color;
if (tile.LeftColor == default(Color)) if (tile.MinColor == default(Color))
tile.GetType().GetField("LeftColor").SetValue(tile, overrideColor); tile.GetType().GetField("MinColor").SetValue(tile, overrideColor);
if (tile.RightColor == default(Color)) if (tile.MaxColor == default(Color))
tile.GetType().GetField("RightColor").SetValue(tile, overrideColor); tile.GetType().GetField("MaxColor").SetValue(tile, overrideColor);
return tile; return tile;
} }
@@ -139,6 +138,8 @@ namespace OpenRA
public readonly string[] EditorTemplateOrder; public readonly string[] EditorTemplateOrder;
public readonly bool IgnoreTileSpriteOffsets; public readonly bool IgnoreTileSpriteOffsets;
public readonly bool EnableDepth = false; public readonly bool EnableDepth = false;
public readonly float MinHeightColorBrightness = 1.0f;
public readonly float MaxHeightColorBrightness = 1.0f;
[FieldLoader.Ignore] [FieldLoader.Ignore]
public readonly IReadOnlyDictionary<ushort, TerrainTemplateInfo> Templates; public readonly IReadOnlyDictionary<ushort, TerrainTemplateInfo> Templates;

View File

@@ -143,8 +143,8 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
if (rampType != 0) if (rampType != 0)
data.AppendLine("\t\t\t\tRampType: {0}".F(rampType)); data.AppendLine("\t\t\t\tRampType: {0}".F(rampType));
data.AppendLine("\t\t\t\tLeftColor: {0:X2}{1:X2}{2:X2}".F(s.ReadUInt8(), s.ReadUInt8(), s.ReadUInt8())); data.AppendLine("\t\t\t\tMinColor: {0:X2}{1:X2}{2:X2}".F(s.ReadUInt8(), s.ReadUInt8(), s.ReadUInt8()));
data.AppendLine("\t\t\t\tRightColor: {0:X2}{1:X2}{2:X2}".F(s.ReadUInt8(), s.ReadUInt8(), s.ReadUInt8())); data.AppendLine("\t\t\t\tMaxColor: {0:X2}{1:X2}{2:X2}".F(s.ReadUInt8(), s.ReadUInt8(), s.ReadUInt8()));
data.AppendLine("\t\t\t\tZOffset: {0}".F(-tileSize.Height / 2.0f)); data.AppendLine("\t\t\t\tZOffset: {0}".F(-tileSize.Height / 2.0f));
data.AppendLine("\t\t\t\tZRamp: 0"); data.AppendLine("\t\t\t\tZRamp: 0");
} }

View File

@@ -91,17 +91,31 @@ namespace OpenRA.Mods.Common.Traits
public static Pair<int, int> GetColor(Map map, MPos uv) public static Pair<int, int> GetColor(Map map, MPos uv)
{ {
var custom = map.CustomTerrain[uv]; var custom = map.CustomTerrain[uv];
int leftColor, rightColor; Color leftColor, rightColor;
if (custom == byte.MaxValue) if (custom == byte.MaxValue)
{ {
var type = map.Rules.TileSet.GetTileInfo(map.Tiles[uv]); var tileset = map.Rules.TileSet;
leftColor = type != null ? type.LeftColor.ToArgb() : Color.Black.ToArgb(); var type = tileset.GetTileInfo(map.Tiles[uv]);
rightColor = type != null ? type.RightColor.ToArgb() : Color.Black.ToArgb(); if (type != null)
{
if (tileset.MinHeightColorBrightness != 1.0f || tileset.MaxHeightColorBrightness != 1.0f)
{
var left = Exts.ColorLerp(Game.CosmeticRandom.NextFloat(), type.MinColor, type.MaxColor);
var right = Exts.ColorLerp(Game.CosmeticRandom.NextFloat(), type.MinColor, type.MaxColor);
var scale = float2.Lerp(tileset.MinHeightColorBrightness, tileset.MaxHeightColorBrightness, map.Height[uv] * 1f / map.Grid.MaximumTerrainHeight);
leftColor = Color.FromArgb((int)(scale * left.R).Clamp(0, 255), (int)(scale * left.G).Clamp(0, 255), (int)(scale * left.B).Clamp(0, 255));
rightColor = Color.FromArgb((int)(scale * right.R).Clamp(0, 255), (int)(scale * right.G).Clamp(0, 255), (int)(scale * right.B).Clamp(0, 255));
}
else
leftColor = rightColor = type.MinColor;
}
else
leftColor = rightColor = Color.Black;
} }
else else
leftColor = rightColor = map.Rules.TileSet[custom].Color.ToArgb(); leftColor = rightColor = map.Rules.TileSet[custom].Color;
return Pair.New(leftColor, rightColor); return Pair.New(leftColor.ToArgb(), rightColor.ToArgb());
} }
} }
} }

View File

@@ -0,0 +1,50 @@
#region Copyright & License Information
/*
* Copyright 2007-2020 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System;
using System.Collections.Generic;
namespace OpenRA.Mods.Common.UpdateRules.Rules
{
class UpdateTilesetColors : UpdateRule
{
public override string Name { get { return "Rename Tileset LeftColor and RightColor"; } }
public override string Description
{
get
{
return "The LeftColor and RightColor keys in tilesets have been renamed to MinColor and MaxColor to reflect their proper usage.";
}
}
public override IEnumerable<string> UpdateTilesetNode(ModData modData, MiniYamlNode tilesetNode)
{
if (tilesetNode.Key == "Templates")
{
foreach (var templateNode in tilesetNode.Value.Nodes)
{
foreach (var tilesNode in templateNode.ChildrenMatching("Tiles"))
{
foreach (var node in tilesNode.Value.Nodes)
{
foreach (var leftNode in node.ChildrenMatching("LeftColor"))
leftNode.RenameKey("MinColor");
foreach (var leftNode in node.ChildrenMatching("RightColor"))
leftNode.RenameKey("MaxColor");
}
}
}
}
yield break;
}
}
}

View File

@@ -65,6 +65,7 @@ namespace OpenRA.Mods.Common.UpdateRules
new SpawnActorPowerDefaultEffect(), new SpawnActorPowerDefaultEffect(),
new RemoveConditionManager(), new RemoveConditionManager(),
new ConvertSupportPowerRangesToFootprint(), new ConvertSupportPowerRangesToFootprint(),
new UpdateTilesetColors(),
}) })
}; };

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 113 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 41 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff