From 86d26046f7cdad66031747b88ae055ba158f5567 Mon Sep 17 00:00:00 2001 From: Mario Kleiner Date: Thu, 13 Jul 2023 04:33:21 +0200 Subject: [PATCH] Procedural texture shaders: Remove corrective texture offsets. Issue #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 #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 #800. --- .../PsychOpenGL/PsychGLSLShaders/BasicGaborShader.vert.txt | 4 +--- .../PsychGLSLShaders/BasicGaussBlobShader.vert.txt | 4 +--- .../PsychGLSLShaders/BasicSineGratingShader.vert.txt | 3 +-- .../PsychGLSLShaders/NonSymetricGaborShader.vert.txt | 4 +--- .../SineGratingSmoothedApertureShader.vert.txt | 3 +-- .../PsychOpenGL/PsychGLSLShaders/SmoothedDiscShader.vert.txt | 3 +-- .../PsychGLSLShaders/SquareWaveApertureShader.vert.txt | 3 +-- .../PsychOpenGL/PsychGLSLShaders/SquareWaveShader.vert.txt | 3 +-- 8 files changed, 8 insertions(+), 19 deletions(-) diff --git a/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/BasicGaborShader.vert.txt b/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/BasicGaborShader.vert.txt index a244a8ad82..d9b9728d4c 100644 --- a/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/BasicGaborShader.vert.txt +++ b/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/BasicGaborShader.vert.txt @@ -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]; diff --git a/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/BasicGaussBlobShader.vert.txt b/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/BasicGaussBlobShader.vert.txt index e18635b2f1..d6661a0cf8 100644 --- a/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/BasicGaussBlobShader.vert.txt +++ b/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/BasicGaussBlobShader.vert.txt @@ -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]; diff --git a/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/BasicSineGratingShader.vert.txt b/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/BasicSineGratingShader.vert.txt index 00c3b46f6c..431a64321d 100644 --- a/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/BasicSineGratingShader.vert.txt +++ b/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/BasicSineGratingShader.vert.txt @@ -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]; diff --git a/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/NonSymetricGaborShader.vert.txt b/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/NonSymetricGaborShader.vert.txt index 512a1ed53f..5218771671 100644 --- a/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/NonSymetricGaborShader.vert.txt +++ b/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/NonSymetricGaborShader.vert.txt @@ -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]; diff --git a/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/SineGratingSmoothedApertureShader.vert.txt b/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/SineGratingSmoothedApertureShader.vert.txt index 6823592bd6..bbb44fe7b1 100644 --- a/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/SineGratingSmoothedApertureShader.vert.txt +++ b/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/SineGratingSmoothedApertureShader.vert.txt @@ -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]; diff --git a/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/SmoothedDiscShader.vert.txt b/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/SmoothedDiscShader.vert.txt index 63426eb25b..7ea409961e 100644 --- a/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/SmoothedDiscShader.vert.txt +++ b/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/SmoothedDiscShader.vert.txt @@ -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; diff --git a/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/SquareWaveApertureShader.vert.txt b/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/SquareWaveApertureShader.vert.txt index 08f7ef58a7..e097b88f74 100644 --- a/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/SquareWaveApertureShader.vert.txt +++ b/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/SquareWaveApertureShader.vert.txt @@ -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]; diff --git a/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/SquareWaveShader.vert.txt b/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/SquareWaveShader.vert.txt index 48eba7cda7..c7913a48fe 100644 --- a/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/SquareWaveShader.vert.txt +++ b/Psychtoolbox/PsychOpenGL/PsychGLSLShaders/SquareWaveShader.vert.txt @@ -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];