diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index cdb68c7e2..32839346b 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -408,10 +408,15 @@ public static GameObject MakeStarGraphics(GameObject rootObject, Sector sector, if (starModule.endTint != null) { 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)) diff --git a/NewHorizons/Utility/Files/ImageUtilities.cs b/NewHorizons/Utility/Files/ImageUtilities.cs index 742e5310e..99772e606 100644 --- a/NewHorizons/Utility/Files/ImageUtilities.cs +++ b/NewHorizons/Utility/Files/ImageUtilities.cs @@ -297,6 +297,40 @@ public static Texture2D LerpGreyscaleImage(Texture2D image, Color lightTint, Col 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) { var key = $"Clear {width} {height} {wrap}"; diff --git a/NewHorizons/manifest.json b/NewHorizons/manifest.json index 4f8d2554a..869bb3a76 100644 --- a/NewHorizons/manifest.json +++ b/NewHorizons/manifest.json @@ -4,7 +4,7 @@ "author": "xen, Bwc9876, JohnCorby, MegaPiggy, Clay, Trifid, and friends", "name": "New Horizons", "uniqueName": "xen.NewHorizons", - "version": "1.19.1", + "version": "1.19.2", "owmlVersion": "2.9.8", "dependencies": [ "JohnCorby.VanillaFix", "_nebula.MenuFramework", "xen.CommonCameraUtility", "dgarro.CustomShipLogModes" ], "conflicts": [ "Raicuparta.QuantumSpaceBuddies", "PacificEngine.OW_CommonResources" ],