Commit 3f8f883d authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - switched to front to back compositing with alpha test

parent 4d038036
......@@ -242,6 +242,7 @@ void WMDirectVolumeRendering::moduleMain()
{
warnLog() << "Transfer function texture could not be loaded from " << m_tfLoaderFile->get( true ).file_string() << ".";
}
m_tfLoaderTrigger->get( true );
}
////////////////////////////////////////////////////////////////////////////////////////////////////
......
......@@ -44,10 +44,6 @@
uniform sampler3D tex0;
uniform sampler1D TRANSFERFUNCTION_SAMPLER;
// The isovalue to use.
uniform float u_isovalue1 = 0.33;
uniform float u_isovalue2 = 0.80;
/////////////////////////////////////////////////////////////////////////////
// Attributes
/////////////////////////////////////////////////////////////////////////////
......@@ -117,12 +113,12 @@ vec3 getGradient( in vec3 position )
*
* \return the color.
*/
vec4 transferFunction( in float value )
vec4 transferFunction( float value )
{
#ifdef TRANSFERFUNCTION_ENABLED
return texture1D( TRANSFERFUNCTION_SAMPLER, value );
#else
if ( isZero( value - 0.5, 0.1 ) ) // if not TF has been specified, at least show something
if ( isZero( value - 0.5, 0.01 ) ) // if not TF has been specified, at least show something
{
return vec4( 1.0, 0.0, 0.0, 0.1 );
}
......@@ -175,39 +171,34 @@ void main()
vec3 rayEnd = findRayEnd( totalDistance );
// walk along the ray
vec4 accumColor = vec4( vec3( 0.0 ), 1.0 ); // the composited color
float accumAlpha = 1.0; // accumulated transparency of the volume.
float depth = gl_FragCoord.z; // the depth of the last hit
float value; // the current value inside the data
float hit = 0.0; // this value will be != 0.0 if something has been hit
vec4 dst = vec4( 0.0 );
while ( currentDistance <= totalDistance )
{
// get current value
vec3 rayPoint = rayEnd - ( currentDistance * v_ray );
value = texture3D( tex0, rayPoint ).r;
// get current value, classify and illuminate
vec3 rayPoint = v_rayStart + ( currentDistance * v_ray );
vec4 src = localIllumination( rayPoint, transferFunction( texture3D( tex0, rayPoint ).r ) );
// go to next value
currentDistance += v_stepDistance;
// classify point in volume and evaluate local illumination model at this position
vec4 color = localIllumination( rayPoint, transferFunction( value ) );
// apply front-to-back compositing
dst = ( 1.0 - dst.a ) * src + dst;
// has there ever been something we hit?
hit = max( hit, color.a );
accumColor.rgba = mix( accumColor.rgba, color.rgba, color.a ); // compositing
accumAlpha *= ( 1.0 - color.a ); // compositing: keep track of final alpha value of the background
if ( dst.a >= 0.95 )
break;
}
/*
// have we hit something which was classified not to be transparent?
// This is, visually, not needed but useful if volume rendere is used in conjunction with other geometry.
if ( isZero( hit ) )
if ( isZero( dst.a ) )
{
discard;
}
}*/
// set final color
accumColor.a = 1.0 - accumAlpha;
gl_FragColor = accumColor;
gl_FragDepth = depth;
float depth = gl_FragCoord.z;
gl_FragColor = dst;
gl_FragDepth = depth; // the depth of the last hit
}
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