Skip to content
Snippets Groups Projects
Commit 2b991114 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Interrupted vector opts cmap to add the ability to VolumeOpts to clip by

another image - this will be needed by VectorOpts cmap, if I want to
re-use the GLVolume fragment shader.
parent 2537e9f1
No related branches found
No related tags found
No related merge requests found
...@@ -9,10 +9,15 @@ ...@@ -9,10 +9,15 @@
#pragma include test_in_bounds.glsl #pragma include test_in_bounds.glsl
/* /*
* image data texture. * image data texture, used for colouring.
*/ */
uniform sampler3D imageTexture; uniform sampler3D imageTexture;
/*
* image data texture, used for clipping.
*/
uniform sampler3D clipTexture;
/* /*
* Texture containing the colour map. * Texture containing the colour map.
*/ */
...@@ -23,6 +28,14 @@ uniform sampler1D colourTexture; ...@@ -23,6 +28,14 @@ uniform sampler1D colourTexture;
*/ */
uniform sampler1D negColourTexture; uniform sampler1D negColourTexture;
/*
* Flag which tells the shader whether
* the image and clip textures are actually
* the same - if they are, set this to true
* to avoid an extra texture lookup.
*/
uniform bool imageIsClip;
/* /*
* Flag which determines whether to * Flag which determines whether to
* use the negative colour map. * use the negative colour map.
...@@ -30,7 +43,7 @@ uniform sampler1D negColourTexture; ...@@ -30,7 +43,7 @@ uniform sampler1D negColourTexture;
uniform bool useNegCmap; uniform bool useNegCmap;
/* /*
* Shape of the imageTexture. * Shape of the imageTexture/clipTexture.
*/ */
uniform vec3 imageShape; uniform vec3 imageShape;
...@@ -86,6 +99,7 @@ varying vec3 fragTexCoord; ...@@ -86,6 +99,7 @@ varying vec3 fragTexCoord;
void main(void) { void main(void) {
float voxValue; float voxValue;
float clipValue;
vec4 normVoxValue; vec4 normVoxValue;
bool negCmap = false; bool negCmap = false;
vec3 voxCoord = fragVoxCoord; vec3 voxCoord = fragVoxCoord;
...@@ -109,6 +123,15 @@ void main(void) { ...@@ -109,6 +123,15 @@ void main(void) {
else voxValue = texture3D( imageTexture, else voxValue = texture3D( imageTexture,
fragTexCoord).r; fragTexCoord).r;
if (imageIsClip) clipValue = voxValue;
else if (useSpline) clipValue = spline_interp(clipTexture,
fragTexCoord,
imageShape,
0);
else clipValue = texture3D( clipTexture,
fragTexCoord).r;
/* /*
* If we are using a negative colour map, * If we are using a negative colour map,
* and the voxel value is below the negative * and the voxel value is below the negative
...@@ -122,11 +145,12 @@ void main(void) { ...@@ -122,11 +145,12 @@ void main(void) {
voxValue = texZero + (texZero - voxValue); voxValue = texZero + (texZero - voxValue);
} }
/* /*
* Clip out of range voxel values * Clip out of range voxel values
*/ */
if ((!invertClip && (voxValue < clipLow || voxValue > clipHigh)) || if ((!invertClip && (clipValue < clipLow || clipValue > clipHigh)) ||
( invertClip && (voxValue >= clipLow && voxValue <= clipHigh))) { ( invertClip && (clipValue >= clipLow && clipValue <= clipHigh))) {
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
return; return;
......
...@@ -59,11 +59,12 @@ def compileShaders(self): ...@@ -59,11 +59,12 @@ def compileShaders(self):
shaderVars = {} shaderVars = {}
vertAtts = ['vertex', 'voxCoord', 'texCoord'] vertAtts = ['vertex', 'voxCoord', 'texCoord']
fragUniforms = ['imageTexture', 'colourTexture', 'negColourTexture', fragUniforms = ['imageTexture', 'clipTexture', 'colourTexture',
'useNegCmap', 'imageShape', 'useSpline', 'negColourTexture', 'imageIsClip', 'useNegCmap',
'voxValXform', 'clipLow', 'clipHigh', 'imageShape', 'useSpline', 'voxValXform',
'texZero', 'invertClip'] 'clipLow', 'clipHigh', 'texZero',
'invertClip']
for va in vertAtts: for va in vertAtts:
shaderVars[va] = gl.glGetAttribLocation(self.shaders, va) shaderVars[va] = gl.glGetAttribLocation(self.shaders, va)
...@@ -111,16 +112,18 @@ def updateShaderState(self): ...@@ -111,16 +112,18 @@ def updateShaderState(self):
gl.glUniform3fv(svars['imageShape'], 1, np.array(self.image.shape, gl.glUniform3fv(svars['imageShape'], 1, np.array(self.image.shape,
dtype=np.float32)) dtype=np.float32))
gl.glUniform1f(svars['clipLow'], clipLow) gl.glUniform1f(svars['clipLow'], clipLow)
gl.glUniform1f(svars['clipHigh'], clipHigh) gl.glUniform1f(svars['clipHigh'], clipHigh)
gl.glUniform1f(svars['texZero'], texZero) gl.glUniform1f(svars['texZero'], texZero)
gl.glUniform1f(svars['invertClip'], opts.invertClipping) gl.glUniform1f(svars['invertClip'], opts.invertClipping)
gl.glUniform1f(svars['useNegCmap'], opts.useNegativeCmap) gl.glUniform1f(svars['useNegCmap'], opts.useNegativeCmap)
gl.glUniform1f(svars['imageIsClip'], 1)
gl.glUniformMatrix4fv(svars['voxValXform'], 1, False, vvx) gl.glUniformMatrix4fv(svars['voxValXform'], 1, False, vvx)
# Set up the colour and image textures # Set up the colour and image textures
gl.glUniform1i(svars['imageTexture'], 0) gl.glUniform1i(svars['imageTexture'], 0)
gl.glUniform1i(svars['clipTexture'], 0)
gl.glUniform1i(svars['colourTexture'], 1) gl.glUniform1i(svars['colourTexture'], 1)
gl.glUniform1i(svars['negColourTexture'], 2) gl.glUniform1i(svars['negColourTexture'], 2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment