#version 150 in vec2 vertTexCoord; uniform sampler2DRect colorTexture; uniform float texelsPerFragment; out vec4 fragColor; // TODO: Use textureSize and texelFetch instead of texture() and texelsPerFragment void main() { float halfTexelsPerFragment = texelsPerFragment * 0.5; vec2 contributingTexCoords[2]; contributingTexCoords[0] = vec2(vertTexCoord.x - halfTexelsPerFragment, vertTexCoord.y - halfTexelsPerFragment); contributingTexCoords[1] = vec2(vertTexCoord.x + halfTexelsPerFragment, vertTexCoord.y + halfTexelsPerFragment); float weights[4]; float weightX = min(1.0, (ceil(contributingTexCoords[0].x) - contributingTexCoords[0].x) / texelsPerFragment); float weightY = min(1.0, (ceil(contributingTexCoords[0].y) - contributingTexCoords[0].y) / texelsPerFragment); weights[0] = weightX * weightY; weights[1] = (1.0 - weightX) * weightY; weights[2] = weightX * (1.0 - weightY); weights[3] = (1.0 - weightX) * (1.0 - weightY); fragColor = vec4(0.0, 0.0, 0.0, 0.0); for (int indexY = 0; indexY < 2; indexY++) { for (int indexX = 0; indexX < 2; indexX++) { fragColor += texture(colorTexture, vec2(contributingTexCoords[indexX].x, contributingTexCoords[indexY].y)) * weights[indexY * 2 + indexX]; } } }