Adjust star start and end tinting to look better

This commit is contained in:
Nick 2024-03-15 16:57:57 -04:00
parent bb39c98411
commit 5b989100cb
3 changed files with 43 additions and 4 deletions

View File

@ -408,10 +408,15 @@ namespace NewHorizons.Builder.Body
if (starModule.endTint != null) if (starModule.endTint != null)
{ {
var endColour = starModule.endTint.ToColor(); var endColour = starModule.endTint.ToColor();
darkenedColor = new Color(endColour.r * modifier, endColour.g * modifier, endColour.b * modifier); var adjustedEndColour = new Color(endColour.r * modifier, endColour.g * modifier, endColour.b * modifier);
Color.RGBToHSV(adjustedEndColour, out var hEnd, out var sEnd, out var vEnd);
var darkenedEndColor = Color.HSVToRGB(hEnd, sEnd * 1.2f, vEnd * 0.1f);
surface.sharedMaterial.SetTexture(ColorRamp, ImageUtilities.LerpGreyscaleImageAlongX(_colorOverTime, adjustedColour, darkenedColor, adjustedEndColour, darkenedEndColor));
}
else
{
surface.sharedMaterial.SetTexture(ColorRamp, ImageUtilities.LerpGreyscaleImage(_colorOverTime, adjustedColour, darkenedColor));
} }
surface.sharedMaterial.SetTexture(ColorRamp, ImageUtilities.LerpGreyscaleImage(_colorOverTime, adjustedColour, darkenedColor));
} }
if (!string.IsNullOrEmpty(starModule.starRampTexture)) if (!string.IsNullOrEmpty(starModule.starRampTexture))

View File

@ -297,6 +297,40 @@ namespace NewHorizons.Utility.Files
return newImage; return newImage;
} }
public static Color LerpColor(Color start, Color end, float amount)
{
return new Color(Mathf.Lerp(start.r, end.r, amount), Mathf.Lerp(start.g, end.g, amount), Mathf.Lerp(start.b, end.b, amount));
}
public static Texture2D LerpGreyscaleImageAlongX(Texture2D image, Color lightTintStart, Color darkTintStart, Color lightTintEnd, Color darkTintEnd)
{
var key = $"{image.name} > lerp greyscale {lightTintStart} {darkTintStart} {lightTintEnd} {darkTintEnd}";
if (_textureCache.TryGetValue(key, out var existingTexture)) return (Texture2D)existingTexture;
var pixels = image.GetPixels();
for (int i = 0; i < pixels.Length; i++)
{
var amount = (i % image.width) / (float) image.width;
var lightTint = LerpColor(lightTintStart, lightTintEnd, amount);
var darkTint = LerpColor(darkTintStart, darkTintEnd, amount);
pixels[i].r = Mathf.Lerp(darkTint.r, lightTint.r, pixels[i].r);
pixels[i].g = Mathf.Lerp(darkTint.g, lightTint.g, pixels[i].g);
pixels[i].b = Mathf.Lerp(darkTint.b, lightTint.b, pixels[i].b);
}
var newImage = new Texture2D(image.width, image.height, image.format, image.mipmapCount != 1);
newImage.name = key;
newImage.SetPixels(pixels);
newImage.Apply();
newImage.wrapMode = image.wrapMode;
_textureCache.Add(key, newImage);
return newImage;
}
public static Texture2D ClearTexture(int width, int height, bool wrap = false) public static Texture2D ClearTexture(int width, int height, bool wrap = false)
{ {
var key = $"Clear {width} {height} {wrap}"; var key = $"Clear {width} {height} {wrap}";

View File

@ -4,7 +4,7 @@
"author": "xen, Bwc9876, JohnCorby, MegaPiggy, Clay, Trifid, and friends", "author": "xen, Bwc9876, JohnCorby, MegaPiggy, Clay, Trifid, and friends",
"name": "New Horizons", "name": "New Horizons",
"uniqueName": "xen.NewHorizons", "uniqueName": "xen.NewHorizons",
"version": "1.19.1", "version": "1.19.2",
"owmlVersion": "2.9.8", "owmlVersion": "2.9.8",
"dependencies": [ "JohnCorby.VanillaFix", "_nebula.MenuFramework", "xen.CommonCameraUtility", "dgarro.CustomShipLogModes" ], "dependencies": [ "JohnCorby.VanillaFix", "_nebula.MenuFramework", "xen.CommonCameraUtility", "dgarro.CustomShipLogModes" ],
"conflicts": [ "Raicuparta.QuantumSpaceBuddies", "PacificEngine.OW_CommonResources" ], "conflicts": [ "Raicuparta.QuantumSpaceBuddies", "PacificEngine.OW_CommonResources" ],