Allow setting supernova colour

This commit is contained in:
Nick 2022-05-17 17:29:38 -04:00
parent ebe8bd9c1c
commit 34cc923a5f
7 changed files with 104 additions and 32 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 B

View File

@ -59,8 +59,6 @@ namespace NewHorizons.Builder.Body
{ {
var starGO = StarBuilder.MakeStarProxy(planetGO, newProxy, body.Config.Star); var starGO = StarBuilder.MakeStarProxy(planetGO, newProxy, body.Config.Star);
if (body.Config.Star.Curve != null) AddSizeController(starGO, body.Config.Star.Curve, body.Config.Star.Size);
if (realSize < body.Config.Star.Size) realSize = body.Config.Star.Size; if (realSize < body.Config.Star.Size) realSize = body.Config.Star.Size;
} }
if (body.Config.ProcGen != null) if (body.Config.ProcGen != null)
@ -135,8 +133,6 @@ namespace NewHorizons.Builder.Body
var proxyController = newProxy.AddComponent<NHProxy>(); var proxyController = newProxy.AddComponent<NHProxy>();
proxyController.astroName = body.Config.Name; proxyController.astroName = body.Config.Name;
proxyController._realObjectDiameter = realSize; proxyController._realObjectDiameter = realSize;
proxyController.renderers = newProxy.GetComponentsInChildren<Renderer>();
proxyController.tessellatedRenderers = newProxy.GetComponentsInChildren<TessellatedRenderer>();
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -38,16 +38,18 @@ namespace NewHorizons.Builder.Body
{ {
sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), starGO.transform); sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), starGO.transform);
sunAtmosphere.transform.position = planetGO.transform.position; sunAtmosphere.transform.position = planetGO.transform.position;
sunAtmosphere.transform.localScale = Vector3.one; sunAtmosphere.transform.localScale = Vector3.one * OuterRadiusRatio;
sunAtmosphere.name = "Atmosphere_Star"; sunAtmosphere.name = "Atmosphere_Star";
PlanetaryFogController fog = sunAtmosphere.transform.Find("FogSphere").GetComponent<PlanetaryFogController>(); PlanetaryFogController fog = sunAtmosphere.transform.Find("FogSphere").GetComponent<PlanetaryFogController>();
if (starModule.Tint != null) if (starModule.Tint != null)
{ {
fog.fogTint = starModule.Tint.ToColor(); fog.fogTint = starModule.Tint.ToColor();
sunAtmosphere.transform.Find("AtmoSphere").transform.localScale = Vector3.one * (starModule.Size * OuterRadiusRatio); sunAtmosphere.transform.Find("AtmoSphere").transform.localScale = Vector3.one;
foreach (var lod in sunAtmosphere.transform.Find("AtmoSphere").GetComponentsInChildren<MeshRenderer>()) foreach (var lod in sunAtmosphere.transform.Find("AtmoSphere").GetComponentsInChildren<MeshRenderer>())
{ {
lod.material.SetColor("_SkyColor", starModule.Tint.ToColor()); lod.material.SetColor("_SkyColor", starModule.Tint.ToColor());
lod.material.SetColor("_AtmosFar", starModule.Tint.ToColor());
lod.material.SetColor("_AtmosNear", starModule.Tint.ToColor());
lod.material.SetFloat("_InnerRadius", starModule.Size); lod.material.SetFloat("_InnerRadius", starModule.Size);
lod.material.SetFloat("_OuterRadius", starModule.Size * OuterRadiusRatio); lod.material.SetFloat("_OuterRadius", starModule.Size * OuterRadiusRatio);
} }
@ -72,7 +74,7 @@ namespace NewHorizons.Builder.Body
deathVolume.transform.localScale = Vector3.one; deathVolume.transform.localScale = Vector3.one;
deathVolume.GetComponent<SphereCollider>().radius = 1f; deathVolume.GetComponent<SphereCollider>().radius = 1f;
deathVolume.GetComponent<DestructionVolume>()._onlyAffectsPlayerAndShip = false; deathVolume.GetComponent<DestructionVolume>()._onlyAffectsPlayerAndShip = false;
deathVolume.GetComponent<DestructionVolume>()._shrinkBodies = false; deathVolume.GetComponent<DestructionVolume>()._shrinkBodies = true;
deathVolume.name = "DestructionVolume"; deathVolume.name = "DestructionVolume";
Light ambientLight = ambientLightGO.GetComponent<Light>(); Light ambientLight = ambientLightGO.GetComponent<Light>();
@ -125,7 +127,7 @@ namespace NewHorizons.Builder.Body
starController.SunColor = lightColour; starController.SunColor = lightColour;
} }
var supernova = MakeSupernova(starGO); var supernova = MakeSupernova(starGO, starModule);
var controller = starGO.AddComponent<StarEvolutionController>(); var controller = starGO.AddComponent<StarEvolutionController>();
if(starModule.Curve != null) controller.scaleCurve = starModule.ToAnimationCurve(); if(starModule.Curve != null) controller.scaleCurve = starModule.ToAnimationCurve();
@ -133,25 +135,33 @@ namespace NewHorizons.Builder.Body
controller.atmosphere = sunAtmosphere; controller.atmosphere = sunAtmosphere;
controller.supernova = supernova; controller.supernova = supernova;
controller.startColour = starModule.Tint; controller.startColour = starModule.Tint;
controller.startColour = starModule.EndTint; controller.endColour = starModule.EndTint;
controller.willExplode = starModule.GoSupernova;
// It fucking insists on this existing and its really annoying
var supernovaVolume = new GameObject("SupernovaVolumePlaceholder");
supernovaVolume.transform.SetParent(starGO.transform);
supernova._supernovaVolume = supernovaVolume.AddComponent<SupernovaDestructionVolume>();
var sphere = supernovaVolume.AddComponent<SphereShape>();
sphere.radius = 0f;
supernovaVolume.AddComponent<OWCollider>();
return starController; return starController;
} }
public static GameObject MakeStarProxy(GameObject planet, GameObject proxyGO, StarModule starModule) public static GameObject MakeStarProxy(GameObject planet, GameObject proxyGO, StarModule starModule)
{ {
var starGO = new GameObject("Star"); var starGO = MakeStarGraphics(proxyGO, null, starModule);
starGO.transform.parent = proxyGO.transform;
starGO.transform.localPosition = Vector3.zero;
MakeStarGraphics(proxyGO, null, starModule); var supernova = MakeSupernova(starGO, starModule);
var supernova = MakeSupernova(starGO);
var controller = starGO.AddComponent<StarEvolutionController>(); var controller = starGO.AddComponent<StarEvolutionController>();
if (starModule.Curve != null) controller.scaleCurve = starModule.ToAnimationCurve(); if (starModule.Curve != null) controller.scaleCurve = starModule.ToAnimationCurve();
controller.size = starModule.Size; controller.size = starModule.Size;
controller.supernova = supernova; controller.supernova = supernova;
controller.startColour = starModule.Tint;
controller.endColour = starModule.EndTint;
controller.enabled = true;
planet.GetComponentInChildren<StarEvolutionController>().SetProxy(controller); planet.GetComponentInChildren<StarEvolutionController>().SetProxy(controller);
@ -206,7 +216,7 @@ namespace NewHorizons.Builder.Body
return starGO; return starGO;
} }
public static SupernovaEffectController MakeSupernova(GameObject starGO) private static SupernovaEffectController MakeSupernova(GameObject starGO, StarModule starModule)
{ {
var supernovaGO = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/Supernova").InstantiateInactive(); var supernovaGO = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/Supernova").InstantiateInactive();
supernovaGO.transform.SetParent(starGO.transform); supernovaGO.transform.SetParent(starGO.transform);
@ -216,6 +226,20 @@ namespace NewHorizons.Builder.Body
supernova._surface = starGO.GetComponentInChildren<TessellatedSphereRenderer>(); supernova._surface = starGO.GetComponentInChildren<TessellatedSphereRenderer>();
supernova._supernovaVolume = null; supernova._supernovaVolume = null;
if(starModule.SupernovaTint != null)
{
var colour = starModule.SupernovaTint.ToColor();
var supernovaMaterial = new Material(supernova._supernovaMaterial);
var ramp = ImageUtilities.LerpGreyscaleImage(ImageUtilities.GetTexture(Main.Instance, "AssetBundle/Effects_SUN_Supernova_d.png"), Color.white, colour);
supernovaMaterial.SetTexture("_ColorRamp", ramp);
supernova._supernovaMaterial = supernovaMaterial;
// Motes
var moteMaterial = supernova.GetComponentInChildren<ParticleSystemRenderer>().material;
moteMaterial.color = new Color(colour.r * 3f, colour.g * 3f, colour.b * 3f, moteMaterial.color.a);
}
supernovaGO.SetActive(true); supernovaGO.SetActive(true);
return supernova; return supernova;

View File

@ -1,4 +1,5 @@
using NewHorizons.Utility; using NewHorizons.Components.SizeControllers;
using NewHorizons.Utility;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
@ -7,8 +8,29 @@ namespace NewHorizons.Components
public class NHProxy : ProxyPlanet public class NHProxy : ProxyPlanet
{ {
public string astroName; public string astroName;
public Renderer[] renderers;
public TessellatedRenderer[] tessellatedRenderers; private GameObject _star;
private Renderer[] _starRenderers;
private TessellatedRenderer[] _starTessellatedRenderers;
public override void Awake()
{
base.Awake();
// The star part cant be disabled like the rest and we have to manually disable the renderers
// Else it can stop the supernova effect mid way through
_star = GetComponentInChildren<StarEvolutionController>()?.gameObject;
if(_star != null)
{
_starRenderers = _star.GetComponentsInChildren<Renderer>();
_starTessellatedRenderers = _star.GetComponentsInChildren<TessellatedRenderer>();
}
// Start off
_outOfRange = false;
ToggleRendering(false);
}
public override void Initialize() public override void Initialize()
{ {
@ -34,10 +56,25 @@ namespace NewHorizons.Components
public override void ToggleRendering(bool on) public override void ToggleRendering(bool on)
{ {
base.ToggleRendering(on); base.ToggleRendering(on);
foreach (Transform child in transform) foreach (Transform child in transform)
{ {
if (child.gameObject == _star) continue;
child.gameObject.SetActive(on); child.gameObject.SetActive(on);
} }
if(_star != null)
{
foreach (var renderer in _starRenderers)
{
renderer.enabled = on;
}
foreach (var renderer in _starTessellatedRenderers)
{
renderer.enabled = on;
}
}
} }
} }
} }

View File

@ -13,9 +13,10 @@ namespace NewHorizons.Components.SizeControllers
{ {
public GameObject atmosphere; public GameObject atmosphere;
public SupernovaEffectController supernova; public SupernovaEffectController supernova;
public bool willExplode;
public MColor startColour; public MColor startColour { get; set; }
public MColor endColour; public MColor endColour { get; set; }
private Color _startColour; private Color _startColour;
private Color _endColour; private Color _endColour;
@ -69,7 +70,8 @@ namespace NewHorizons.Components.SizeControllers
if (endColour == null) if (endColour == null)
{ {
_endColour = _endSurfaceMaterial.color; _endColour = _startColour;
_endSurfaceMaterial.color = _startColour;
} }
else else
{ {
@ -77,22 +79,21 @@ namespace NewHorizons.Components.SizeControllers
_endSurfaceMaterial.color = _endColour; _endSurfaceMaterial.color = _endColour;
} }
_heatVolume = GetComponentInChildren<HeatHazardVolume>(); _heatVolume = GetComponentInChildren<HeatHazardVolume>();
_destructionVolume = GetComponentInChildren<DestructionVolume>(); _destructionVolume = GetComponentInChildren<DestructionVolume>();
if (atmosphere != null) if (atmosphere != null)
{ {
_fog = atmosphere.GetComponentInChildren<PlanetaryFogController>(); _fog = atmosphere?.GetComponentInChildren<PlanetaryFogController>();
_atmosphereRenderers = atmosphere.transform.Find("AtmoSphere").GetComponentsInChildren<MeshRenderer>(); _atmosphereRenderers = atmosphere?.transform?.Find("AtmoSphere")?.GetComponentsInChildren<MeshRenderer>();
} }
GlobalMessenger.AddListener("TriggerSupernova", Die); if (willExplode) GlobalMessenger.AddListener("TriggerSupernova", Die);
} }
public void OnDestroy() public void OnDestroy()
{ {
GlobalMessenger.RemoveListener("TriggerSupernova", Die); if (willExplode) GlobalMessenger.RemoveListener("TriggerSupernova", Die);
} }
public void SetProxy(StarEvolutionController proxy) public void SetProxy(StarEvolutionController proxy)
@ -124,8 +125,8 @@ namespace NewHorizons.Components.SizeControllers
transform.localScale = Vector3.one; transform.localScale = Vector3.one;
// Make the destruction volume scale slightly smaller so you really have to be in the supernova to die // Make the destruction volume scale slightly smaller so you really have to be in the supernova to die
if(_destructionVolume != null) _destructionVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius() * 0.9f; if (_destructionVolume != null) _destructionVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius() * 0.9f;
if(_heatVolume != null) _heatVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius(); if (_heatVolume != null) _heatVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius();
if (Time.time > _supernovaStartTime + 45f) if (Time.time > _supernovaStartTime + 45f)
{ {
@ -173,17 +174,24 @@ namespace NewHorizons.Components.SizeControllers
if (_fog != null) if (_fog != null)
{ {
_fog.fogRadius = CurrentScale * StarBuilder.OuterRadiusRatio; _fog.fogRadius = CurrentScale * StarBuilder.OuterRadiusRatio;
_fog.lodFadeDistance = CurrentScale * (StarBuilder.OuterRadiusRatio - 1f); _fog.lodFadeDistance = CurrentScale * StarBuilder.OuterRadiusRatio / 3f;
_fog.fogTint = currentColour; // The colour thing goes over one
var max = Math.Max(currentColour.g, Math.Max(currentColour.b, currentColour.r));
var fogColour = currentColour / max / 1.5f;
fogColour.a = 1f;
_fog.fogTint = fogColour;
_fog._fogTint = fogColour;
} }
if (_atmosphereRenderers.Count() > 0) if (_atmosphereRenderers != null && _atmosphereRenderers.Count() > 0)
{ {
foreach (var lod in _atmosphereRenderers) foreach (var lod in _atmosphereRenderers)
{ {
lod.material.SetFloat("_InnerRadius", CurrentScale); lod.material.SetFloat("_InnerRadius", CurrentScale);
lod.material.SetFloat("_OuterRadius", CurrentScale * StarBuilder.OuterRadiusRatio); lod.material.SetFloat("_OuterRadius", CurrentScale * StarBuilder.OuterRadiusRatio);
lod.material.SetColor("_AtmosFar", currentColour);
lod.material.SetColor("_AtmosNear", currentColour);
lod.material.SetColor("_SkyColor", currentColour); lod.material.SetColor("_SkyColor", currentColour);
} }
} }

View File

@ -12,9 +12,11 @@ namespace NewHorizons.External.VariableSize
public float Size { get; set; } = 2000f; public float Size { get; set; } = 2000f;
public MColor Tint { get; set; } public MColor Tint { get; set; }
public MColor EndTint { get; set; } public MColor EndTint { get; set; }
public MColor SupernovaTint { get; set; }
public MColor SolarFlareTint { get; set; } public MColor SolarFlareTint { get; set; }
public MColor LightTint { get; set; } public MColor LightTint { get; set; }
public float SolarLuminosity { get; set; } = 1f; public float SolarLuminosity { get; set; } = 1f;
public bool HasAtmosphere { get; set; } = true; public bool HasAtmosphere { get; set; } = true;
public bool GoSupernova { get; set; } = true;
} }
} }

View File

@ -622,6 +622,11 @@
"curve": { "curve": {
"$ref": "#/$defs/curve", "$ref": "#/$defs/curve",
"description": "Allows the star to shrink/grow over time." "description": "Allows the star to shrink/grow over time."
},
"goSupernova": {
"type": "boolean",
"default": true,
"description": "Should this star explode after 22 minutes?"
} }
} }
}, },