diff --git a/fsl/fslview/gl/gl21/gllinevector_vert.glsl b/fsl/fslview/gl/gl21/gllinevector_vert.glsl index 132f814909fe47fe5189e72eef7d4ef5d47d7b8b..84f567f79449f070e058dd8d8d38ffdbfed5f495 100644 --- a/fsl/fslview/gl/gl21/gllinevector_vert.glsl +++ b/fsl/fslview/gl/gl21/gllinevector_vert.glsl @@ -16,8 +16,14 @@ varying vec3 fragTexCoord; void main(void) { // TODO check voxel +0.5 offset + + // Round the vertex position to the nearest integer - + // this gives us the corresponding voxel coordinates fragVoxCoord = floor(vertex + 0.5); - fragTexCoord = fragVoxCoord / imageShape; + + // Transform the voxel coordinates to texture + // coordinates, adding 0.5 to centre them + fragTexCoord = (fragVoxCoord + 0.5) / imageShape; gl_Position = gl_ModelViewProjectionMatrix * vec4(vertex, 1); } diff --git a/fsl/fslview/gl/globject.py b/fsl/fslview/gl/globject.py index 81bb34dcfb26853b967094edcb7b4258265df23e..61f5fd93e8cfa7dd2251d61f791399eb0b648de2 100644 --- a/fsl/fslview/gl/globject.py +++ b/fsl/fslview/gl/globject.py @@ -601,7 +601,12 @@ def slice2D(dataShape, xax, yax, zpos, voxToDisplayMat, displayToVoxMat): vertices[:, zax] = zpos voxCoords = transform.transform(vertices, displayToVoxMat) - texCoords = voxCoords / dataShape + + # offset by 0.5, because voxel coordinates are by + # default centered at 0 (i.e. the space of a voxel + # lies in the range [-0.5, 0.5]), but we want voxel + # coordinates to map to the effective range [0, 1] + texCoords = (voxCoords + 0.5) / dataShape return vertices, voxCoords, texCoords