mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Make sun appear dimmer on atmo shader when it should
This commit is contained in:
parent
d66f179eb7
commit
3479e60c0d
@ -1,5 +1,6 @@
|
|||||||
using NewHorizons.External.Modules;
|
using NewHorizons.External.Modules;
|
||||||
using NewHorizons.Utility;
|
using NewHorizons.Utility;
|
||||||
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
namespace NewHorizons.Builder.Atmosphere
|
namespace NewHorizons.Builder.Atmosphere
|
||||||
{
|
{
|
||||||
@ -9,6 +10,13 @@ namespace NewHorizons.Builder.Atmosphere
|
|||||||
private static readonly int OuterRadius = Shader.PropertyToID("_OuterRadius");
|
private static readonly int OuterRadius = Shader.PropertyToID("_OuterRadius");
|
||||||
private static readonly int SkyColor = Shader.PropertyToID("_SkyColor");
|
private static readonly int SkyColor = Shader.PropertyToID("_SkyColor");
|
||||||
|
|
||||||
|
public static readonly List<(GameObject, Material)> Skys = new();
|
||||||
|
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
Skys.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmosphereModule, float surfaceSize)
|
public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmosphereModule, float surfaceSize)
|
||||||
{
|
{
|
||||||
GameObject atmoGO = new GameObject("Atmosphere");
|
GameObject atmoGO = new GameObject("Atmosphere");
|
||||||
@ -20,15 +28,20 @@ namespace NewHorizons.Builder.Atmosphere
|
|||||||
GameObject atmo = GameObject.Instantiate(SearchUtilities.Find("TimberHearth_Body/Atmosphere_TH/AtmoSphere"), atmoGO.transform, true);
|
GameObject atmo = GameObject.Instantiate(SearchUtilities.Find("TimberHearth_Body/Atmosphere_TH/AtmoSphere"), atmoGO.transform, true);
|
||||||
atmo.transform.position = planetGO.transform.TransformPoint(Vector3.zero);
|
atmo.transform.position = planetGO.transform.TransformPoint(Vector3.zero);
|
||||||
atmo.transform.localScale = Vector3.one * atmosphereModule.size * 1.2f;
|
atmo.transform.localScale = Vector3.one * atmosphereModule.size * 1.2f;
|
||||||
foreach (var meshRenderer in atmo.GetComponentsInChildren<MeshRenderer>())
|
|
||||||
|
var renderers = atmo.GetComponentsInChildren<MeshRenderer>();
|
||||||
|
var sharedMaterial = new Material(renderers[0].material);
|
||||||
|
foreach (var meshRenderer in renderers)
|
||||||
{
|
{
|
||||||
meshRenderer.material.SetFloat(InnerRadius, atmosphereModule.clouds != null ? atmosphereModule.size : surfaceSize);
|
meshRenderer.sharedMaterial = sharedMaterial;
|
||||||
meshRenderer.material.SetFloat(OuterRadius, atmosphereModule.size * 1.2f);
|
|
||||||
if (atmosphereModule.atmosphereTint != null)
|
|
||||||
meshRenderer.material.SetColor(SkyColor, atmosphereModule.atmosphereTint.ToColor());
|
|
||||||
}
|
}
|
||||||
|
sharedMaterial.SetFloat(InnerRadius, atmosphereModule.clouds != null ? atmosphereModule.size : surfaceSize);
|
||||||
|
sharedMaterial.SetFloat(OuterRadius, atmosphereModule.size * 1.2f);
|
||||||
|
if (atmosphereModule.atmosphereTint != null) sharedMaterial.SetColor(SkyColor, atmosphereModule.atmosphereTint.ToColor());
|
||||||
|
|
||||||
atmo.SetActive(true);
|
atmo.SetActive(true);
|
||||||
|
|
||||||
|
Skys.Add((planetGO, sharedMaterial));
|
||||||
}
|
}
|
||||||
|
|
||||||
atmoGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero);
|
atmoGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero);
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using NewHorizons.Builder.Atmosphere;
|
||||||
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Logger = NewHorizons.Utility.Logger;
|
using Logger = NewHorizons.Utility.Logger;
|
||||||
namespace NewHorizons.Components
|
namespace NewHorizons.Components
|
||||||
@ -7,6 +8,9 @@ namespace NewHorizons.Components
|
|||||||
[RequireComponent(typeof(SunLightParamUpdater))]
|
[RequireComponent(typeof(SunLightParamUpdater))]
|
||||||
public class StarLightController : MonoBehaviour
|
public class StarLightController : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
private static readonly int SunIntensity = Shader.PropertyToID("_SunIntensity");
|
||||||
|
private static readonly float hearthSunDistanceSqr = 8593 * 8593;
|
||||||
|
|
||||||
public static StarLightController Instance { get; private set; }
|
public static StarLightController Instance { get; private set; }
|
||||||
|
|
||||||
private List<StarController> _stars = new List<StarController>();
|
private List<StarController> _stars = new List<StarController>();
|
||||||
@ -57,9 +61,27 @@ namespace NewHorizons.Components
|
|||||||
if (_stars.Count > 0) ChangeActiveStar(_stars[0]);
|
if (_stars.Count > 0) ChangeActiveStar(_stars[0]);
|
||||||
else gameObject.SetActive(false);
|
else gameObject.SetActive(false);
|
||||||
|
|
||||||
|
foreach (var atmo in AtmosphereBuilder.Skys)
|
||||||
|
{
|
||||||
|
var shader = atmo.Item2;
|
||||||
|
shader.SetFloat(SunIntensity, 0);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update atmo shaders
|
||||||
|
foreach (var atmo in AtmosphereBuilder.Skys)
|
||||||
|
{
|
||||||
|
var planet = atmo.Item1;
|
||||||
|
var shader = atmo.Item2;
|
||||||
|
|
||||||
|
var sqrDist = (planet.transform.position - _activeStar.transform.position).sqrMagnitude;
|
||||||
|
var intensity = Mathf.Min(_activeStar.Light.intensity / (sqrDist / hearthSunDistanceSqr), 2f);
|
||||||
|
|
||||||
|
shader.SetFloat(SunIntensity, intensity);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var star in _stars)
|
foreach (var star in _stars)
|
||||||
{
|
{
|
||||||
if (star == null) continue;
|
if (star == null) continue;
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using NewHorizons.AchievementsPlus;
|
using NewHorizons.AchievementsPlus;
|
||||||
|
using NewHorizons.Builder.Atmosphere;
|
||||||
using NewHorizons.Builder.Body;
|
using NewHorizons.Builder.Body;
|
||||||
using NewHorizons.Builder.Props;
|
using NewHorizons.Builder.Props;
|
||||||
using NewHorizons.Components;
|
using NewHorizons.Components;
|
||||||
@ -274,11 +275,14 @@ namespace NewHorizons
|
|||||||
IsSystemReady = false;
|
IsSystemReady = false;
|
||||||
|
|
||||||
NewHorizonsData.Load();
|
NewHorizonsData.Load();
|
||||||
|
|
||||||
|
// Some builders have to be reset each loop
|
||||||
SignalBuilder.Init();
|
SignalBuilder.Init();
|
||||||
BrambleDimensionBuilder.Init();
|
BrambleDimensionBuilder.Init();
|
||||||
AstroObjectLocator.Init();
|
AstroObjectLocator.Init();
|
||||||
StreamingHandler.Init();
|
StreamingHandler.Init();
|
||||||
AudioTypeHandler.Init();
|
AudioTypeHandler.Init();
|
||||||
|
AtmosphereBuilder.Init();
|
||||||
BrambleNodeBuilder.Init(BodyDict[CurrentStarSystem].Select(x => x.Config).Where(x => x.Bramble?.dimension != null).ToArray());
|
BrambleNodeBuilder.Init(BodyDict[CurrentStarSystem].Select(x => x.Config).Where(x => x.Bramble?.dimension != null).ToArray());
|
||||||
|
|
||||||
PlanetCreationHandler.Init(BodyDict[CurrentStarSystem]);
|
PlanetCreationHandler.Init(BodyDict[CurrentStarSystem]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user