From d6eb69b5517efcd0389c40f61ec982d2c5ba01d6 Mon Sep 17 00:00:00 2001
From: TerrificTrifid <99054745+TerrificTrifid@users.noreply.github.com>
Date: Thu, 23 Feb 2023 22:56:23 -0600
Subject: [PATCH] Setup AmbientLightModule
---
.../Builder/General/AmbientLightBuilder.cs | 34 ++++++++++++---
NewHorizons/External/Configs/PlanetConfig.cs | 5 +++
.../External/Modules/AmbientLightModule.cs | 42 +++++++++++++++++++
NewHorizons/External/Modules/BaseModule.cs | 10 ++---
4 files changed, 79 insertions(+), 12 deletions(-)
create mode 100644 NewHorizons/External/Modules/AmbientLightModule.cs
diff --git a/NewHorizons/Builder/General/AmbientLightBuilder.cs b/NewHorizons/Builder/General/AmbientLightBuilder.cs
index a3157165..634051a0 100644
--- a/NewHorizons/Builder/General/AmbientLightBuilder.cs
+++ b/NewHorizons/Builder/General/AmbientLightBuilder.cs
@@ -1,10 +1,11 @@
using UnityEngine;
using NewHorizons.Utility;
+using NewHorizons.External.Modules;
namespace NewHorizons.Builder.General
{
public static class AmbientLightBuilder
{
- public static Light Make(GameObject planetGO, Sector sector, float scale, float intensity)
+ public static Light Make(GameObject planetGO, Sector sector, AmbientLightModule config)
{
var ambientLight = Main.Instance.CurrentStarSystem == "EyeOfTheUniverse" ? SearchUtilities.Find("EyeOfTheUniverse_Body/Sector_EyeOfTheUniverse/SixthPlanet_Root/QuantumMoonProxy_Pivot/QuantumMoonProxy_Root/MoonState_Root/AmbientLight_QM") : SearchUtilities.Find("QuantumMoon_Body/AmbientLight_QM");
if (ambientLight == null) return null;
@@ -23,12 +24,33 @@ namespace NewHorizons.Builder.General
light.color = new Color(0.5f, 0.0f, 0.8f, 0.0225f);
light.range = scale;
light.intensity = intensity;
-
- /*if (tint != null)
+
+ var tint = Color.blue; // test
+ var cubemap = (Cubemap)light.cookie;
+ var cubemapFace = CubemapFace.Unknown;
+ for (int i = 0; i < 6; i++)
{
- var cubemap = ImageUtilities.TintImage(ImageUtilities.GetTexture(Main.Instance, "Assets/textures/AmbientLight_QM.png"), tint.ToColor());
- light.cookie = cubemap;
- }*/
+ switch (i)
+ {
+ case 0: cubemapFace = CubemapFace.PositiveX; break;
+ case 1: cubemapFace = CubemapFace.NegativeX; break;
+ case 2: cubemapFace = CubemapFace.PositiveY; break;
+ case 3: cubemapFace = CubemapFace.NegativeY; break;
+ case 4: cubemapFace = CubemapFace.PositiveZ; break;
+ case 5: cubemapFace = CubemapFace.NegativeZ; break;
+ default: break;
+ }
+ var sourceColors = cubemap.GetPixels(cubemapFace, 0);
+ var newColors = new Color[sourceColors.Length];
+ for (int j = 0; j < sourceColors.Length; j++)
+ {
+ var grey = sourceColors[j].grayscale;
+ newColors[j] = tint * new Color(grey, grey, grey);
+ }
+ cubemap.SetPixels(newColors, cubemapFace);
+ }
+ cubemap.Apply();
+ light.cookie = cubemap;
return light;
}
diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs
index ef36bca5..875922df 100644
--- a/NewHorizons/External/Configs/PlanetConfig.cs
+++ b/NewHorizons/External/Configs/PlanetConfig.cs
@@ -27,6 +27,11 @@ namespace NewHorizons.External.Configs
///
[DefaultValue("SolarSystem")] public string starSystem = "SolarSystem";
+ ///
+ /// Add ambient lights to this body
+ ///
+ public AmbientLightModule[] AmbientLights;
+
///
/// Generate asteroids around this body
///
diff --git a/NewHorizons/External/Modules/AmbientLightModule.cs b/NewHorizons/External/Modules/AmbientLightModule.cs
new file mode 100644
index 00000000..af6124d8
--- /dev/null
+++ b/NewHorizons/External/Modules/AmbientLightModule.cs
@@ -0,0 +1,42 @@
+using System;
+using System.ComponentModel;
+using System.ComponentModel.DataAnnotations;
+using NewHorizons.Utility;
+using Newtonsoft.Json;
+
+namespace NewHorizons.External.Modules
+{
+ [JsonObject]
+ public class AmbientLightModule
+ {
+ ///
+ /// The range of the light. Defaults to surfaceSize * 2.
+ ///
+ [Range(0, double.MaxValue)] public float outerRadius;
+
+ ///
+ /// The lower radius where the light is brightest, fading in from outerRadius. Defaults to half of outerRadius.
+ ///
+ [Range(0, double.MaxValue)] public float innerRadius;
+
+ ///
+ /// The brightness of the light. For reference, Timber Hearth is `1.4`, and Giant's Deep is `0.8`.
+ ///
+ [Range(0, double.MaxValue)][DefaultValue(1f)] public float intensity = 1f;
+
+ ///
+ /// The tint of the light
+ ///
+ public MColor tint;
+
+ ///
+ /// If true, the light will start fading away below innerRadius, instead of staying constant. This means that innerRadius will be the midpoint between the outerRadius and an inner cutoff.
+ ///
+ [DefaultValue(false)] public bool isShell = false;
+
+ ///
+ /// The position of the light
+ ///
+ public MVector3 position;
+ }
+}
\ No newline at end of file
diff --git a/NewHorizons/External/Modules/BaseModule.cs b/NewHorizons/External/Modules/BaseModule.cs
index 338f3c05..9c47a59d 100644
--- a/NewHorizons/External/Modules/BaseModule.cs
+++ b/NewHorizons/External/Modules/BaseModule.cs
@@ -19,11 +19,6 @@ namespace NewHorizons.External.Modules
[JsonObject]
public class BaseModule
{
- ///
- /// The intensity of light the dark side of the body should have. Timber Hearth has `1.4` for reference
- ///
- public float ambientLight;
-
///
/// Set this to true if you are replacing the sun with a different body. Only one object in a star system should ever
/// have this set to true.
@@ -103,9 +98,12 @@ namespace NewHorizons.External.Modules
[Obsolete("WaterTint is deprecated, please use WaterModule instead")]
public MColor waterTint;
- [Obsolete("HasAmbientLight is deprecated, please use AmbientLight instead")]
+ [Obsolete("HasAmbientLight is deprecated, please use AmbientLightModule instead")]
public bool hasAmbientLight;
+ [Obsolete("AmbientLight is deprecated, please use AmbientLightModule instead")]
+ public float ambientLight;
+
[Obsolete("HasReferenceFrame is deprecated, please use ReferenceModule instead")]
[DefaultValue(true)] public bool hasReferenceFrame = true;