Commit 28dd3365 authored by schurade's avatar schurade
Browse files

[MERGE]

parents 4228dc66 0ab2976f
......@@ -224,11 +224,15 @@ WDataSetFibers::ColorArray WDataSetFibers::getLocalColors() const
void WDataSetFibers::addColorScheme( WDataSetFibers::ColorArray colors, std::string name, std::string description )
{
ColorScheme::ColorMode mode = ColorScheme::GRAY;
if ( colors->size() % 3 == 0 )
// number of verts is needed to distinguish color mode.
size_t verts = m_vertices->size() / 3;
size_t cols = colors->size();
if ( cols / verts == 3 )
{
mode = ColorScheme::RGB;
}
else if ( colors->size() % 4 == 0 )
else if ( cols / verts == 4 )
{
mode = ColorScheme::RGBA;
}
......
......@@ -58,8 +58,8 @@ WGEPostprocessingNode::WGEPostprocessingNode( osg::ref_ptr< osg::Camera > refere
// some info text:
m_infoText = m_properties->addProperty( "Hint", "This is for advanced users.",
std::string( "The post-processing has to be seen as facility to create appealing images. The here offered options are not all "
"possibilities. The most powerful effects can be achieved by using custom combinations of post-processors and recommended "
"for <b>advanced users</b> only." )
"possibilities. The most powerful effects can be achieved by using custom combinations (using custom GLSL code) of "
"post-processors and is recommended for <b>advanced users</b> only." )
);
m_infoText->setPurpose( PV_PURPOSE_INFORMATION );
......@@ -72,12 +72,13 @@ WGEPostprocessingNode::WGEPostprocessingNode( osg::ref_ptr< osg::Camera > refere
typedef WGEShaderPropertyDefineOptionsTools::NameDescriptionDefineTuple Tuple;
std::vector< Tuple > namesAndDefs;
namesAndDefs.push_back( Tuple( "Color Only", "No Post-Processing.", "WGE_POSTPROCESSOR_COLOR" ) );
namesAndDefs.push_back( Tuple( "Gaussed Color", "Smoothed Color Image using Gauss Filter.", "WGE_POSTPROCESSOR_GAUSSEDCOLOR" ) );
namesAndDefs.push_back( Tuple( "Smoothed Color", "Smoothed Color Image using Gauss Filter.", "WGE_POSTPROCESSOR_GAUSSEDCOLOR" ) );
namesAndDefs.push_back( Tuple( "PPL - Phong", "Per-Pixel-Lighting using Phong.", "WGE_POSTPROCESSOR_PPLPHONG" ) );
namesAndDefs.push_back( Tuple( "SSAO", "Screen-Space Ambient Occlusion.", "WGE_POSTPROCESSOR_SSAO" ) );
namesAndDefs.push_back( Tuple( "Cel Shading", "Under-sampling of the color for cartoon-like shading.", "WGE_POSTPROCESSOR_CELSHADING" ) );
namesAndDefs.push_back( Tuple( "Cel-Shading", "Under-sampling of the color for cartoon-like shading.", "WGE_POSTPROCESSOR_CELSHADING" ) );
namesAndDefs.push_back( Tuple( "Depth-Cueing", "Use the Depth to fade out the pixel's brightness.", "WGE_POSTPROCESSOR_DEPTHFADING" ) );
namesAndDefs.push_back( Tuple( "Edge", "Edge of Rendered Geometry.", "WGE_POSTPROCESSOR_EDGE" ) );
namesAndDefs.push_back( Tuple( "Depth", "Depth Value only.", "WGE_POSTPROCESSOR_DEPTH" ) );
namesAndDefs.push_back( Tuple( "Smoothed Depth", "Gauss-Smoothed Depth Value only.", "WGE_POSTPROCESSOR_GAUSSEDDEPTH" ) );
namesAndDefs.push_back( Tuple( "Normal", "Geometry Normal.", "WGE_POSTPROCESSOR_NORMAL" ) );
namesAndDefs.push_back( Tuple( "Custom", "Provide Your Own Post-processing-Code.", "WGE_POSTPROCESSOR_CUSTOM" ) );
......@@ -99,11 +100,6 @@ WGEPostprocessingNode::WGEPostprocessingNode( osg::ref_ptr< osg::Camera > refere
m_offscreen->getTextureHUD()->addUpdateCallback( new WGENodeMaskCallback( m_showHUD ) );
// let the activePostprocessors property control the options in the shader:
m_postProcessShader->addPreprocessor( activePostprocessorsOpts );
// some of the post-processors need some white noise, like the ssao
const size_t size = 64;
osg::ref_ptr< WGETexture2D > randTex = wge::genWhiteNoiseTexture( size, 3 );
m_postprocess->bind( randTex, 3 );
}
WGEPostprocessingNode::~WGEPostprocessingNode()
......
......@@ -311,11 +311,13 @@ float getEdge()
}
/**
* Returns the gauss-smoothed color of the pixel from the input color texture.
* Returns the gauss-smoothed color of the specified pixel from the input color texture.
*
* \param where the pixel to grab
*
* \return the color
*/
vec4 getGaussedColor()
vec4 getGaussedColor( vec2 where )
{
// TODO(ebaum): provide properties/uniforms for the scaling factors here
......@@ -339,98 +341,53 @@ vec4 getGaussedColor()
}
/**
* Calculate the screen-space ambient occlusion from normal and depth map.
* Returns the gauss-smoothed color of the current pixel from the input color texture.
*
* \return the SSAO factor
* \return the color
*/
float getSSAO()
vec4 getGaussedColor()
{
// NOTE: Currently, most of the code is from http://www.gamerendering.com/2009/01/14/ssao/
// TODO(ebaum): optimize code. It is quite slow curretly.
// some switches which can be used to fine-tune this.
// TODO(ebaum): provide uniforms for this
float totStrength = 1.38; // total strength - scaling the resulting AO
float falloff = 0.000002;
float rad = 0.006;
#define SAMPLES 32 // 10+ is good
const float invSamples = 1.0/float( SAMPLES );
const float strength = 0.07;
// these are the random vectors inside a unit sphere
vec3 pSphere[46] = vec3[]( vec3( 0.53812504, 0.18565957, -0.43192 ), vec3( 0.13790712, 0.24864247, 0.44301823 ),
vec3( 0.33715037, 0.56794053, -0.005789503 ), vec3( -0.6999805, -0.04511441, -0.0019965635 ),
vec3( 0.06896307, -0.15983082, -0.85477847 ), vec3( 0.056099437, 0.006954967, -0.1843352 ),
vec3( -0.014653638, 0.14027752, 0.0762037 ), vec3( 0.010019933, -0.1924225, -0.034443386 ),
vec3( -0.35775623, -0.5301969, -0.43581226 ), vec3( -0.3169221, 0.106360726, 0.015860917 ),
vec3( 0.010350345, -0.58698344, 0.0046293875 ), vec3( -0.08972908, -0.49408212, 0.3287904 ),
vec3( 0.7119986, -0.0154690035, -0.09183723 ), vec3( -0.053382345, 0.059675813, -0.5411899 ),
vec3( 0.035267662, -0.063188605, 0.54602677 ), vec3( -0.47761092, 0.2847911, -0.0271716 ),
vec3( 0.24710192, 0.6445882, 0.033550154 ), vec3( 0.00991752, -0.21947019, 0.7196721 ),
vec3( 0.25109035, -0.1787317, -0.011580509 ), vec3( -0.08781511, 0.44514698, 0.56647956 ),
vec3( -0.011737816, -0.0643377, 0.16030222 ), vec3( 0.035941467, 0.04990871, -0.46533614 ),
vec3( -0.058801126, 0.7347013, -0.25399926 ), vec3( -0.24799341, -0.022052078, -0.13399573 ),
vec3( -0.13657719, 0.30651027, 0.16118456 ), vec3( -0.14714938, 0.33245975, -0.113095455 ),
vec3( 0.030659059, 0.27887347, -0.7332209 ), vec3( 0.009913514, -0.89884496, 0.07381549 ),
vec3( 0.040318526, 0.40091, 0.6847858 ), vec3( 0.22311053, -0.3039437, -0.19340435 ),
vec3( 0.36235332, 0.21894878, -0.05407306 ), vec3( -0.15198798, -0.38409665, -0.46785462 ),
vec3( -0.013492276, -0.5345803, 0.11307949 ), vec3( -0.4972847, 0.037064247, -0.4381323 ),
vec3( -0.024175806, -0.008928787, 0.17719103 ), vec3( 0.694014, -0.122672155, 0.33098832 ),
vec3( -0.010735935, 0.01647018, 0.0062425877 ), vec3( -0.06533369, 0.3647007, -0.13746321 ),
vec3( -0.6539235, -0.016726388, -0.53000957 ), vec3( 0.40958285, 0.0052428036, -0.5591124 ),
vec3( -0.1465366, 0.09899267, 0.15571679 ), vec3( -0.44122112, -0.5458797, 0.04912532 ),
vec3( 0.03755566, -0.10961345, -0.33040273 ), vec3( 0.019100213, 0.29652783, 0.066237666 ),
vec3( 0.8765323, 0.011236004, 0.28265962 ), vec3( 0.29264435, -0.40794238, 0.15964167 ) );
// grab a normal for reflecting the sample rays later on
vec3 fres = normalize( ( texture2D( u_texture3Sampler, pixelCoord * u_texture3SizeX ).xyz * 2.0 ) - vec3( 1.0 ) );
vec3 currentPixelSample = getNormal( pixelCoord ).xyz;
float currentPixelDepth = getDepth( pixelCoord );
// current fragment coords in screen space
vec3 ep = vec3( pixelCoord.xy, currentPixelDepth );
// get the normal of current fragment
vec3 norm = currentPixelSample.xyz;
// accumulated occlusion
float bl = 0.0;
// adjust for the depth ( not shure if this is good..)
float radD = rad / currentPixelDepth;
// some temporaries
vec3 ray, se, occNorm;
float occDepth, depthDifference, normDiff;
for( int i = 0; i < SAMPLES; ++i )
{
// get a vector (randomized inside of a sphere with radius 1.0) from a texture and reflect it
ray = radD * reflect( pSphere[i], fres );
// if the ray is outside the hemisphere then change direction
se = ep + sign( dot( ray, norm ) ) * ray;
// get the depth of the occluder fragment
occDepth = getDepth( se.xy );
// get the normal of the occluder fragment
occNorm = 0.75 * getNormal( se.xy ).xyz;
return getGaussedColor( pixelCoord );
}
// if depthDifference is negative = occluder is behind current fragment
depthDifference = currentPixelDepth - occDepth;
/**
* Returns the gauss-smoothed depth of the specified ixel from the input color texture.
*
* \param where the point to grab
*
* \return the gaussed depth
*/
float getGaussedDepth( vec2 where )
{
// TODO(ebaum): provide properties/uniforms for the scaling factors here
// calculate the difference between the normals as a weight
normDiff = 1.0 - dot( occNorm, norm );
// get the 8-neighbourhood
float gaussedDepthc = getDepth( where );
float gaussedDepthbl = getDepth( where + vec2( -offsetX, -offsetY ) );
float gaussedDepthl = getDepth( where + vec2( -offsetX, 0.0 ) );
float gaussedDepthtl = getDepth( where + vec2( -offsetX, offsetY ) );
float gaussedDeptht = getDepth( where + vec2( 0.0, offsetY ) );
float gaussedDepthtr = getDepth( where + vec2( offsetX, offsetY ) );
float gaussedDepthr = getDepth( where + vec2( offsetX, 0.0 ) );
float gaussedDepthbr = getDepth( where + vec2( offsetX, offsetY ) );
float gaussedDepthb = getDepth( where + vec2( 0.0, -offsetY ) );
// the falloff equation, starts at falloff and is kind of 1/x^2 falling
bl += step( falloff, depthDifference ) * 1.0 * normDiff * ( 1.0 - smoothstep( falloff, strength, depthDifference ) );
}
// apply gauss filter
float gaussed = ( 1.0 / 16.0 ) * (
1.0 * gaussedDepthtl + 2.0 * gaussedDeptht + 1.0 * gaussedDepthtr +
2.0 * gaussedDepthl + 4.0 * gaussedDepthc + 2.0 * gaussedDepthr +
1.0 * gaussedDepthbl + 2.0 * gaussedDepthb + 1.0 * gaussedDepthbr );
return gaussed;
}
// output the result
return 1.0 - ( totStrength * bl * invSamples );
/**
* Returns the gauss-smoothed depth of the current pixel from the input depth texture.
*
* \return the gaussed depth
*/
float getGaussedDepth()
{
return getGaussedDepth( pixelCoord );
}
/**
......@@ -460,6 +417,30 @@ vec4 getCelShading()
return getCelShading( getColor() );
}
/**
* Returns a fade-out factor basing on pixel depth for the specified pixel
*
* \param where pixel coordinate
*
* \return the fade-out factor.
*/
float getDepthFading( vec2 where )
{
// TODO(ebaum): add uniforms for this limits
float invD = ( 1.0 - getDepth( where ) );
return smoothstep( 0.20, 0.5, invD );
}
/**
* Returns a fade-out factor basing on pixel depth for the current pixel.
*
* \return the fade-out factor.
*/
float getDepthFading()
{
return getDepthFading( pixelCoord );
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Main
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......@@ -493,14 +474,14 @@ void main()
blendScale( getPPLPhong() );
#endif
#ifdef WGE_POSTPROCESSOR_SSAO
blendScale( getSSAO() );
#endif
#ifdef WGE_POSTPROCESSOR_CELSHADING
blend( getCelShading() );
#endif
#ifdef WGE_POSTPROCESSOR_DEPTHFADING
blendScale( getDepthFading() );
#endif
#ifdef WGE_POSTPROCESSOR_EDGE
blendAdd( getEdge() );
#endif
......@@ -509,6 +490,10 @@ void main()
blendScale( depth );
#endif
#ifdef WGE_POSTPROCESSOR_GAUSSEDDEPTH
blendScale( getGaussedDepth() );
#endif
#ifdef WGE_POSTPROCESSOR_NORMAL
blend( getNormal() );
#endif
......
......@@ -43,9 +43,10 @@ WMDistanceMapIsosurface::WMDistanceMapIsosurface():
WModuleContainer( "Distance Map Isosurface",
"Computes a smoothed version of the dataset"
" and a distance map on it. Finally it renders"
"this distance map using an isosurface. This isosurface"
" this distance map using an isosurface. This isosurface"
" can be textured with values from scalar data sets in order to display"
"the structures at the given distance." )
" the structures at the given distance."
" This is <b>only</b> useful for peeled data." )
{
// WARNING: initializing connectors inside the constructor will lead to an exception.
// NOTE: Do not use the module factory inside this constructor. This will cause a dead lock as the module factory is locked
......
......@@ -25,14 +25,16 @@
#include <vector>
#include <string>
#include "../../kernel/WKernel.h"
#include "../../common/WPropertyHelper.h"
#include "../../common/WPropertyObserver.h"
#include "../../dataHandler/WDataHandler.h"
#include "../../dataHandler/WDataTexture3D.h"
#include "../../graphicsEngine/shaders/WGEShader.h"
#include "../../graphicsEngine/callbacks/WGENodeMaskCallback.h"
#include "../../graphicsEngine/callbacks/WGEFunctorCallback.h"
#include "../../graphicsEngine/callbacks/WGENodeMaskCallback.h"
#include "../../graphicsEngine/shaders/WGEShader.h"
#include "../../graphicsEngine/shaders/WGEShaderDefineOptions.h"
#include "../../graphicsEngine/shaders/WGEShaderPropertyDefineOptions.h"
#include "../../kernel/WKernel.h"
#include "WMFiberDisplaySimple.h"
#include "WMFiberDisplaySimple.xpm"
......@@ -90,8 +92,8 @@ void WMFiberDisplaySimple::properties()
m_clipPlaneGroup = m_properties->addPropertyGroup( "Clipping", "Clip the fiber data basing on an arbitrary plane." );
m_clipPlaneEnabled = m_clipPlaneGroup->addProperty( "Enabled", "If set, clipping of fibers is done using an arbitrary plane and plane distance.",
false, m_propCondition );
m_clipPlaneShowPlane = m_clipPlaneGroup->addProperty( "Show Clip Plane", "If set, the clipping plane will be shown.", true );
false );
m_clipPlaneShowPlane = m_clipPlaneGroup->addProperty( "Show Clip Plane", "If set, the clipping plane will be shown.", false );
m_clipPlanePoint = m_clipPlaneGroup->addProperty( "Plane point", "An point on the plane.", wmath::WPosition( 0.0, 0.0, 0.0 ) );
m_clipPlaneVector = m_clipPlaneGroup->addProperty( "Plane normal", "The normal of the plane.", wmath::WPosition( 1.0, 0.0, 0.0 ) );
m_clipPlaneDistance= m_clipPlaneGroup->addProperty( "Clip distance", "The distance from the plane where fibers get clipped.", 10.0 );
......@@ -131,6 +133,9 @@ void WMFiberDisplaySimple::moduleMain()
m_clipPlanePointUniform = new WGEPropertyUniform< WPropPosition >( "u_planePoint", m_clipPlanePoint );
m_clipPlaneVectorUniform = new WGEPropertyUniform< WPropPosition >( "u_planeVector", m_clipPlaneVector );
m_clipPlaneDistanceUniform = new WGEPropertyUniform< WPropDouble >( "u_distance", m_clipPlaneDistance );
m_shader->addPreprocessor( WGEShaderPreprocessor::SPtr(
new WGEShaderPropertyDefineOptions< WPropBool >( m_clipPlaneEnabled, "CLIPPLANE_DISABLED", "CLIPPLANE_ENABLED" ) )
);
// get notified about data changes
m_moduleState.setResetable( true, true );
......@@ -141,8 +146,8 @@ void WMFiberDisplaySimple::moduleMain()
ready();
// this node keeps the geode
m_rootNode = osg::ref_ptr< WGEManagedGroupNode > ( new WGEManagedGroupNode( m_active ) );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( m_rootNode );
osg::ref_ptr< WGEManagedGroupNode > rootNode = osg::ref_ptr< WGEManagedGroupNode >( new WGEManagedGroupNode( m_active ) );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( rootNode );
// needed to observe the properties of the input connector data
boost::shared_ptr< WPropertyObserver > propObserver = WPropertyObserver::create();
......@@ -172,7 +177,7 @@ void WMFiberDisplaySimple::moduleMain()
{
debugLog() << "Resetting.";
// remove geode if no valid data is available
m_rootNode->clear();
rootNode->clear();
// remove the fib's properties from my props
m_properties->removeProperty( m_fibProps );
......@@ -238,10 +243,20 @@ void WMFiberDisplaySimple::moduleMain()
fibVerts->at( ( 3 * k ) + sidx + 2 ) ) );
// for correctly indexing the color array, the offset depends on the color mode.
colors->push_back( osg::Vec4( fibColors->at( ( fibColorMode * k ) + csidx + ( 0 % fibColorMode ) ),
fibColors->at( ( fibColorMode * k ) + csidx + ( 1 % fibColorMode ) ),
fibColors->at( ( fibColorMode * k ) + csidx + ( 2 % fibColorMode ) ),
fibColors->at( ( fibColorMode * k ) + csidx + ( 3 % fibColorMode ) ) ) );
if ( fibColorMode == WDataSetFibers::ColorScheme::RGBA )
{
colors->push_back( osg::Vec4( fibColors->at( ( fibColorMode * k ) + csidx + ( 0 % fibColorMode ) ),
fibColors->at( ( fibColorMode * k ) + csidx + ( 1 % fibColorMode ) ),
fibColors->at( ( fibColorMode * k ) + csidx + ( 2 % fibColorMode ) ),
fibColors->at( ( fibColorMode * k ) + csidx + ( 3 % fibColorMode ) ) ) );
}
else
{
colors->push_back( osg::Vec4( fibColors->at( ( fibColorMode * k ) + csidx + ( 0 % fibColorMode ) ),
fibColors->at( ( fibColorMode * k ) + csidx + ( 1 % fibColorMode ) ),
fibColors->at( ( fibColorMode * k ) + csidx + ( 2 % fibColorMode ) ),
1.0 ) );
}
}
// add the above line-strip
......@@ -271,54 +286,49 @@ void WMFiberDisplaySimple::moduleMain()
state->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
// add geode to module node
m_rootNode->clear();
rootNode->clear();
// Apply the shader. This is for clipping.
if ( m_clipPlaneEnabled->get( true ) )
{
state->addUniform( m_clipPlanePointUniform );
state->addUniform( m_clipPlaneVectorUniform );
state->addUniform( m_clipPlaneDistanceUniform );
m_shader->apply( geode );
if ( m_clipPlaneShowPlane->get( true ) )
{
// draw the plane
osg::ref_ptr< osg::Geode > planeGeode = new osg::Geode();
osg::ref_ptr< osg::MatrixTransform > planeTransform = new osg::MatrixTransform();
osg::ref_ptr< osg::Vec3Array > planeVertices = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
osg::ref_ptr< osg::Vec4Array > planeColor = osg::ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
osg::ref_ptr< osg::Geometry > planeGeometry = osg::ref_ptr< osg::Geometry >( new osg::Geometry );
planeColor->push_back( osg::Vec4( 1.0, 0.0, 0.0, 0.125 ) );
planeVertices->push_back( osg::Vec3( 0.0, -100.0, -100.0 ) );
planeVertices->push_back( osg::Vec3( 0.0, -100.0, 100.0 ) );
planeVertices->push_back( osg::Vec3( 0.0, 100.0, 100.0 ) );
planeVertices->push_back( osg::Vec3( 0.0, 100.0, -100.0 ) );
// build geometry
planeGeometry->setVertexArray( planeVertices );
planeGeometry->setColorArray( planeColor );
planeGeometry->setColorBinding( osg::Geometry::BIND_OVERALL );
planeGeometry->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::QUADS, 0, 4 ) );
planeGeode->addDrawable( planeGeometry );
enableTransparency( planeGeode->getOrCreateStateSet() );
// add a callback for showing and hiding the plane
planeTransform->addUpdateCallback( new WGENodeMaskCallback( m_clipPlaneShowPlane ) );
// add a callback which actually moves, scales and rotates the plane according to the plane parameter
planeTransform->addUpdateCallback( new WGEFunctorCallback< osg::Node >(
boost::bind( &WMFiberDisplaySimple::clipPlaneCallback, this, _1 ) )
);
// add the geode to the root and provide an callback
planeTransform->addChild( planeGeode );
m_rootNode->insert( planeTransform );
}
}
m_rootNode->insert( geode );
state->addUniform( m_clipPlanePointUniform );
state->addUniform( m_clipPlaneVectorUniform );
state->addUniform( m_clipPlaneDistanceUniform );
// add the clipping plane
osg::ref_ptr< osg::Geode > planeGeode = new osg::Geode();
osg::ref_ptr< osg::MatrixTransform > planeTransform = new osg::MatrixTransform();
osg::ref_ptr< osg::Vec3Array > planeVertices = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
osg::ref_ptr< osg::Vec4Array > planeColor = osg::ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
osg::ref_ptr< osg::Geometry > planeGeometry = osg::ref_ptr< osg::Geometry >( new osg::Geometry );
planeColor->push_back( osg::Vec4( 1.0, 0.0, 0.0, 0.125 ) );
planeVertices->push_back( osg::Vec3( 0.0, -100.0, -100.0 ) );
planeVertices->push_back( osg::Vec3( 0.0, -100.0, 100.0 ) );
planeVertices->push_back( osg::Vec3( 0.0, 100.0, 100.0 ) );
planeVertices->push_back( osg::Vec3( 0.0, 100.0, -100.0 ) );
// build geometry
planeGeometry->setVertexArray( planeVertices );
planeGeometry->setColorArray( planeColor );
planeGeometry->setColorBinding( osg::Geometry::BIND_OVERALL );
planeGeometry->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::QUADS, 0, 4 ) );
planeGeode->addDrawable( planeGeometry );
enableTransparency( planeGeode->getOrCreateStateSet() );
// add a callback for showing and hiding the plane
planeTransform->addUpdateCallback( new WGENodeMaskCallback( m_clipPlaneShowPlane ) );
// add a callback which actually moves, scales and rotates the plane according to the plane parameter
planeTransform->addUpdateCallback( new WGEFunctorCallback< osg::Node >(
boost::bind( &WMFiberDisplaySimple::clipPlaneCallback, this, _1 ) )
);
// add the geode to the root and provide an callback
planeTransform->addChild( planeGeode );
rootNode->insert( planeTransform );
m_shader->apply( geode );
rootNode->insert( geode );
debugLog() << "Iterating over all fibers: done!";
progress1->finish();
......@@ -326,7 +336,7 @@ void WMFiberDisplaySimple::moduleMain()
// At this point, the container managing this module signalled to shutdown. The main loop has ended and you should clean up. Always remove
// allocated memory and remove all OSG nodes.
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->remove( m_rootNode );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->remove( rootNode );
}
void WMFiberDisplaySimple::clipPlaneCallback( osg::Node* node )
......
......@@ -107,11 +107,6 @@ private:
*/
boost::shared_ptr< WCondition > m_propCondition;
/**
* The root node used for this modules graphics. For OSG nodes, always use osg::ref_ptr to ensure proper resource management.
*/
osg::ref_ptr< WGEManagedGroupNode > m_rootNode;
/**
* The properties of the fiber dataset.
*/
......
......@@ -24,14 +24,18 @@
#version 120
#include "WGETextureTools.glsl"
/////////////////////////////////////////////////////////////////////////////
// Varyings
/////////////////////////////////////////////////////////////////////////////
#ifdef CLIPPLANE_ENABLED
/**
* The distance to the plane
*/
varying float dist;
#endif
/////////////////////////////////////////////////////////////////////////////
// Uniforms
......@@ -59,13 +63,14 @@ uniform float u_distance = 1.0;
*/
void main()
{
#ifdef CLIPPLANE_ENABLED
// discard fragment if too far from plane
if ( abs( dist ) >= u_distance )
{
discard;
}
#endif
gl_FragColor = gl_Color;
gl_FragDepth = gl_FragCoord.z;
}
......@@ -28,10 +28,12 @@
// Varyings
/////////////////////////////////////////////////////////////////////////////
#ifdef CLIPPLANE_ENABLED
/**
* The distance to the plane
*/
varying float dist;
#endif
/////////////////////////////////////////////////////////////////////////////
// Uniforms
......@@ -64,10 +66,12 @@ uniform vec3 u_planeVector;
*/
void main()
{
#ifdef CLIPPLANE_ENABLED
// define the plane
vec3 n = normalize( u_planeVector );
float d = dot( u_planePoint, n );
dist = dot( gl_Vertex.xyz, n ) - d;
#endif
// 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