Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.19.2 #809

Merged
merged 1 commit into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading