From 3cb87363082157b151dcbfc0e1172ee711d515a6 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauld.mccarthy@gmail.com>
Date: Fri, 30 Jan 2015 12:06:35 +0000
Subject: [PATCH] Image textures now clamp to edge values, rather than
 returning 0.

---
 fsl/fslview/gl/gl21/glvolume_frag.glsl  |  6 +++---
 fsl/fslview/gl/gl21/test_in_bounds.glsl | 11 -----------
 fsl/fslview/gl/textures.py              | 15 +++++++--------
 3 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/fsl/fslview/gl/gl21/glvolume_frag.glsl b/fsl/fslview/gl/gl21/glvolume_frag.glsl
index 70052b9c2..db0791778 100644
--- a/fsl/fslview/gl/gl21/glvolume_frag.glsl
+++ b/fsl/fslview/gl/gl21/glvolume_frag.glsl
@@ -58,18 +58,18 @@ void main(void) {
     /* 
      * Normalise voxel coordinates to (0.0, 1.0)
      */
-    voxCoords.xyz = voxCoords.xyz / imageShape.xyz;
+    voxCoords = voxCoords / imageShape;
 
     /*
      * Look up the voxel value 
      */
     float voxValue;
     if (useSpline) voxValue = spline_interp(imageTexture,
-                                            voxCoords.xyz,
+                                            voxCoords,
                                             imageShape,
                                             0);
     else           voxValue = texture3D(    imageTexture,
-                                            voxCoords.xyz).r;
+                                            voxCoords).r;
 
     /*
      * Transform the voxel value to a colour map texture
diff --git a/fsl/fslview/gl/gl21/test_in_bounds.glsl b/fsl/fslview/gl/gl21/test_in_bounds.glsl
index d01b2dd56..8c0d9971f 100644
--- a/fsl/fslview/gl/gl21/test_in_bounds.glsl
+++ b/fsl/fslview/gl/gl21/test_in_bounds.glsl
@@ -14,16 +14,5 @@ bool test_in_bounds(inout vec3 coords, vec3 shape) {
         return false;
     }
 
-    /*
-     * Be lenient at voxel boundaries
-     */
-    if (coords.x <  0.0)     coords.x = 0.01;
-    if (coords.y <  0.0)     coords.y = 0.01;
-    if (coords.z <  0.0)     coords.z = 0.01; 
-    if (coords.x >= shape.x) coords.x = shape.x - 0.01;
-    if (coords.y >= shape.y) coords.y = shape.y - 0.01;
-    if (coords.z >= shape.z) coords.z = shape.z - 0.01;
-
-
     return true;
 }
\ No newline at end of file
diff --git a/fsl/fslview/gl/textures.py b/fsl/fslview/gl/textures.py
index f4227aa20..fc8bc68f0 100644
--- a/fsl/fslview/gl/textures.py
+++ b/fsl/fslview/gl/textures.py
@@ -437,20 +437,19 @@ class ImageTexture(object):
                            gl.GL_TEXTURE_MIN_FILTER,
                            interp)
 
-        # Make everything outside
-        # of the image transparent
-        gl.glTexParameterfv(gl.GL_TEXTURE_3D,
-                            gl.GL_TEXTURE_BORDER_COLOR,
-                            np.array([0, 0, 0, 0], dtype=np.float32))
+        # Clamp texture borders to the edge
+        # values - it is the responsibility
+        # of the rendering logic to not draw
+        # anything outside of the image space
         gl.glTexParameteri(gl.GL_TEXTURE_3D,
                            gl.GL_TEXTURE_WRAP_S,
-                           gl.GL_CLAMP_TO_BORDER)
+                           gl.GL_CLAMP_TO_EDGE)
         gl.glTexParameteri(gl.GL_TEXTURE_3D,
                            gl.GL_TEXTURE_WRAP_T,
-                           gl.GL_CLAMP_TO_BORDER)
+                           gl.GL_CLAMP_TO_EDGE)
         gl.glTexParameteri(gl.GL_TEXTURE_3D,
                            gl.GL_TEXTURE_WRAP_R,
-                           gl.GL_CLAMP_TO_BORDER)
+                           gl.GL_CLAMP_TO_EDGE)
 
         # create the texture according to
         # the format determined by the
-- 
GitLab