[32/35] libcamera: shaders: Fix neighbouring positions in 8-bit debayering
diff mbox series

Message ID 20250611013245.133785-33-bryan.odonoghue@linaro.org
State New
Headers show
Series
  • Add GLES 2.0 GPUISP to libcamera
Related show

Commit Message

Bryan O'Donoghue June 11, 2025, 1:32 a.m. UTC
From: Milan Zamazal <mzamazal@redhat.com>

When accessing a texture position in a shader, the pixel with the
nearest centre to the specified texture coordinates (as mandated by
specifying GL_NEAREST parameter) is taken.  The current vertex shader
determines the positions of the neighbouring pixels by adding the
provided texture steps to the exact centre pixel coordinates.  But this
places the computed coordinates, from the point of view of GL_NEAREST,
exactly between the pixels and is thus prone to floating point
inaccuracies.  Wrong neighbouring pixel coordinates may be used,
resulting in artefacts in the output image.

Let's fix the problem by shifting the initial coordinates a bit from the
pixel border.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
---
 include/libcamera/internal/shaders/bayer_8.vert | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Patch
diff mbox series

diff --git a/include/libcamera/internal/shaders/bayer_8.vert b/include/libcamera/internal/shaders/bayer_8.vert
index fb5109ee..fc1cf89f 100644
--- a/include/libcamera/internal/shaders/bayer_8.vert
+++ b/include/libcamera/internal/shaders/bayer_8.vert
@@ -44,10 +44,10 @@  void main(void) {
     center.xy = textureIn;
     center.zw = textureIn * tex_size + tex_bayer_first_red;
 
-    xCoord = center.x + vec4(-2.0 * tex_step.x,
-                             -tex_step.x, tex_step.x, 2.0 * tex_step.x);
-    yCoord = center.y + vec4(-2.0 * tex_step.y,
-                              -tex_step.y, tex_step.y, 2.0 * tex_step.y);
+    xCoord = center.x + 0.1 * tex_step.x +
+      vec4(-2.0 * tex_step.x, -tex_step.x, tex_step.x, 2.0 * tex_step.x);
+    yCoord = center.y + 0.1 * tex_step.y +
+      vec4(-2.0 * tex_step.y, -tex_step.y, tex_step.y, 2.0 * tex_step.y);
 
     gl_Position = proj_matrix * vertexIn;
 }