Skip to content

Commit

Permalink
Procedural texture shaders: Remove corrective texture offsets.
Browse files Browse the repository at this point in the history
Issue Psychtoolbox-3#800 suggests that it is no longer needed or helpful, but
harmful. The offsets were applied in the past to correct for
hardware texture sampling offsets of 0.5 texels. This was very
neccessary 10+ years ago.

What may have happened is that somebody at Khronos added a new
texture sampling conformance test case to their OpenGL conformance
test suite (CTS). Then a new version of the CTS was released to the
gpu hardware vendors. They rerun the CTS against their drivers,
found this conformance failure and fixed their OpenGL drivers, so
that nowadays those texture sampling offsets no longer exist in
modern driver + gpu combos. And this way our fix for texture
sampling offsets turned into a bug that causes offsets on properly
working drivers + gpu hardware.

I've tested BasicGaborShader with the test code from issue Psychtoolbox-3#800
on multiple gpu's on Linux, Windows and macOS and could reproduce
the problem, and the fix. Removing the sampling offset correction
from BasicGaborShader.vert.txt fixed the shading on all current
OS + gpu combos. The assumption is that the same issue and fix
translate to all other procedural texture shaders, so the same
fix is applied to all procedural shaders.

Lets see if this holds up. Thanks to @qx1147 for propsing this
fix. Heads up to @iandol for Opticka.

Hopefully fixes Psychtoolbox-3#800.
  • Loading branch information
kleinerm committed Jul 13, 2023
1 parent 6cc9167 commit 86d2604
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ void main()
/* Apply standard geometric transformations to patch: */
gl_Position = ftransform();

/* Don't pass real texture coordinates, but ones corrected for hardware offsets (-0.5,0.5) */
/* and so that the center of the gabor patch has coordinate (0,0): */
gl_TexCoord[0] = gl_MultiTexCoord0 - vec4(Center, 0.0, 0.0) + vec4(-0.5, 0.5, 0.0, 0.0);
gl_TexCoord[0] = gl_MultiTexCoord0 - vec4(Center, 0.0, 0.0);

/* Contrast value is stored in auxParameters0[3]: */
float Contrast = auxParameters0[3];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ void main()
/* Apply standard geometric transformations to patch: */
gl_Position = ftransform();

/* Don't pass real texture coordinates, but ones corrected for hardware offsets (-0.5,0.5) */
/* and so that the center of the gabor patch has coordinate (0,0): */
gl_TexCoord[0] = gl_MultiTexCoord0 - vec4(Center, 0.0, 0.0) + vec4(-0.5, 0.5, 0.0, 0.0);
gl_TexCoord[0] = gl_MultiTexCoord0 - vec4(Center, 0.0, 0.0);

/* Contrast value is stored in auxParameters0[0]: */
float Contrast = auxParameters0[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ void main()
/* Apply standard geometric transformations to patch: */
gl_Position = ftransform();

/* Don't pass real texture coordinates, but ones corrected for hardware offsets (-0.5,0.5) */
gl_TexCoord[0] = (gl_TextureMatrix[0] * gl_MultiTexCoord0) + vec4(-0.5, 0.5, 0.0, 0.0);
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;

/* Contrast value is stored in auxParameters0[2]: */
float Contrast = auxParameters0[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ void main()
/* Apply standard geometric transformations to patch: */
gl_Position = ftransform();

/* Don't pass real texture coordinates, but ones corrected for hardware offsets (-0.5,0.5) */
/* and so that the center of the gabor patch has coordinate (0,0): */
gl_TexCoord[0] = gl_MultiTexCoord0 - vec4(Center, 0.0, 0.0) + vec4(-0.5, 0.5, 0.0, 0.0);
gl_TexCoord[0] = gl_MultiTexCoord0 - vec4(Center, 0.0, 0.0);

/* Contrast value is stored in auxParameters0[3]: */
float Contrast = auxParameters0[3];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ void main()
/* Apply standard geometric transformations to patch: */
gl_Position = ftransform();

/* Don't pass real texture coordinates, but ones corrected for hardware offsets (-0.5,0.5) */
gl_TexCoord[0] = (gl_TextureMatrix[0] * gl_MultiTexCoord0) + vec4(-0.5, 0.5, 0.0, 0.0);
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;

/* Contrast value is stored in auxParameters0[2]: */
float Contrast = auxParameters0[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ void main()
/* Apply standard geometric transformations to patch: */
gl_Position = ftransform();

/* Don't pass real texture coordinates, but ones corrected for hardware offsets (-0.5,0.5) */
gl_TexCoord[0] = (gl_TextureMatrix[0] * gl_MultiTexCoord0) + vec4(-0.5, 0.5, 0.0, 0.0);
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;

/* Premultiply the wanted Contrast to the color: */
baseColor = modulateColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ void main()
/* Apply standard geometric transformations to patch: */
gl_Position = ftransform();

/* Don't pass real texture coordinates, but ones corrected for hardware offsets (-0.5,0.5) */
gl_TexCoord[0] = (gl_TextureMatrix[0] * gl_MultiTexCoord0) + vec4(-0.5, 0.5, 0.0, 0.0);
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;

/* Contrast value is stored in auxParameters0[2]: */
float Contrast = auxParameters0[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ void main()
/* Apply standard geometric transformations to patch: */
gl_Position = ftransform();

/* Don't pass real texture coordinates, but ones corrected for hardware offsets (-0.5,0.5) */
gl_TexCoord[0] = (gl_TextureMatrix[0] * gl_MultiTexCoord0) + vec4(-0.5, 0.5, 0.0, 0.0);
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;

/* Contrast value is stored in auxParameters0[2]: */
float Contrast = auxParameters0[2];
Expand Down

0 comments on commit 86d2604

Please sign in to comment.