uniform float hPaperScale, vPaperScale, vPaperScroll;

float interp(float textureValue, float baseValue) {
    float strength = PAPER_TEXTURE_STRENGTH;
    float istrength = 1.0 - strength;

    return (istrength + strength * textureValue) * baseValue;
}

vec4 applyPaperTexture(vec4 baseColour) {
    float strength = paperTone(gl_FragCoord.x * hPaperScale, (gl_FragCoord.y - vPaperScroll) * vPaperScale);

    vec4 r = vec4(
        interp(strength, baseColour.r),
        interp(strength, baseColour.g),
        interp(strength, baseColour.b),
        baseColour.a
    );

#ifdef GRAYSCALE_BUILD
    // these are the outdated NTSC colours
    float s = 0.299 * r.r + 0.587 * r.g + 0.114 * r.b;
    r = vec4(s, s, s, baseColour.a);
#endif

    return r;
}
