Commit 0b172dca authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] - added possibility to remove noisy boundaries. This somehow is a dirty solution.

parent 48a8a614
......@@ -136,6 +136,13 @@ void WMIsosurfaceRaytracer::properties()
m_stochasticJitter = m_properties->addProperty( "Stochastic Jitter", "Improves image quality at low sampling rates but introduces slight "
"noise effect.", true );
m_borderClip = m_properties->addProperty( "Border Clip", "If enabled, a certain area on the volume boundary can be clipped. This is useful "
"for noise and non-peeled data but will consume a lot of GPU power.", false );
m_borderClipDistance = m_properties->addProperty( "Border Clip Distance", "The distance that should be ignored.", 0.05 );
m_borderClipDistance->setMin( 0.0 );
m_borderClipDistance->setMax( 0.1 );
WModule::properties();
}
......@@ -157,6 +164,9 @@ void WMIsosurfaceRaytracer::moduleMain()
new WGEShaderPropertyDefineOptions< WPropBool >( m_phongShading, "PHONGSHADING_DISABLED", "PHONGSHADING_ENABLED" ) )
);
WGEShaderDefineSwitch::SPtr gradTexEnableDefine = m_shader->setDefine( "GRADIENTTEXTURE_ENABLED" );
m_shader->addPreprocessor( WGEShaderPreprocessor::SPtr(
new WGEShaderPropertyDefineOptions< WPropBool >( m_borderClip, "BORDERCLIP_DISABLED", "BORDERCLIP_ENABLED" ) )
);
// let the main loop awake if the data changes or the properties changed.
m_moduleState.setResetable( true, true );
......@@ -259,6 +269,7 @@ void WMIsosurfaceRaytracer::moduleMain()
rootState->addUniform( new WGEPropertyUniform< WPropInt >( "u_steps", m_stepCount ) );
rootState->addUniform( new WGEPropertyUniform< WPropDouble >( "u_alpha", m_alpha ) );
rootState->addUniform( new WGEPropertyUniform< WPropDouble >( "u_colormapRatio", m_colormapRatio ) );
rootState->addUniform( new WGEPropertyUniform< WPropDouble >( "u_borderClipDistance", m_borderClipDistance ) );
// Stochastic jitter?
const size_t size = 64;
osg::ref_ptr< WGETexture2D > randTex = wge::genWhiteNoiseTexture( size, size, 1 );
......
......@@ -157,6 +157,16 @@ private:
*/
WPropBool m_stochasticJitter;
/**
* If true, a certain border area can be clipped. Very useful for non-peeled noisy data.
*/
WPropBool m_borderClip;
/**
* The distance used for clipping.
*/
WPropDouble m_borderClipDistance;
/**
* A condition used to notify about changes in several properties.
*/
......
......@@ -59,6 +59,13 @@ uniform int u_texture1SizeX;
uniform sampler3D u_gradientsSampler;
#endif
#ifdef BORDERCLIP_ENABLED
/**
* The distance before the entry/exit point that should be clipped.
*/
uniform float u_borderClipDistance = 0.05;
#endif
// The number of steps to use.
uniform int u_steps;
......@@ -133,7 +140,7 @@ void main()
{
// please do not laugh, it is a very very very simple "isosurface" shader
wge_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
gl_FragDepth = gl_FragCoord.z;
gl_FragDepth = 1.0;
// First, find the rayEnd point. We need to do it in the fragment shader as the ray end point may be interpolated wrong
// when done for each vertex.
......@@ -149,21 +156,29 @@ void main()
// introduce some noise artifacts.
float jitter = 0.5 - texture2D( u_texture1Sampler, gl_FragCoord.xy / u_texture1SizeX ).r;
// the point along the ray in cube coordinates
vec3 curPoint = ( 1.0 * v_ray ) + v_rayStart + ( v_ray * stepDistance * jitter );
vec3 curPoint = v_ray + v_rayStart + ( v_ray * stepDistance * jitter );
vec3 rayStart = curPoint;
#else
// the point along the ray in cube coordinates
vec3 curPoint = ( 1.0 * v_ray ) + v_rayStart;
vec3 curPoint = v_ray + v_rayStart;
#endif
// the step counter
int i = 0;
while ( i < u_steps - 1 ) // we do not need to ch
int i = 1;
while ( i < u_steps )
{
// get current value
value = texture3D( u_texture0Sampler, curPoint ).r;
// is it the isovalue?
if ( abs( value - v_isovalue ) < 0.1 )
if ( ( abs( value - v_isovalue ) < 0.01 )
#ifdef BORDERCLIP_ENABLED
&&
!( length( curPoint - rayStart ) < u_borderClipDistance )
&&
!( length( curPoint - rayEnd ) < u_borderClipDistance )
#endif
)
{
// we need to know the depth value of the current point inside the cube
// Therefore, the complete standard pipeline is reproduced here:
......@@ -231,11 +246,5 @@ void main()
// do not miss to count the steps already done
i++;
}
// the ray did never hit the surface --> discard the pixel
if ( i == u_steps - 1 )
{
discard;
}
}
......@@ -78,9 +78,8 @@ void main()
// transform the ray direction to texture space, which equals object space
// Therefore use two points, as we transform a vector
vec4 camLookAt = vec4( 0.0, 0.0, -1.0, 1.0 );
vec4 camPos = vec4( 0.0, 0.0, 0.0, 1.0 );
v_ray = worldToLocal( camLookAt, camPos ).xyz;
vec4 camLookAt = vec4( 0.0, 0.0, -1.0, 0.0 );
v_ray = worldToLocal( camLookAt ).xyz;
// Simply project the vertex
gl_Position = ftransform();
......
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