Setup AmbientLightModule

This commit is contained in:
TerrificTrifid 2023-02-23 22:56:23 -06:00
parent c33150823d
commit d6eb69b551
4 changed files with 79 additions and 12 deletions

View File

@ -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;
@ -24,11 +25,32 @@ namespace NewHorizons.Builder.General
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());
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;
}

View File

@ -27,6 +27,11 @@ namespace NewHorizons.External.Configs
/// </summary>
[DefaultValue("SolarSystem")] public string starSystem = "SolarSystem";
/// <summary>
/// Add ambient lights to this body
/// </summary>
public AmbientLightModule[] AmbientLights;
/// <summary>
/// Generate asteroids around this body
/// </summary>

View File

@ -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
{
/// <summary>
/// The range of the light. Defaults to surfaceSize * 2.
/// </summary>
[Range(0, double.MaxValue)] public float outerRadius;
/// <summary>
/// The lower radius where the light is brightest, fading in from outerRadius. Defaults to half of outerRadius.
/// </summary>
[Range(0, double.MaxValue)] public float innerRadius;
/// <summary>
/// The brightness of the light. For reference, Timber Hearth is `1.4`, and Giant's Deep is `0.8`.
/// </summary>
[Range(0, double.MaxValue)][DefaultValue(1f)] public float intensity = 1f;
/// <summary>
/// The tint of the light
/// </summary>
public MColor tint;
/// <summary>
/// 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.
/// </summary>
[DefaultValue(false)] public bool isShell = false;
/// <summary>
/// The position of the light
/// </summary>
public MVector3 position;
}
}

View File

@ -19,11 +19,6 @@ namespace NewHorizons.External.Modules
[JsonObject]
public class BaseModule
{
/// <summary>
/// The intensity of light the dark side of the body should have. Timber Hearth has `1.4` for reference
/// </summary>
public float ambientLight;
/// <summary>
/// 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;