Commit 8145aa20 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] - Volume Renderer now allows the direct usage of pre-calculated gradient...

[ADD] - Volume Renderer now allows the direct usage of pre-calculated gradient fields for lighting. This speeds up rendering since gradients do not need to be created on the fly. It is still possible to use it without the gradient field.
parent 64a30286
......@@ -85,12 +85,10 @@ const std::string WMDirectVolumeRendering::getDescription() const
void WMDirectVolumeRendering::connectors()
{
// DVR needs one input: the scalar dataset
m_input = boost::shared_ptr< WModuleInputData < WDataSetScalar > >(
new WModuleInputData< WDataSetScalar >( shared_from_this(), "in", "The scalar dataset shown using isosurface." )
);
m_input = WModuleInputData< WDataSetScalar >::createAndAdd( shared_from_this(), "in", "The scalar dataset." );
// As properties, every connector needs to be added to the list of connectors.
addConnector( m_input );
// Optional: the gradient field
m_gradients = WModuleInputData< WDataSetVector >::createAndAdd( shared_from_this(), "gradients", "The gradient field of the dataset to display" );
// call WModules initialization
WModule::connectors();
......@@ -102,9 +100,9 @@ void WMDirectVolumeRendering::properties()
m_propCondition = boost::shared_ptr< WCondition >( new WCondition() );
m_stepCount = m_properties->addProperty( "Step count", "The number of steps to walk along the ray during raycasting. A low value "
"may cause artifacts whilst a high value slows down rendering.", 250 );
"may cause artifacts whilst a high value slows down rendering.", 512 );
m_stepCount->setMin( 1 );
m_stepCount->setMax( 1000 );
m_stepCount->setMax( 5000 );
// illumination model
m_localIlluminationSelections = boost::shared_ptr< WItemSelection >( new WItemSelection() );
......@@ -138,6 +136,7 @@ void WMDirectVolumeRendering::moduleMain()
// let the main loop awake if the data changes or the properties changed.
m_moduleState.setResetable( true, true );
m_moduleState.add( m_input->getDataChangedCondition() );
m_moduleState.add( m_gradients->getDataChangedCondition() );
m_moduleState.add( m_propCondition );
// Signal ready state.
......@@ -164,7 +163,7 @@ void WMDirectVolumeRendering::moduleMain()
}
// was there an update?
bool dataUpdated = m_input->updated();
bool dataUpdated = m_input->updated() || m_gradients->updated();
boost::shared_ptr< WDataSetScalar > dataSet = m_input->getData();
bool dataValid = ( dataSet );
bool propUpdated = m_localIlluminationAlgo->changed() || m_tfLoaderEnabled || m_tfLoaderFile->changed() || m_tfLoaderTrigger->changed();
......@@ -204,7 +203,7 @@ void WMDirectVolumeRendering::moduleMain()
rootState->setMode( GL_BLEND, osg::StateAttribute::ON );
////////////////////////////////////////////////////////////////////////////////////////////////////
// setup defines (illumination)
// setup illumination
////////////////////////////////////////////////////////////////////////////////////////////////////
size_t localIlluminationAlgo = m_localIlluminationAlgo->get( true ).getItemIndexOfSelected( 0 );
......@@ -218,6 +217,19 @@ void WMDirectVolumeRendering::moduleMain()
break;
}
// if there is a gradient field available -> apply as texture too
boost::shared_ptr< WDataSetVector > gradients = m_gradients->getData();
if ( gradients )
{
debugLog() << "Uploading specified gradient field.";
// bind the texture to the node
rootState->setTextureAttributeAndModes( 1, gradients->getTexture()->getTexture(), osg::StateAttribute::ON );
rootState->addUniform( new osg::Uniform( "tex1", 1 ) );
m_shader->setDefine( "GRADIENTTEXTURE_SAMPLER", "tex1" );
m_shader->setDefine( "GRADIENTTEXTURE_ENABLED" );
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// load transfer function
////////////////////////////////////////////////////////////////////////////////////////////////////
......@@ -233,9 +245,9 @@ void WMDirectVolumeRendering::moduleMain()
tfTexture->setImage( tfImg );
// apply it
rootState->setTextureAttributeAndModes( 1, tfTexture, osg::StateAttribute::ON );
rootState->addUniform( new osg::Uniform( "tex1", 1 ) );
m_shader->setDefine( "TRANSFERFUNCTION_SAMPLER", "tex1" );
rootState->setTextureAttributeAndModes( 2, tfTexture, osg::StateAttribute::ON );
rootState->addUniform( new osg::Uniform( "tex2", 2 ) );
m_shader->setDefine( "TRANSFERFUNCTION_SAMPLER", "tex2" );
m_shader->setDefine( "TRANSFERFUNCTION_ENABLED" );
}
else
......@@ -263,7 +275,6 @@ void WMDirectVolumeRendering::moduleMain()
// build spatial search structure
////////////////////////////////////////////////////////////////////////////////////////////////////
// update node
debugLog() << "Adding new rendering.";
rootNode->clear();
......
......@@ -31,6 +31,8 @@
#include <osg/Uniform>
#include "../../graphicsEngine/WShader.h"
#include "../../dataHandler/WDataSetScalar.h"
#include "../../dataHandler/WDataSetVector.h"
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleInputData.h"
#include "../../kernel/WModuleOutputData.h"
......@@ -108,6 +110,11 @@ private:
*/
boost::shared_ptr< WModuleInputData< WDataSetScalar > > m_input;
/**
* The gradient field input
*/
boost::shared_ptr< WModuleInputData< WDataSetVector > > m_gradients;
/**
* The number of steps to walk along the ray.
*/
......
......@@ -43,6 +43,7 @@
// texture containing the data
uniform sampler3D tex0;
uniform sampler1D TRANSFERFUNCTION_SAMPLER;
uniform sampler3D GRADIENTTEXTURE_SAMPLER;
/////////////////////////////////////////////////////////////////////////////
// Attributes
......@@ -95,6 +96,9 @@ vec3 findRayEnd( out float d )
*/
vec3 getGradient( in vec3 position )
{
#ifdef GRADIENTTEXTURE_ENABLED
return ( 2.0 * texture3D( GRADIENTTEXTURE_SAMPLER, position ).rgb ) + vec3( -1.0 );
#else
float s = 0.01;
float valueXP = texture3D( tex0, position + vec3( s, 0.0, 0.0 ) ).r;
float valueXM = texture3D( tex0, position - vec3( s, 0.0, 0.0 ) ).r;
......@@ -104,6 +108,7 @@ vec3 getGradient( in vec3 position )
float valueZM = texture3D( tex0, position - vec3( 0.0, 0.0, s ) ).r;
return vec3( valueXP - valueXM, valueYP - valueYM, valueZP - valueZM );
#endif
}
/**
......
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