#version 150

uniform sampler2D InSampler;

in vec2 texCoord;
in vec2 oneTexel;

layout(std140) uniform SamplerInfo {
    vec2 OutSize;
    vec2 InSize;
};

layout(std140) uniform BitsConfig {
    float Saturation;
};

uniform float ColorResolution = 8.0;

out vec4 fragColor;

void main() {
    vec2 scaleFactors = InSize / 2;
    vec2 truncPos = floor(texCoord * scaleFactors) / scaleFactors;
    vec4 baseTexel = texture2D(InSampler, truncPos);
    vec3 truncTexel = floor(baseTexel.rgb * ColorResolution) / ColorResolution;

    float luma = dot(truncTexel, vec3(0.3, 0.59, 0.11));
    vec3 chroma = (truncTexel - luma) * Saturation;
    fragColor = vec4(luma + chroma, 1.0);
}