diff --git a/fsl/fsleyes/gl/gl14/glvolume_frag.prog b/fsl/fsleyes/gl/gl14/glvolume_frag.prog index 3c43b568868badc1a52a29aa76c65b67d1645a07..a0113aefcfb0483920d60ed0078b791781030e93 100644 --- a/fsl/fsleyes/gl/gl14/glvolume_frag.prog +++ b/fsl/fsleyes/gl/gl14/glvolume_frag.prog @@ -35,8 +35,10 @@ # component determines the clipping direction - pass # in -1 for the above behaviour, or +1 to invert # this behaviour (i.e. to clip values that are within -# the range). Clipping values are assumed to be -# normalised to the image texture value range. +# the range). The (w) component is a boolen flag which +# indicates whether the image texture is to be used +# as the clip texture. Clipping values are assumed to +# be normalised to the image texture value range. # # program.local[6] - Negative colour map control. The (x) component # is a boolean flag controlling whether the negative @@ -57,10 +59,12 @@ TEMP voxCoord; TEMP voxClipLo; TEMP voxClipHi; TEMP voxValue; +TEMP clipValue; TEMP posColour; TEMP negColour; TEMP useNegCmap; TEMP negVoxValue; +TEMP negClipValue; PARAM imageShape = program.local[4]; PARAM clipping = program.local[5]; @@ -81,8 +85,15 @@ MOV voxCoord, fragment.texcoord[1]; #pragma include test_in_bounds.prog # look up image voxel value -# from 3D image texture -TEX voxValue.x, fragment.texcoord[0], texture[0], 3D; +# and clipping value from 3D +# image/clipping textures +TEX voxValue.x, fragment.texcoord[0], texture[0], 3D; +TEX clipValue.x, fragment.texcoord[0], texture[3], 3D; + +# If the image texture is the clip +# texture, overwrite the clip value +# we just looked up. +CMP clipValue.x, clipping.w, clipValue.x, voxValue.x; # Figure out which negative colour map # should be used for this fragment. @@ -108,16 +119,27 @@ MUL useNegCmap.x, useNegCmap.x, -1; ADD negVoxValue.x, negCmap.y, negCmap.y; SUB negVoxValue.x, negVoxValue.x, voxValue.x; +# And do the same for the clip value - +# this is necessary if the image texture +# is the clipping texture. +ADD negClipValue.x, negCmap.y, negCmap.y; +SUB negClipValue.x, negClipValue.x, clipValue.x; + # If we're using the negative colour # map, replace the original voxel # value with the inverted one. CMP voxValue.x, useNegCmap.x, negVoxValue.x, voxValue.x; +# And do the same to the clip value if +# the image texture is the clip texture. +CMP negClipValue.x, useNegCmap.x, negClipValue.x, clipValue.x; +CMP clipValue.x, clipping.w, clipValue.x, negClipValue.x; + # Test the low clipping range -SUB voxClipLo, voxValue.x, clipping.x; +SUB voxClipLo, clipValue.x, clipping.x; # And the high clipping range -SUB voxClipHi, voxValue.x, clipping.y; +SUB voxClipHi, clipValue.x, clipping.y; # Multiply the low/high results - after # this, voxClipLo will be positive if diff --git a/fsl/fsleyes/gl/gl14/glvolume_funcs.py b/fsl/fsleyes/gl/gl14/glvolume_funcs.py index 41a1bdbc5ee35561b3d5f2ea5d43f5968119004e..c1e2bfeed707ba22c4774c95f1e83b23d8accbef 100644 --- a/fsl/fsleyes/gl/gl14/glvolume_funcs.py +++ b/fsl/fsleyes/gl/gl14/glvolume_funcs.py @@ -93,19 +93,23 @@ def updateShaderState(self): # And the clipping range, normalised # to the image texture value range - invClip = 1 if opts.invertClipping else -1 - useNegCmap = 1 if opts.useNegativeCmap else 0 - - xform = self.imageTexture.invVoxValXform - clipLo = opts.clippingRange[0] * xform[0, 0] + xform[3, 0] - clipHi = opts.clippingRange[1] * xform[0, 0] + xform[3, 0] - texZero = 0.0 * xform[0, 0] + xform[3, 0] + invClip = 1 if opts.invertClipping else -1 + useNegCmap = 1 if opts.useNegativeCmap else 0 + imageIsClip = 1 if opts.clipImage is None else -1 + + imgXform = self.imageTexture.invVoxValXform + if opts.clipImage is None: clipXform = imgXform + else: clipXform = self.clipTexture.invVoxValXform + + clipLo = opts.clippingRange[0] * clipXform[0, 0] + clipXform[3, 0] + clipHi = opts.clippingRange[1] * clipXform[0, 0] + clipXform[3, 0] + texZero = 0.0 * imgXform[ 0, 0] + imgXform[ 3, 0] shaders.setVertexProgramVector( 0, shape + [0]) shaders.setFragmentProgramMatrix(0, voxValXform) shaders.setFragmentProgramVector(4, shape + [0]) - shaders.setFragmentProgramVector(5, [clipLo, clipHi, invClip, 0]) + shaders.setFragmentProgramVector(5, [clipLo, clipHi, invClip, imageIsClip]) shaders.setFragmentProgramVector(6, [useNegCmap, texZero, 0, 0]) gl.glDisable(arbvp.GL_VERTEX_PROGRAM_ARB)