Suns never take a green hue: draw sun hues from the circle minus a Settings band

Primary hue maps through ColorMath.HueOutsideBand; the secondary takes the
out-of-band side; fog tint and light derive from primary. Band edges are
SunHueExcludedStart/End (75 and 165 degrees by default).

Not yet verified on Yggdrasil at this commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-16 17:20:52 +02:00
commit 0f26c4bb35
4 changed files with 156 additions and 2 deletions

View file

@ -18,6 +18,12 @@ public static class ColorMath
return saturate(float3(r,g,b));
}
// A hue band on the circle runs from start up to end, wrapping past 1 when end < start.
public static bool HueInBand(float hue, float start, float end) => frac(hue - start) < frac(end - start);
// Maps u in [0,1) onto the hues outside the band, so a uniform draw stays uniform over the allowed arc.
public static float HueOutsideBand(float u, float start, float end) => frac(end + u * (1 - frac(end - start)));
public static float3 HsvToRgb(in float3 hsv)
{
float3 rgb = HueToRgb(hsv.x);

View file

@ -142,6 +142,9 @@ public class ZoneGenerationSettings
public float SunSecondaryColorDistance = .25f;
public float SunLightSaturation = .5f;
public float SunFogTintSaturation = .5f;
// The green band no sun colour may take, as fractions of the hue circle (75 to 165 degrees: chartreuse through spring green).
public float SunHueExcludedStart = 75f / 360f;
public float SunHueExcludedEnd = 165f / 360f;
public ExponentialLerp GasGiantBandCount;
public float GasGiantBandColorSeparation = .25f;

View file

@ -159,8 +159,11 @@ public static class ZoneGenerator
{
if (gas is SunData sun)
{
float primary = random.NextFloat();
float secondary = frac(primary + 1 + zoneSettings.SunSecondaryColorDistance * (random.NextFloat() > .5 ? 1 : -1));
float primary = ColorMath.HueOutsideBand(random.NextFloat(), zoneSettings.SunHueExcludedStart, zoneSettings.SunHueExcludedEnd);
float step = zoneSettings.SunSecondaryColorDistance * (random.NextFloat() > .5 ? 1 : -1);
float secondary = frac(primary + 1 + step);
if (ColorMath.HueInBand(secondary, zoneSettings.SunHueExcludedStart, zoneSettings.SunHueExcludedEnd))
secondary = frac(primary + 1 - step);
gas.Colors = new []
{
float4(ColorMath.HsvToRgb(float3(primary, zoneSettings.SunColorSaturation, .5f)), 0),