Skip to content

Commit

Permalink
1.19.2 (#809)
Browse files Browse the repository at this point in the history
## Improvements
- Starts using start and end tint now look way less awful
  • Loading branch information
xen-42 authored Mar 16, 2024
2 parents 13ea363 + 5b98910 commit 67e5a02
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
11 changes: 8 additions & 3 deletions NewHorizons/Builder/Body/StarBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
34 changes: 34 additions & 0 deletions NewHorizons/Utility/Files/ImageUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand Down
2 changes: 1 addition & 1 deletion NewHorizons/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" ],
Expand Down

0 comments on commit 67e5a02

Please sign in to comment.