#version 150 in vec2 vertTexCoord; uniform sampler2DRect colorTexture; out vec4 fragColor; void main() { float changePerTexel = fwidth(vertTexCoord.x); vec2 nearestNeighborTexCoord = vertTexCoord; nearestNeighborTexCoord.x = floor(nearestNeighborTexCoord.x) + 0.5; nearestNeighborTexCoord.y = floor(nearestNeighborTexCoord.y) + 0.5; vec2 difference = nearestNeighborTexCoord - vertTexCoord; vec2 edgeDistance = vec2(0.5 - abs(difference.x), 0.5 - abs(difference.y)); vec2 biasedTexCoord = vertTexCoord + difference * min(vec2(1.0, 1.0), edgeDistance / (changePerTexel / 2)); fragColor = texture(colorTexture, biasedTexCoord); }