//-------------------------------------------------------------- // Fragment Shader: Attribute 2D Transfer Function //-------------------------------------------------------------- uniform sampler3D sam3Tex0; // Sampler for Transfer Function uniform sampler3D sam3Tex1; // Sampler for Value Image uniform sampler3D sam3Tex2; // Sampler for Gradient Image uniform sampler3D sam3Tex3; // Sampler for Tags uniform float fSamplingRate; // Current sampling rate uniform float fNormalOffset; // Offset for normal calculataions float adjustAlphaForSamplingRate( float a ) { return 1.0 - pow( 1.0 - a, 1.0 / fSamplingRate ); } vec4 computeNormal( ) { vec3 pos3Tex1X1 = vec3( gl_TexCoord[1] ); pos3Tex1X1.x -= fNormalOffset; vec3 pos3Tex1X2 = vec3( gl_TexCoord[1] ); pos3Tex1X2.x += fNormalOffset; vec3 pos3Tex1Y1 = vec3( gl_TexCoord[1] ); pos3Tex1Y1.y -= fNormalOffset; vec3 pos3Tex1Y2 = vec3( gl_TexCoord[1] ); pos3Tex1Y2.y += fNormalOffset; vec3 pos3Tex1Z1 = vec3( gl_TexCoord[1] ); pos3Tex1Z1.z -= fNormalOffset; vec3 pos3Tex1Z2 = vec3( gl_TexCoord[1] ); pos3Tex1Z2.z += fNormalOffset; vec4 val4Tex1X1 = texture3D( sam3Tex1, pos3Tex1X1 ); vec4 val4Tex1X2 = texture3D( sam3Tex1, pos3Tex1X2 ); vec4 val4Tex1Y1 = texture3D( sam3Tex1, pos3Tex1Y1 ); vec4 val4Tex1Y2 = texture3D( sam3Tex1, pos3Tex1Y2 ); vec4 val4Tex1Z1 = texture3D( sam3Tex1, pos3Tex1Z1 ); vec4 val4Tex1Z2 = texture3D( sam3Tex1, pos3Tex1Z2 ); float fDiffTex1X = 0.5*val4Tex1X1.a - 0.5*val4Tex1X2.a; float fDiffTex1Y = 0.5*val4Tex1Y1.a - 0.5*val4Tex1Y2.a; float fDiffTex1Z = 0.5*val4Tex1Z1.a - 0.5*val4Tex1Z2.a; return vec4( fDiffTex1X, fDiffTex1Y, fDiffTex1Z, 0.0 ); } void main() { // Interpolate images float value = texture3D( sam3Tex1, gl_TexCoord[1] ).a; float grad = texture3D( sam3Tex2, gl_TexCoord[2] ).a; float attrib = texture3D( sam3Tex3, gl_TexCoord[3] ).a; // Interpolate transfer function const float fNumLayers = 2.0; vec3 pos3TfAll = vec3( value, 1.0-grad, 0.0/(fNumLayers-1.0) ); vec3 pos3TfTag1 = vec3( attrib, 1.0-grad, 1.0/(fNumLayers-1.0) ); //vec3 pos3TfTag2 = vec3( value, 1.0-grad, 2.0/(fNumLayers-1.0) ); //vec3 pos3TfTag3 = vec3( value, 1.0-grad, 3.0/(fNumLayers-1.0) ); //vec3 pos3TfTag4 = vec3( value, 1.0-grad, 4.0/(fNumLayers-1.0) ); vec4 val4TfAll = texture3D( sam3Tex0, pos3TfAll ); vec4 val4TfTag1 = texture3D( sam3Tex0, pos3TfTag1 ); //vec4 val4TfTag2 = texture3D( sam3Tex0, pos3TfTag2 ); //vec4 val4TfTag3 = texture3D( sam3Tex0, pos3TfTag3 ); //vec4 val4TfTag4 = texture3D( sam3Tex0, pos3TfTag4 ); // Adjust alpha for sampling rate val4TfAll.a = adjustAlphaForSamplingRate( val4TfAll.a ); val4TfTag1.a = adjustAlphaForSamplingRate( val4TfTag1.a ); //val4TfTag2.a = adjustAlphaForSamplingRate( val4TfTag2.a ); //val4TfTag3.a = adjustAlphaForSamplingRate( val4TfTag3.a ); //val4TfTag4.a = adjustAlphaForSamplingRate( val4TfTag4.a ); // Mix tags vec4 val4Mix = val4TfAll; if (attrib > 0.0 && val4TfTag1.a > 0.0) val4Mix = val4TfTag1; //val4Mix = mix( val4Mix, val4TfTag1, 1.0-val4TfTag1.a ); //if (attrib > 0.0) val4Mix = val4TfTag1; //else if (tags > XXX) vec4Mix = vec4TfTag2; //else if (tags > XXX) vec4Mix = vec4TfTag3; //else if (tags > XXX) vec4Mix = vec4TfTag4; // Compute the normal vec4 vec4N = computeNormal( ); vec4N = normalize( vec4N ); // Get lighting parameters gl_LightSourceParameters light0 = gl_LightSource[0]; float fExp = gl_FrontMaterial.shininess; // Compute light vector vec4 vec4L = vec4( 0.0, 0.0, -0.5, 0.0 ); vec4L = vec4L * gl_ModelViewMatrix; vec4L = vec4( vec4L.x, vec4L.y, -vec4L.z, 0.0 ); // Compute lighting model values float fNdotL = max( dot(vec4N, vec4L), 0.0 ); vec4 vec4R = (2.0 * fNdotL * vec4N) - vec4L; vec4R = normalize( vec4R ); float fNdotR = max( dot(vec4N, vec4R), 0.0 ); // Apply to value gl_FragColor = ( val4Mix * light0.ambient ); gl_FragColor += ( val4Mix * light0.diffuse * fNdotL ); gl_FragColor += ( val4Mix * light0.specular * pow(fNdotR,fExp) ); }