

uniform sampler2D noisetex;
uniform sampler2D colortex14;

float blueNoise(vec2 coord)
{
    return fract(texelFetch2D(noisetex, ivec2(coord.xy) % 512, 0).a + 1.0 / 1.6180339887 * frameCounter);
}
float blueNoise2(vec2 coord)
{
    return fract(texelFetch2D(noisetex, ivec2(coord.xy) % 512, 0).a + 1.0 / 1.6180339887 );
}

float R2_dither_slow(vec2 coord)
{
    vec2 alpha = vec2(0.75487765, 0.56984026);
    return fract(alpha.x * coord.x + alpha.y * coord.y + 1.0 / 1.6180339887 * frameCounter * 0.001);
}
float R2_dither(vec2 coord)
{
    vec2 alpha = vec2(0.75487765, 0.56984026);
    return fract(alpha.x * coord.x + alpha.y * coord.y + 1.0 / 1.6180339887 * frameCounter);
}

float R2_dither(int iteration, vec2 coord)
{
    return fract(0.75487765 * coord.x + 0.56984026 * coord.y +
                 1.0 / 1.6180339887 * (float(iteration * 0.5) + (frameCounter)));
}

float InterleavedGradientNoise(vec2 uv)
{
    const vec3 magic = vec3(0.06711056, 0.00583715, 52.9829189);
    return fract(magic.z * fract(dot(uv, magic.xy)));
}

vec2 R2_samples3(int n)
{
    vec2 alpha = vec2(0.75487765, 0.56984026);
    return fract(alpha * n);
}
vec4 blueNoise4(vec2 coord)
{
    return fract(texelFetch2D(colortex14, ivec2(coord) % 512, 0) + 1.0 / 1.6180339887 * frameCounter);
}

vec4 blueNoise3(vec2 coord)
{
    return texelFetch2D(colortex14, ivec2(coord) % 512, 0);
}

float noise_standard(vec2 coord)
{
#ifdef HQ_NOISE
    return blueNoise(coord);
#else
    return R2_dither(coord);
#endif
}
