// ============================================================================
// Realistic Water Color (original Unbound feature, not ported from any pack)
//
// Vanilla water color in this pack (WATERCOLOR_R/G/B) is a single flat tint
// applied no matter how much water the view ray actually passed through -
// a puddle and the bottom of the ocean get the same color. Real water isn't
// like that: it absorbs light unevenly per wavelength (red goes first, then
// green, blue travels furthest), so shallow water looks clear/true-color and
// only turns blue-green once light has traveled far enough through it.
//
// This models that with a simple per-channel Beer-Lambert falloff: each
// color channel exponentially decays toward a "deep water" target color at
// its own rate (RW_ABSORB_R/G/B), scaled by how far the ray traveled through
// water and by RW_CLARITY (how far you can see before it washes out).
// ============================================================================
#ifndef INCLUDE_REALISTIC_WATER_COLOR
#define INCLUDE_REALISTIC_WATER_COLOR

vec3 GetRealisticWaterColor(vec3 baseColor, vec3 deepColor, float travelDistance) {
    float clarityM = max(RW_CLARITY * 0.01, 0.01);
    vec3 absorbCoeff = vec3(RW_ABSORB_R, RW_ABSORB_G, RW_ABSORB_B) * 0.01;

    // How much of the ray's path was spent "in" water, normalized by clarity.
    vec3 opticalDepth = max0(travelDistance) * absorbCoeff * (0.3 / clarityM);
    vec3 transmittance = exp2(-opticalDepth);

    // Near the light source/surface (small travelDistance) transmittance ~1,
    // so baseColor (the true/clear color) dominates. Further through the
    // water, transmittance -> 0 and it settles into deepColor.
    return mix(deepColor, baseColor, transmittance);
}

#endif
