libcamera: shaders: Fix neighbouring positions in 8-bit debayering

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>
This commit is contained in:
Milan Zamazal 2025-04-29 13:56:25 +02:00 committed by Bryan O'Donoghue
parent 6637b468b7
commit 9b66144aad

View file

@ -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;
}