vec4 packDepth24(in float depth)
{
    // Constants
    const vec3 scale  = vec3(1.0, 256.0, 65536.0);
    const vec2 ogb    = vec2(65536.0, 256.0) / 16777215.0;
    const float normal  = 256.0 / 255.0;

    // Avoid Precision Errors
    vec3 unit         = vec3 (depth, depth, depth);
    unit.gb             -= floor(unit.gb / ogb) * ogb;

    // Scale Up
    vec3 color        = unit * scale;

    // Use Fraction to emulate Modulo
    color               = fract(color);

    // Normalize Range
    color               *= normal;

    // Mask Noise
    color.rg            -= color.gb / 256.0;

    return vec4(color,1.0);
}

void main()
{
  gl_FragColor = packDepth24(gl_FragCoord.z);
}
