// Cranked up a bit since the new blending mode has a less noticeable impact
float perspectiveDitherCutoffDistance = 500.0;
float orthoDitherCutoffDistance = 1000.0;

float transparency = (1.0 - step(0.99, opaqueness)) * max(1.0 - opaqueness * DITHERING_OPACITY_COEFFICIENT, 0.0);

float fakeDistance = pow(min((gl_FragCoord.z / gl_FragCoord.w) / 7.5, 1.0), 1.15);

vec2 samplePosition = (gl_FragCoord.xy / resolution) * ditherSize;
vec3 dither = texture2D(ditherSampler, samplePosition).xyz;

float exponent = dither.r;
float mantissa = dither.g;
float unpackedValue = mantissa * exp2(exponent);

float transparencyWithDistanceImpact = transparency - (fakeDistance * distanceImpact * transparency);
float depth = 0.0;

if(isPerspective) {
    depth = linearizeDepth(gl_FragCoord.z, nearPlane, farPlane);
    depth = smoothstep(0.0, perspectiveDitherCutoffDistance, depth);
} else {
    depth = smoothstep(0.0, orthoDitherCutoffDistance, orthoSize);
}
transparencyWithDistanceImpact = mix(transparencyWithDistanceImpact, 0.0, depth * ditherDistanceFade);
if (unpackedValue < transparencyWithDistanceImpact) {
    discard;
}