Suns: secondary hue stays on the allowed arc with the primary; ramp never crosses the band

The secondary is placed along the allowed arc (reflected at its ends, distance capped at half
the arc) so the RGB blend between the two stops stays outside the band for any Settings band.
Tests sample the production ramp and pin draw uniformity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-16 19:14:15 +02:00
commit 4930ecd06a
3 changed files with 68 additions and 6 deletions

View file

@ -22,7 +22,24 @@ public static class ColorMath
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 float HueOutsideBand(float u, float start, float end) => frac(end + u * AllowedArc(start, end));
static float AllowedArc(float start, float end) => 1 - frac(end - start);
// The second hue of a pair whose first is HueOutsideBand(u): distance away along the allowed arc, on the side given by up,
// reflected to the other side if that would leave the arc. Both hues lie on one arc, so the straight RGB blend between
// the two stops never crosses the band. The distance is capped at half the arc, so the reflection always fits and a
// wide band shortens the distance instead of leaving the secondary inside it.
public static float SecondaryHueOutsideBand(float u, bool up, float distance, float start, float end)
{
float arc = AllowedArc(start, end);
float d = min(distance, arc / 2);
float t = u * arc;
float s = up ? t + d : t - d;
if (s < 0 || s > arc)
s = up ? t - d : t + d;
return frac(end + s);
}
public static float3 HsvToRgb(in float3 hsv)
{

View file

@ -159,11 +159,10 @@ public static class ZoneGenerator
{
if (gas is SunData sun)
{
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);
var hueDraw = random.NextFloat();
float primary = ColorMath.HueOutsideBand(hueDraw, zoneSettings.SunHueExcludedStart, zoneSettings.SunHueExcludedEnd);
float secondary = ColorMath.SecondaryHueOutsideBand(hueDraw, random.NextFloat() > .5, zoneSettings.SunSecondaryColorDistance,
zoneSettings.SunHueExcludedStart, zoneSettings.SunHueExcludedEnd);
gas.Colors = new []
{
float4(ColorMath.HsvToRgb(float3(primary, zoneSettings.SunColorSaturation, .5f)), 0),