Add color ramp to stars

This commit is contained in:
Nick 2022-06-30 23:22:12 -04:00
parent 21f9d3a5e7
commit 44fa349d8c
4 changed files with 28 additions and 12 deletions

View File

@ -62,7 +62,7 @@ namespace NewHorizons.Builder.Body
} }
if (body.Config.Star != null) if (body.Config.Star != null)
{ {
var starGO = StarBuilder.MakeStarProxy(planetGO, newProxy, body.Config.Star); var starGO = StarBuilder.MakeStarProxy(planetGO, newProxy, body.Config.Star, body.Mod);
if (realSize < body.Config.Star.size) realSize = body.Config.Star.size; if (realSize < body.Config.Star.size) realSize = body.Config.Star.size;
} }

View File

@ -5,6 +5,8 @@ using OWML.Utils;
using UnityEngine; using UnityEngine;
using NewHorizons.External.Modules.VariableSize; using NewHorizons.External.Modules.VariableSize;
using Logger = NewHorizons.Utility.Logger; using Logger = NewHorizons.Utility.Logger;
using OWML.ModHelper;
using OWML.Common;
namespace NewHorizons.Builder.Body namespace NewHorizons.Builder.Body
{ {
@ -19,9 +21,9 @@ namespace NewHorizons.Builder.Body
private static readonly int InnerRadius = Shader.PropertyToID("_InnerRadius"); private static readonly int InnerRadius = Shader.PropertyToID("_InnerRadius");
private static readonly int OuterRadius = Shader.PropertyToID("_OuterRadius"); private static readonly int OuterRadius = Shader.PropertyToID("_OuterRadius");
public static StarController Make(GameObject planetGO, Sector sector, StarModule starModule) public static StarController Make(GameObject planetGO, Sector sector, StarModule starModule, IModBehaviour mod)
{ {
var starGO = MakeStarGraphics(planetGO, sector, starModule); var starGO = MakeStarGraphics(planetGO, sector, starModule, mod);
var sunAudio = Object.Instantiate(SearchUtilities.Find("Sun_Body/Sector_SUN/Audio_SUN"), starGO.transform); var sunAudio = Object.Instantiate(SearchUtilities.Find("Sun_Body/Sector_SUN/Audio_SUN"), starGO.transform);
sunAudio.transform.localPosition = Vector3.zero; sunAudio.transform.localPosition = Vector3.zero;
@ -152,9 +154,9 @@ namespace NewHorizons.Builder.Body
return starController; return starController;
} }
public static GameObject MakeStarProxy(GameObject planet, GameObject proxyGO, StarModule starModule) public static GameObject MakeStarProxy(GameObject planet, GameObject proxyGO, StarModule starModule, IModBehaviour mod)
{ {
var starGO = MakeStarGraphics(proxyGO, null, starModule); var starGO = MakeStarGraphics(proxyGO, null, starModule, mod);
var supernova = MakeSupernova(starGO, starModule); var supernova = MakeSupernova(starGO, starModule);
@ -175,7 +177,7 @@ namespace NewHorizons.Builder.Body
return proxyGO; return proxyGO;
} }
public static GameObject MakeStarGraphics(GameObject rootObject, Sector sector, StarModule starModule) public static GameObject MakeStarGraphics(GameObject rootObject, Sector sector, StarModule starModule, IModBehaviour mod)
{ {
if (_colorOverTime == null) _colorOverTime = ImageUtilities.GetTexture(Main.Instance, "Assets/textures/StarColorOverTime.png"); if (_colorOverTime == null) _colorOverTime = ImageUtilities.GetTexture(Main.Instance, "Assets/textures/StarColorOverTime.png");
@ -208,10 +210,10 @@ namespace NewHorizons.Builder.Body
starGO.transform.position = rootObject.transform.position; starGO.transform.position = rootObject.transform.position;
starGO.transform.localScale = starModule.size * Vector3.one; starGO.transform.localScale = starModule.size * Vector3.one;
if (starModule.tint != null)
{
TessellatedSphereRenderer surface = sunSurface.GetComponent<TessellatedSphereRenderer>(); TessellatedSphereRenderer surface = sunSurface.GetComponent<TessellatedSphereRenderer>();
if (starModule.tint != null)
{
var colour = starModule.tint.ToColor(); var colour = starModule.tint.ToColor();
var sun = SearchUtilities.Find("Sun_Body"); var sun = SearchUtilities.Find("Sun_Body");
@ -219,8 +221,8 @@ namespace NewHorizons.Builder.Body
var giantMaterial = sun.GetComponent<SunController>()._endSurfaceMaterial; var giantMaterial = sun.GetComponent<SunController>()._endSurfaceMaterial;
surface.sharedMaterial = new Material(starModule.size >= 3000 ? giantMaterial : mainSequenceMaterial); surface.sharedMaterial = new Material(starModule.size >= 3000 ? giantMaterial : mainSequenceMaterial);
var mod = Mathf.Max(1f, 2f * Mathf.Sqrt(starModule.solarLuminosity)); var modifier = Mathf.Max(1f, 2f * Mathf.Sqrt(starModule.solarLuminosity));
var adjustedColour = new Color(colour.r * mod, colour.g * mod, colour.b * mod); var adjustedColour = new Color(colour.r * modifier, colour.g * modifier, colour.b * modifier);
surface.sharedMaterial.color = adjustedColour; surface.sharedMaterial.color = adjustedColour;
Color.RGBToHSV(adjustedColour, out var h, out var s, out var v); Color.RGBToHSV(adjustedColour, out var h, out var s, out var v);
@ -229,12 +231,21 @@ 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 * mod, endColour.g * mod, endColour.b * mod); darkenedColor = new Color(endColour.r * modifier, endColour.g * modifier, endColour.b * modifier);
} }
surface.sharedMaterial.SetTexture(ColorRamp, ImageUtilities.LerpGreyscaleImage(_colorOverTime, adjustedColour, darkenedColor)); surface.sharedMaterial.SetTexture(ColorRamp, ImageUtilities.LerpGreyscaleImage(_colorOverTime, adjustedColour, darkenedColor));
} }
if (!string.IsNullOrEmpty(starModule.starRampTexture))
{
var ramp = ImageUtilities.GetTexture(mod, starModule.starRampTexture);
if (ramp != null)
{
surface.sharedMaterial.SetTexture(ColorRamp, ramp);
}
}
return starGO; return starGO;
} }

View File

@ -56,6 +56,11 @@ namespace NewHorizons.External.Modules.VariableSize
/// </summary> /// </summary>
public MColor tint; public MColor tint;
/// <summary>
/// Path to the texture to put as the star ramp. Optional.
/// </summary>
public string starRampTexture;
/// <summary> /// <summary>
/// How far the light from the star can reach. /// How far the light from the star can reach.
/// </summary> /// </summary>

View File

@ -399,7 +399,7 @@ namespace NewHorizons.Handlers
if (body.Config.Star != null) if (body.Config.Star != null)
{ {
StarLightController.AddStar(StarBuilder.Make(go, sector, body.Config.Star)); StarLightController.AddStar(StarBuilder.Make(go, sector, body.Config.Star, body.Mod));
} }
if (body.Config.Ring != null) if (body.Config.Ring != null)