Fix shaders that sample at texel edges

Sampling at the edge between texels causes one or the other to be chosen
semi-randomly, depending on rounding errors. Add half a pixel so they
sample at texel centers instead.
This commit is contained in:
LMLB 2018-03-11 14:56:15 +01:00
parent 6e8567eadc
commit 0c80ac3296
3 changed files with 12 additions and 12 deletions

View File

@ -8,10 +8,10 @@ vec4 omniScale(sampler2D image, vec2 texCoord)
{
vec2 pixel = texCoord * textureDimensions - vec2(0.5, 0.5);
vec4 q11 = texture(image, vec2(floor(pixel.x) / textureDimensions.x, floor(pixel.y) / textureDimensions.y));
vec4 q12 = texture(image, vec2(floor(pixel.x) / textureDimensions.x, ceil(pixel.y) / textureDimensions.y));
vec4 q21 = texture(image, vec2(ceil(pixel.x) / textureDimensions.x, floor(pixel.y) / textureDimensions.y));
vec4 q22 = texture(image, vec2(ceil(pixel.x) / textureDimensions.x, ceil(pixel.y) / textureDimensions.y));
vec4 q11 = texture(image, (floor(pixel) + 0.5) / textureDimensions);
vec4 q12 = texture(image, (vec2(floor(pixel.x), ceil(pixel.y)) + 0.5) / textureDimensions);
vec4 q21 = texture(image, (vec2(ceil(pixel.x), floor(pixel.y)) + 0.5) / textureDimensions);
vec4 q22 = texture(image, (ceil(pixel) + 0.5) / textureDimensions);
vec2 pos = fract(pixel);

View File

@ -4,10 +4,10 @@ vec4 scale(sampler2D image)
vec2 pixel = texCoord * textureDimensions - vec2(0.5, 0.5);
vec4 q11 = texture(image, vec2(floor(pixel.x) / textureDimensions.x, floor(pixel.y) / textureDimensions.y));
vec4 q12 = texture(image, vec2(floor(pixel.x) / textureDimensions.x, ceil(pixel.y) / textureDimensions.y));
vec4 q21 = texture(image, vec2(ceil(pixel.x) / textureDimensions.x, floor(pixel.y) / textureDimensions.y));
vec4 q22 = texture(image, vec2(ceil(pixel.x) / textureDimensions.x, ceil(pixel.y) / textureDimensions.y));
vec4 q11 = texture(image, (floor(pixel) + 0.5) / textureDimensions);
vec4 q12 = texture(image, (vec2(floor(pixel.x), ceil(pixel.y)) + 0.5) / textureDimensions);
vec4 q21 = texture(image, (vec2(ceil(pixel.x), floor(pixel.y)) + 0.5) / textureDimensions);
vec4 q22 = texture(image, (ceil(pixel) + 0.5) / textureDimensions);
vec4 r1 = mix(q11, q21, fract(pixel.x));
vec4 r2 = mix(q12, q22, fract(pixel.x));

View File

@ -4,10 +4,10 @@ vec4 scale(sampler2D image)
vec2 pixel = texCoord * textureDimensions - vec2(0.5, 0.5);
vec4 q11 = texture(image, vec2(floor(pixel.x) / textureDimensions.x, floor(pixel.y) / textureDimensions.y));
vec4 q12 = texture(image, vec2(floor(pixel.x) / textureDimensions.x, ceil(pixel.y) / textureDimensions.y));
vec4 q21 = texture(image, vec2(ceil(pixel.x) / textureDimensions.x, floor(pixel.y) / textureDimensions.y));
vec4 q22 = texture(image, vec2(ceil(pixel.x) / textureDimensions.x, ceil(pixel.y) / textureDimensions.y));
vec4 q11 = texture(image, (floor(pixel) + 0.5) / textureDimensions);
vec4 q12 = texture(image, (vec2(floor(pixel.x), ceil(pixel.y)) + 0.5) / textureDimensions);
vec4 q21 = texture(image, (vec2(ceil(pixel.x), floor(pixel.y)) + 0.5) / textureDimensions);
vec4 q22 = texture(image, (ceil(pixel) + 0.5) / textureDimensions);
vec2 s = smoothstep(0., 1., fract(pixel));