#include "/lib/voxy_main.glsl"

layout(location = 0) out vec4 outColor;

void voxy_emitFragment(VoxyFragmentParameters parameters) {
    ivec2 pixel = ivec2(gl_FragCoord.xy);
    if (texelFetch(depthtex1, pixel, 0).r < 1.0) {
        discard;
    }

    vec3 playerPosition = voxyPlayerPosition();
    vec3 normal = voxyFaceNormal(parameters.face);
    vec4 base = parameters.sampledColour * parameters.tinting;
    vec3 albedo = max(base.rgb, vec3(0.0));

    // Voxy's translucent LoD is primarily water. Keep the source tint while
    // gently pulling it toward the pack's established distant-water colour.
    albedo = mix(albedo, vec3(0.075, 0.245, 0.315), 0.32);
    vec3 color = voxyApplyLighting(albedo, normal, parameters.lightMap);
    color = voxyApplyAtmosphere(color, playerPosition, normal, parameters.lightMap);
    outColor = vec4(color, clamp(base.a * 0.72, 0.30, 0.72));
}
