#ifndef WE_ASTRAL_NIGHT_INCLUDED
#define WE_ASTRAL_NIGHT_INCLUDED

// Guarded because four of Solas's programs reach this file down two different
// paths - gbuffers_water, gbuffers_textured, dh_water and voxyTranslucent all
// pull in both the lighting and the atmosphere libraries - and a second copy of
// a const and a function is a compile error, not a warning.

// World Evils - is the camera standing in the Astral Infection?
//
// There is no biome uniform to ask. Iris exposes none, and the one OptiFine
// defines is an index into the biome registry, which for a modded biome is
// whatever number that particular world happened to assign it - useless to a
// shader compiled once.
//
// So the mod hands the answer over through a uniform that does exist. Inside
// the Astral it pins skyColor to the biome's own purple, held at the biome's
// permanent-night level and constant at every hour - see AstralSky.dimSky.
// Nothing in vanilla is that colour: every vanilla sky is a blue with green
// above red, and this is a purple with red above green and almost no green.
//
// Matched on direction rather than magnitude, for two reasons. Solas itself
// only ever uses normalize(skyColor), so hue is the part that survives; and it
// means the test still holds if a future Iris feeds the raw biome colour
// instead of the lit one, because both have the same hue.

const vec3 WE_ASTRAL_SKY_HUE = normalize(vec3(42.0, 18.0, 64.0));

// How dark the Astral gets under shaders. Zero would be a black void with no
// horizon in it at all; this leaves the shape of the land readable, which is
// the same call SKY_LIGHT_LEVEL = 4 makes on the vanilla side.
#define WE_ASTRAL_NIGHT_LIGHT 0.22

float weAstralNight() {
    vec3 hue = normalize(skyColor + 0.000001);
    // 0.995 is tight. The nearest thing in the game is the Corruption's own sky
    // at about 0.98, and that biome is meant to keep its daylight.
    return step(0.995, dot(hue, WE_ASTRAL_SKY_HUE));
}

#endif
