Fix fxaa offset (#868)

vertex shader interpolants are interpolated at pixel centers by the GPU,
but we were doing our own "pixel-center" adjustment, so we ended-up with
"vertex_uv" at a pixel corner instead of center.

with this change, the vertex shader always compute vertex_uv in
fractional texels and the conversion to texture coordinates is done
in the fxaa code.

The half-pixel adjustment is removed.

This leads to sharper looking images because in addition to shifting
everything by 0.5 pixels, this was essentially applying a box-filter
to the whole picture -- kind of like taking 1 mip level down.
This commit is contained in:
Pixelflinger
2019-02-23 11:20:35 -08:00
committed by Mathias Agopian
parent e56ff75e1b
commit 8a6de4cff1
2 changed files with 4 additions and 4 deletions

View File

@@ -50,6 +50,8 @@ vec4 PostProcess_AntiAliasing() {
// Next, compute the coordinates of the texel center and its bounding box. There is no need to
// clamp the min corner since the wrap mode will do it automatically.
// vertex_uv is already interpolated to pixel center by the GPU
HIGHP vec2 texelCenter = min(vertex_uv, upperBound);
HIGHP vec2 texelMaxCorner = min(vertex_uv + halfTexel, upperBound);
HIGHP vec2 texelMinCorner = vertex_uv - halfTexel;

View File

@@ -17,10 +17,8 @@ void main() {
#endif
#if POST_PROCESS_ANTI_ALIASING
// Account for the texture actual size
vertex_uv *= postProcessUniforms.uvScale;
// Compute texel center
vertex_uv = (floor(vertex_uv) + vec2(0.5, 0.5)) * frameUniforms.resolution.zw;
// texel to uv, accounting for the texture actual size
vertex_uv *= frameUniforms.resolution.zw * postProcessUniforms.uvScale;
#endif
gl_Position = position;