Commit 783d5ccc by Alexander Wiebel

[CHANGE #298] adapt navslices and marching cubes to the new threshold

behavior. On this way a couple of other things have been fixed:
* use only 8 textures because the compiler told me
    "undefined variable "gl_MultiTexCoord8""
* simplified highlighting of picked slices as they have the correct size for
 some time now
* removed some commented useless code
* fixed the problem that isosurfaces could show only one texture
* simplified calling of renderSurface function in marching cubes module
parent 203507e1
//
// This makes threshold lying between min and max to lie between 0 and 1
// where 0 correspond to min and 1 to max
//
float scaleZeroOne( in float threshold, in float min, in float max )
{
return ( threshold - min ) / ( max - min );
}
......@@ -144,9 +144,6 @@ void WMMarchingCubes::moduleMain()
generateSurfacePre( m_isoValueProp->get() );
// TODO(wiebel): MC remove this from here
// renderMesh( load( "/tmp/isosurfaceTestMesh.vtk" ) );
++*progress;
debugLog() << "Rendering surface ...";
......@@ -154,7 +151,9 @@ void WMMarchingCubes::moduleMain()
m_shaderUseLighting = true;
m_shaderUseTransparency = true;
renderSurface();
renderMesh();
m_output->updateData( m_triMesh );
debugLog() << "Done!";
progress->finish();
......@@ -273,13 +272,7 @@ void WMMarchingCubes::generateSurfacePre( double isoValue )
}
}
void WMMarchingCubes::renderSurface()
{
renderMesh( m_triMesh );
m_output->updateData( m_triMesh );
}
void WMMarchingCubes::renderMesh( boost::shared_ptr< WTriangleMesh2 > mesh )
void WMMarchingCubes::renderMesh()
{
// WKernel::getRunningKernel()->getGraphicsEngine()->getScene()
m_moduleNode->remove( m_surfaceGeode );
......@@ -288,13 +281,13 @@ void WMMarchingCubes::renderMesh( boost::shared_ptr< WTriangleMesh2 > mesh )
m_surfaceGeode->setName( "iso surface" );
surfaceGeometry->setVertexArray( mesh->getVertexArray() );
surfaceGeometry->setVertexArray( m_triMesh->getVertexArray() );
osg::DrawElementsUInt* surfaceElement;
surfaceElement = new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 );
std::vector< size_t >tris = mesh->getTriangles();
std::vector< size_t >tris = m_triMesh->getTriangles();
surfaceElement->reserve( tris.size() );
for( unsigned int vertId = 0; vertId < tris.size(); ++vertId )
......@@ -305,7 +298,7 @@ void WMMarchingCubes::renderMesh( boost::shared_ptr< WTriangleMesh2 > mesh )
// ------------------------------------------------
// normals
surfaceGeometry->setNormalArray( mesh->getVertexNormalArray() );
surfaceGeometry->setNormalArray( m_triMesh->getVertexNormalArray() );
surfaceGeometry->setNormalBinding( osg::Geometry::BIND_PER_VERTEX );
m_surfaceGeode->addDrawable( surfaceGeometry );
......@@ -338,14 +331,6 @@ void WMMarchingCubes::renderMesh( boost::shared_ptr< WTriangleMesh2 > mesh )
// ------------------------------------------------
// Shader stuff
osg::Vec3Array* texCoords = new osg::Vec3Array;
for( size_t i = 0; i < mesh->vertSize(); ++i )
{
osg::Vec3 vertPos = mesh->getVertex( i );
texCoords->push_back( wge::wv3D2ov3( m_grid->worldCoordToTexCoord( wmath::WPosition( vertPos[0], vertPos[1], vertPos[2] ) ) ) );
}
surfaceGeometry->setTexCoordArray( 0, texCoords );
m_typeUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "type0", 0 ) ) );
m_typeUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "type1", 0 ) ) );
m_typeUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "type2", 0 ) ) );
......@@ -379,6 +364,28 @@ void WMMarchingCubes::renderMesh( boost::shared_ptr< WTriangleMesh2 > mesh )
m_thresholdUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "threshold8", 0.0f ) ) );
m_thresholdUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "threshold9", 0.0f ) ) );
m_minUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "min0", 0.0f ) ) );
m_minUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "min1", 0.0f ) ) );
m_minUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "min2", 0.0f ) ) );
m_minUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "min3", 0.0f ) ) );
m_minUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "min4", 0.0f ) ) );
m_minUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "min5", 0.0f ) ) );
m_minUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "min6", 0.0f ) ) );
m_minUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "min7", 0.0f ) ) );
m_minUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "min8", 0.0f ) ) );
m_minUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "min9", 0.0f ) ) );
m_maxUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "max0", 0.0f ) ) );
m_maxUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "max1", 0.0f ) ) );
m_maxUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "max2", 0.0f ) ) );
m_maxUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "max3", 0.0f ) ) );
m_maxUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "max4", 0.0f ) ) );
m_maxUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "max5", 0.0f ) ) );
m_maxUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "max6", 0.0f ) ) );
m_maxUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "max7", 0.0f ) ) );
m_maxUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "max8", 0.0f ) ) );
m_maxUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "max9", 0.0f ) ) );
m_samplerUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "tex0", 0 ) ) );
m_samplerUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "tex1", 1 ) ) );
m_samplerUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "tex2", 2 ) ) );
......@@ -405,14 +412,13 @@ void WMMarchingCubes::renderMesh( boost::shared_ptr< WTriangleMesh2 > mesh )
{
state->addUniform( m_typeUniforms[i] );
state->addUniform( m_thresholdUniforms[i] );
state->addUniform( m_minUniforms[i] );
state->addUniform( m_maxUniforms[i] );
state->addUniform( m_alphaUniforms[i] );
state->addUniform( m_samplerUniforms[i] );
state->addUniform( m_cmapUniforms[i] );
}
// TODO(wiebel): used? Not used? Replace by new Property please
// state->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useTexture", m_properties->getValue< bool >( "Use Texture" ) ) ) );
state->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useLighting", m_shaderUseLighting ) ) );
if( m_shaderUseTransparency )
{
......@@ -434,8 +440,6 @@ void WMMarchingCubes::renderMesh( boost::shared_ptr< WTriangleMesh2 > mesh )
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( m_moduleNode );
m_moduleNode->addUpdateCallback( new SurfaceNodeCallback( this ) );
//osgDB::writeNodeFile( *m_surfaceGeode, "/tmp/saved.osg" ); //for debugging
}
// TODO(wiebel): move this somewhere, where more classes can use it
......@@ -555,6 +559,7 @@ void WMMarchingCubes::updateGraphics()
if ( m_textureChanged || m_opacityProp->changed() || m_useTextureProp->changed() )
{
bool localTextureChangedFlag = m_textureChanged;
m_textureChanged = false;
// grab a list of data textures
......@@ -586,16 +591,35 @@ void WMMarchingCubes::updateGraphics()
int c = 0;
for ( std::vector< boost::shared_ptr< WDataTexture3D > >::const_iterator iter = tex.begin(); iter != tex.end(); ++iter )
{
if( localTextureChangedFlag )
{
osg::ref_ptr< osg::Geometry > surfaceGeometry = m_surfaceGeode->getDrawable( 0 )->asGeometry();
osg::Vec3Array* texCoords = new osg::Vec3Array;
boost::shared_ptr< WGridRegular3D > grid = ( *iter )->getGrid();
for( size_t i = 0; i < m_triMesh->vertSize(); ++i )
{
osg::Vec3 vertPos = m_triMesh->getVertex( i );
texCoords->push_back( wge::wv3D2ov3( grid->worldCoordToTexCoord( wmath::WPosition( vertPos[0], vertPos[1], vertPos[2] ) ) ) );
}
surfaceGeometry->setTexCoordArray( c, texCoords );
}
osg::ref_ptr<osg::Texture3D> texture3D = ( *iter )->getTexture();
rootState->setTextureAttributeAndModes( c, texture3D, osg::StateAttribute::ON );
// set threshold/opacity as uniforms
float t = ( *iter )->getThreshold() / 255.0;
float t = ( *iter )->getThreshold();
float a = ( *iter )->getAlpha();
int cmap = ( *iter )->getSelectedColormap();
m_typeUniforms[c]->set( ( *iter )->getDataType() );
m_thresholdUniforms[c]->set( t );
{
float minValue = ( *iter )->getMinValue();
float maxValue = ( *iter )->getMaxValue();
m_minUniforms[c]->set( minValue );
m_maxUniforms[c]->set( maxValue );
}
m_alphaUniforms[c]->set( a );
m_cmapUniforms[c]->set( cmap );
......
......@@ -91,12 +91,6 @@ public:
virtual const char** getXPMIcon() const;
/**
* Activate the rendering of the computed surface.
* This converts the surface to a WTriangleMesh2 and calls renderMesh afterwards
*/
void renderSurface();
/**
* updates textures and shader parameters
*/
void updateGraphics();
......@@ -126,9 +120,8 @@ private:
/**
* Prepares and commits everything for rendering with the OSG
* \param mesh The mesh that will be rendered.
*/
void renderMesh( boost::shared_ptr< WTriangleMesh2 > mesh );
void renderMesh();
/**
* Store the mesh in legacy vtk file format.
......@@ -195,10 +188,12 @@ private:
std::vector< osg::ref_ptr< osg::Uniform > > m_typeUniforms; //!< uniforms for ...... ? for shader
std::vector< osg::ref_ptr< osg::Uniform > > m_alphaUniforms; //!< uniforms for opacities of textures in shader
std::vector< osg::ref_ptr< osg::Uniform > > m_thresholdUniforms; //!< uniforms for thresholds of textures in shader
std::vector< osg::ref_ptr<osg::Uniform> > m_minUniforms; //!< minimum value per texture
std::vector< osg::ref_ptr<osg::Uniform> > m_maxUniforms; //!< maximu value per texture
std::vector< osg::ref_ptr< osg::Uniform > > m_samplerUniforms; //!< uniforms for ids of textures in shader
std::vector< osg::ref_ptr<osg::Uniform> > m_cmapUniforms; //!< uniforms for color maps per texture in shader
static const int m_maxNumberOfTextures = 10; //!< We support only 10 textures because hardware has may have unknown limits.
static const int m_maxNumberOfTextures = 8; //!< We support only 8 textures because some known hardware does not support more texture coordinates.
};
/**
......
......@@ -6,12 +6,6 @@ varying vec4 VaryingTexCoord4;
varying vec4 VaryingTexCoord5;
varying vec4 VaryingTexCoord6;
varying vec4 VaryingTexCoord7;
varying vec4 VaryingTexCoord8;
varying vec4 VaryingTexCoord9;
uniform bool useLighting;
uniform bool useTexture;
uniform int opacity;
uniform sampler3D tex0;
uniform sampler3D tex1;
......@@ -21,8 +15,6 @@ uniform sampler3D tex4;
uniform sampler3D tex5;
uniform sampler3D tex6;
uniform sampler3D tex7;
uniform sampler3D tex8;
uniform sampler3D tex9;
uniform float threshold0;
uniform float threshold1;
......@@ -32,9 +24,24 @@ uniform float threshold4;
uniform float threshold5;
uniform float threshold6;
uniform float threshold7;
uniform float threshold8;
uniform float threshold9;
uniform float min0;
uniform float min1;
uniform float min2;
uniform float min3;
uniform float min4;
uniform float min5;
uniform float min6;
uniform float min7;
uniform float max0;
uniform float max1;
uniform float max2;
uniform float max3;
uniform float max4;
uniform float max5;
uniform float max6;
uniform float max7;
uniform int type0;
uniform int type1;
......@@ -44,8 +51,6 @@ uniform int type4;
uniform int type5;
uniform int type6;
uniform int type7;
uniform int type8;
uniform int type9;
uniform float alpha0;
uniform float alpha1;
......@@ -55,8 +60,6 @@ uniform float alpha4;
uniform float alpha5;
uniform float alpha6;
uniform float alpha7;
uniform float alpha8;
uniform float alpha9;
uniform int useCmap0;
uniform int useCmap1;
......@@ -66,14 +69,17 @@ uniform int useCmap4;
uniform int useCmap5;
uniform int useCmap6;
uniform int useCmap7;
uniform int useCmap8;
uniform int useCmap9;
uniform bool useLighting;
uniform bool useTexture;
uniform int opacity;
#include "colorMaps.fs"
#include "utils.fs"
#include "lighting.fs"
void lookupTex(inout vec4 col, in int type, in sampler3D tex, in float threshold, in vec3 v, in float alpha, in int cmap)
void lookupTex( inout vec4 col, in int type, in sampler3D tex, in float threshold, in vec3 v, in float alpha, in int cmap)
{
vec3 col1 = vec3(0.0);
......@@ -83,12 +89,12 @@ void lookupTex(inout vec4 col, in int type, in sampler3D tex, in float threshol
if( cmap != 0 )
{
if (threshold < 1.0)
if(threshold < 1.0)
{
col1.r = (col1.r - threshold) / (1.0 - threshold);
}
colorMap(col1, col1.r, cmap );
colorMap( col1, col1.r, cmap );
}
col.rgb = mix( col.rgb, col1.rgb, alpha);
......@@ -107,8 +113,15 @@ void main()
if( useTexture )
{
if ( type9 > 0 ) lookupTex(col, type9, tex9, threshold9, VaryingTexCoord9.xyz, alpha9, useCmap9);
if ( type8 > 0 ) lookupTex(col, type8, tex8, threshold8, VaryingTexCoord8.xyz, alpha8, useCmap8);
threshold0 = scaleZeroOne( threshold0, min0, max0 );
threshold1 = scaleZeroOne( threshold1, min1, max1 );
threshold2 = scaleZeroOne( threshold2, min2, max2 );
threshold3 = scaleZeroOne( threshold3, min3, max3 );
threshold4 = scaleZeroOne( threshold4, min4, max4 );
threshold5 = scaleZeroOne( threshold5, min5, max5 );
threshold6 = scaleZeroOne( threshold6, min6, max6 );
threshold7 = scaleZeroOne( threshold7, min7, max7 );
if ( type7 > 0 ) lookupTex(col, type7, tex7, threshold7, VaryingTexCoord7.xyz, alpha7, useCmap7);
if ( type6 > 0 ) lookupTex(col, type6, tex6, threshold6, VaryingTexCoord6.xyz, alpha6, useCmap6);
if ( type5 > 0 ) lookupTex(col, type5, tex5, threshold5, VaryingTexCoord5.xyz, alpha5, useCmap5);
......@@ -118,6 +131,7 @@ void main()
if ( type1 > 0 ) lookupTex(col, type1, tex1, threshold1, VaryingTexCoord1.xyz, alpha1, useCmap1);
if ( type0 > 0 ) lookupTex(col, type0, tex0, threshold0, VaryingTexCoord0.xyz, alpha0, useCmap0);
}
if ( useLighting )
{
col = (ambient * col / 2.0) + (diffuse * col) + (specular * col / 2.0);
......@@ -125,11 +139,7 @@ void main()
col = clamp(col, 0.0, 1.0);
//discard completely black voxels. So if no texture is active we will see nothing
if ( ( col.r + col.g + col.b ) < 0.01 )
discard;
// opacity of the surface
col.a = opacity * .01;
gl_FragColor = col;
......
varying vec4 VaryingTexCoord0;
varying vec4 VaryingTexCoord1;
varying vec4 VaryingTexCoord2;
varying vec4 VaryingTexCoord3;
varying vec4 VaryingTexCoord4;
varying vec4 VaryingTexCoord5;
varying vec4 VaryingTexCoord6;
varying vec4 VaryingTexCoord7;
#include "lighting.vs"
void main()
{
VaryingTexCoord0 = gl_MultiTexCoord0;
VaryingTexCoord1 = gl_MultiTexCoord1;
VaryingTexCoord2 = gl_MultiTexCoord2;
VaryingTexCoord3 = gl_MultiTexCoord3;
VaryingTexCoord4 = gl_MultiTexCoord4;
VaryingTexCoord5 = gl_MultiTexCoord5;
VaryingTexCoord6 = gl_MultiTexCoord6;
VaryingTexCoord7 = gl_MultiTexCoord7;
prepareLight();
......
......@@ -41,6 +41,7 @@
#include "../../dataHandler/WDataSet.h"
#include "../../dataHandler/WDataHandler.h"
#include "../../dataHandler/WDataSetSingle.h"
#include "../../dataHandler/WDataSetScalar.h"
#include "../../dataHandler/WDataTexture3D.h"
#include "../../dataHandler/WGridRegular3D.h"
#include "../../dataHandler/WSubject.h"
......@@ -823,12 +824,18 @@ void WMNavSlices::updateTextures()
rootState->setTextureAttributeAndModes( c, texture3D, osg::StateAttribute::ON );
// set threshold/opacity as uniforms
float t = ( *iter )->getThreshold() / 255.0;
float t = ( *iter )->getThreshold();
float a = ( *iter )->getAlpha();
int cmap = ( *iter )->getSelectedColormap();
m_typeUniforms[c]->set( ( *iter )->getDataType() );
m_thresholdUniforms[c]->set( t );
{
float minValue = ( *iter )->getMinValue();
float maxValue = ( *iter )->getMaxValue();
m_minUniforms[c]->set( minValue );
m_maxUniforms[c]->set( maxValue );
}
m_alphaUniforms[c]->set( a );
m_cmapUniforms[c]->set( cmap );
......@@ -888,6 +895,28 @@ void WMNavSlices::initUniforms( osg::StateSet* rootState )
m_thresholdUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "threshold8", 0.0f ) ) );
m_thresholdUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "threshold9", 0.0f ) ) );
m_minUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "min0", 0.0f ) ) );
m_minUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "min1", 0.0f ) ) );
m_minUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "min2", 0.0f ) ) );
m_minUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "min3", 0.0f ) ) );
m_minUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "min4", 0.0f ) ) );
m_minUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "min5", 0.0f ) ) );
m_minUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "min6", 0.0f ) ) );
m_minUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "min7", 0.0f ) ) );
m_minUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "min8", 0.0f ) ) );
m_minUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "min9", 0.0f ) ) );
m_maxUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "max0", 0.0f ) ) );
m_maxUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "max1", 0.0f ) ) );
m_maxUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "max2", 0.0f ) ) );
m_maxUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "max3", 0.0f ) ) );
m_maxUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "max4", 0.0f ) ) );
m_maxUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "max5", 0.0f ) ) );
m_maxUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "max6", 0.0f ) ) );
m_maxUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "max7", 0.0f ) ) );
m_maxUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "max8", 0.0f ) ) );
m_maxUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "max9", 0.0f ) ) );
m_samplerUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "tex0", 0 ) ) );
m_samplerUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "tex1", 1 ) ) );
m_samplerUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "tex2", 2 ) ) );
......@@ -914,6 +943,8 @@ void WMNavSlices::initUniforms( osg::StateSet* rootState )
{
rootState->addUniform( m_typeUniforms[i] );
rootState->addUniform( m_thresholdUniforms[i] );
rootState->addUniform( m_minUniforms[i] );
rootState->addUniform( m_maxUniforms[i] );
rootState->addUniform( m_alphaUniforms[i] );
rootState->addUniform( m_samplerUniforms[i] );
rootState->addUniform( m_cmapUniforms[i] );
......
......@@ -301,6 +301,9 @@ private:
*/
std::vector< osg::ref_ptr<osg::Uniform> > m_thresholdUniforms;
std::vector< osg::ref_ptr<osg::Uniform> > m_minUniforms; //!< minimum value per texture
std::vector< osg::ref_ptr<osg::Uniform> > m_maxUniforms; //!< maximu value per texture
/**
* vector of color maps per texture
*/
......@@ -320,7 +323,7 @@ private:
*/
static bool m_navsliceRunning;
static const int m_maxNumberOfTextures = 10; //!< We support only 10 textures because hardware has may have unknown limits.
static const int m_maxNumberOfTextures = 8; //!< We support only 8 textures because some known hardware does not support more texture coordinates.
/**
* Node callback to handle updates properly
......
......@@ -15,8 +15,6 @@ uniform sampler3D tex4;
uniform sampler3D tex5;
uniform sampler3D tex6;
uniform sampler3D tex7;
uniform sampler3D tex8;
uniform sampler3D tex9;
uniform float threshold0;
uniform float threshold1;
......@@ -26,8 +24,24 @@ uniform float threshold4;
uniform float threshold5;
uniform float threshold6;
uniform float threshold7;
uniform float threshold8;
uniform float threshold9;
uniform float min0;
uniform float min1;
uniform float min2;
uniform float min3;
uniform float min4;
uniform float min5;
uniform float min6;
uniform float min7;
uniform float max0;
uniform float max1;
uniform float max2;
uniform float max3;
uniform float max4;
uniform float max5;
uniform float max6;
uniform float max7;
uniform int type0;
uniform int type1;
......@@ -37,8 +51,6 @@ uniform int type4;
uniform int type5;
uniform int type6;
uniform int type7;
uniform int type8;
uniform int type9;
uniform float alpha0;
uniform float alpha1;
......@@ -48,8 +60,6 @@ uniform float alpha4;
uniform float alpha5;
uniform float alpha6;
uniform float alpha7;
uniform float alpha8;
uniform float alpha9;
uniform int useCmap0;
uniform int useCmap1;
......@@ -59,30 +69,31 @@ uniform int useCmap4;
uniform int useCmap5;
uniform int useCmap6;
uniform int useCmap7;
uniform int useCmap8;
uniform int useCmap9;
uniform bool highlighted;
#include "colorMaps.fs"
#include "utils.fs"
void lookupTex(inout vec4 col, in int type, in sampler3D tex, in float threshold, in vec3 v, in float alpha, in int cmap)
void lookupTex( inout vec4 col, in int type, in sampler3D tex, in float threshold, in vec3 v, in float alpha, in int cmap)
{
vec3 col1 = vec3(0.0);
col1 = clamp( texture3D(tex, v).rgb, 0.0, 1.0);
if ( ( col1.r + col1.g + col1.b ) / 3.0 - threshold <= 0.0) return;
if( ( col1.r + col1.g + col1.b ) / 3.0 - threshold <= 0.0) return;
if ( cmap != 0 )
if( cmap != 0 )
{
if (threshold < 1.0)
if(threshold < 1.0)
{
col1.r = (col1.r - threshold) / (1.0 - threshold);
}
colorMap(col1, col1.r, cmap);
colorMap( col1, col1.r, cmap );
}
col.rgb = mix( col.rgb, col1.rgb, alpha);
......@@ -92,8 +103,16 @@ void main()
{
vec4 col = vec4(0.0, 0.0, 0.0, 1.0);
if ( type9 > 0 ) lookupTex(col, type9, tex9, threshold9, VaryingTexCoord7.xyz, alpha9, useCmap9);
if ( type8 > 0 ) lookupTex(col, type8, tex8, threshold8, VaryingTexCoord7.xyz, alpha8, useCmap8);
threshold0 = scaleZeroOne( threshold0, min0, max0 );
threshold1 = scaleZeroOne( threshold1, min1, max1 );
threshold2 = scaleZeroOne( threshold2, min2, max2 );
threshold3 = scaleZeroOne( threshold3, min3, max3 );
threshold4 = scaleZeroOne( threshold4, min4, max4 );
threshold5 = scaleZeroOne( threshold5, min5, max5 );
threshold6 = scaleZeroOne( threshold6, min6, max6 );
threshold7 = scaleZeroOne( threshold7, min7, max7 );
if ( type7 > 0 ) lookupTex(col, type7, tex7, threshold7, VaryingTexCoord7.xyz, alpha7, useCmap7);
if ( type6 > 0 ) lookupTex(col, type6, tex6, threshold6, VaryingTexCoord6.xyz, alpha6, useCmap6);
if ( type5 > 0 ) lookupTex(col, type5, tex5, threshold5, VaryingTexCoord5.xyz, alpha5, useCmap5);
......@@ -105,34 +124,16 @@ void main()
col = clamp(col, 0.0, 1.0);
// col.a = sqrt( col.r * col.r + col.g * col.g + col.b * col.b);
if ( ( col.r + col.g + col.b ) < 0.01 )
{
float upperOuter = 10;
float upperInner = 1;
float lowerInner = .0;
if( highlighted )
{
//colorize the slice and mark the border of the first texture
if ( ( VaryingTexCoord0.x > upperInner && VaryingTexCoord0.x < upperOuter && VaryingTexCoord0.y < upperOuter && VaryingTexCoord0.z < upperOuter )
|| (VaryingTexCoord0.y > upperInner && VaryingTexCoord0.x < upperOuter && VaryingTexCoord0.y < upperOuter && VaryingTexCoord0.z < upperOuter )
|| (VaryingTexCoord0.z > upperInner && VaryingTexCoord0.x < upperOuter && VaryingTexCoord0.y < upperOuter && VaryingTexCoord0.z < upperOuter )
|| (VaryingTexCoord0.x < lowerInner && VaryingTexCoord0.x < upperOuter && VaryingTexCoord0.y < upperOuter && VaryingTexCoord0.z < upperOuter )
|| (VaryingTexCoord0.y < lowerInner && VaryingTexCoord0.x < upperOuter && VaryingTexCoord0.y < upperOuter && VaryingTexCoord0.z < upperOuter )
|| (VaryingTexCoord0.z < lowerInner && VaryingTexCoord0.x < upperOuter && VaryingTexCoord0.y < upperOuter && VaryingTexCoord0.z < upperOuter )
)
{
col = vec4(.75, .75, 1, 1);
}
else
{
col = vec4(.7, .7, 1, 1);
}
}
// higlight picked slice in the areas where ther are zero (very small) values
col = vec4(.7, .7, 1, 1);
}
else
{
discard;
discard;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment