Implement settings

This commit is contained in:
TerrificTrifid 2023-02-25 17:06:07 -06:00
parent 6442f6bb22
commit 441618e8c3
2 changed files with 35 additions and 29 deletions

View File

@ -11,7 +11,7 @@ namespace NewHorizons.Builder.General
if (ambientLight == null) return null;
GameObject lightGO = GameObject.Instantiate(ambientLight, sector?.transform ?? planetGO.transform);
lightGO.transform.position = planetGO.transform.position;
lightGO.transform.position = config.position ?? planetGO.transform.position;
lightGO.name = "AmbientLight";
var light = lightGO.GetComponent<Light>();
@ -21,36 +21,42 @@ namespace NewHorizons.Builder.General
* A is the intensity and its like square rooted and squared and idgi
*/
light.color = new Color(0.5f, 0.0f, 0.8f, 0.0225f);
light.range = scale;
light.intensity = intensity;
light.intensity = config.intensity;
light.range = config.outerRadius ?? surfaceSize * 2;
var innerRadius = config.innerRadius ?? surfaceSize;
innerRadius = Mathf.Clamp01(innerRadius / light.range);
var shell = config.isShell ? 1f : 0f;
light.color = new Color(innerRadius, shell, 0.8f, 0.0225f);
var tint = Color.blue; // test
var cubemap = (Cubemap)light.cookie;
var cubemapFace = CubemapFace.Unknown;
for (int i = 0; i < 6; i++)
if (config.tint != null)
{
switch (i)
var tint = config.tint.ToColor();
var cubemap = (Cubemap)light.cookie;
var cubemapFace = CubemapFace.Unknown;
for (int i = 0; i < 6; 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;
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);
}
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;
}
cubemap.Apply();
light.cookie = cubemap;
return light;
}

View File

@ -12,12 +12,12 @@ namespace NewHorizons.External.Modules
/// <summary>
/// The range of the light. Defaults to surfaceSize * 2.
/// </summary>
[Range(0, double.MaxValue)] public float outerRadius;
[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.
/// The lower radius where the light is brightest, fading in from outerRadius. Defaults to surfaceSize.
/// </summary>
[Range(0, double.MaxValue)] public float innerRadius;
[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`.