From 8a6de4cff1a265e31a4c0607660428657fa4b00a Mon Sep 17 00:00:00 2001 From: Pixelflinger Date: Sat, 23 Feb 2019 11:20:35 -0800 Subject: [PATCH] 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. --- shaders/src/post_process.fs | 2 ++ shaders/src/post_process.vs | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/shaders/src/post_process.fs b/shaders/src/post_process.fs index 23d5493c69..1bc90b7a3d 100644 --- a/shaders/src/post_process.fs +++ b/shaders/src/post_process.fs @@ -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; diff --git a/shaders/src/post_process.vs b/shaders/src/post_process.vs index 110bebcc75..38449f30d5 100644 --- a/shaders/src/post_process.vs +++ b/shaders/src/post_process.vs @@ -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;