fogTransmittance function
FogTransmittance of contributor_eye.glsl: how much of a point the fog
leaves, from nought to one — ApplyFog's share in color.glsl, the
height fog integrated along the ray, so a spark high over the eye fogs as
the thinner air up there does. One with no fog.
Implementation
double fogTransmittance(ShaderBindings b, double x, double y, double z) {
final fog = b.vec4('FogInfo', 'fog', Vector4.zero());
if (fog.w <= 0.0) return 1.0;
final eye = b.vec4('FogInfo', 'eye', Vector4.zero());
final falloff = eye.w;
final k = falloff * (y - eye.y);
final density = falloff <= 0.0
? fog.w
: fog.w * (k.abs() > 1e-3 ? (1.0 - math.exp(-k)) / k : 1.0 - 0.5 * k);
return math.exp(-density * fogDistance(b, x, y, z)).clamp(0.0, 1.0);
}