#version 150 in vec4 colorLeft; in vec4 colorRight; in float edge; in float midpoint; out vec4 fragColor; float curveWithMidpoint(float x, float midpoint) { float sample = pow(x, midpoint / (1.0 - midpoint)); float inverseSample = 1.0 - pow(1.0 - x, (1.0 - midpoint) / midpoint); return (sample + inverseSample) * 0.5; } float sampleDither(ivec2 position, float value) { int index = position.x % 4 + position.y % 4 * 4; float thresholds[16] = float[16](0.5 / 16.0, 12.5 / 16.0, 3.5f / 16.0, 15.5 / 16.0, 8.5 / 16.0, 4.5 / 16.0, 11.5f / 16.0, 7.5 / 16.0, 2.5 / 16.0, 14.5 / 16.0, 1.5f / 16.0, 13.5 / 16.0, 10.5 / 16.0, 6.5 / 16.0, 9.5f / 16.0, 5.5 / 16.0); return value >= thresholds[index] ? 1.0 : 0.0; } void main() { float colorMix = curveWithMidpoint(edge, midpoint); float ditherSample = sampleDither(ivec2(gl_FragCoord), colorMix); fragColor = colorLeft * (1.0 - ditherSample) + colorRight * ditherSample; }