Commit cc4f8c3d authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD #222] added postproc to isosurface

parent e23f1d38
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
#include "core/graphicsEngine/shaders/WGEPropertyUniform.h" #include "core/graphicsEngine/shaders/WGEPropertyUniform.h"
#include "core/graphicsEngine/shaders/WGEShaderPropertyDefineOptions.h" #include "core/graphicsEngine/shaders/WGEShaderPropertyDefineOptions.h"
#include "core/graphicsEngine/shaders/WGEShaderPropertyDefine.h" #include "core/graphicsEngine/shaders/WGEShaderPropertyDefine.h"
#include "core/graphicsEngine/postprocessing/WGEPostprocessingNode.h"
#include "core/graphicsEngine/WGEColormapping.h" #include "core/graphicsEngine/WGEColormapping.h"
#include "core/graphicsEngine/WGEUtils.h" #include "core/graphicsEngine/WGEUtils.h"
#include "core/kernel/WKernel.h" #include "core/kernel/WKernel.h"
...@@ -109,10 +110,30 @@ void WMIsosurface::moduleMain() ...@@ -109,10 +110,30 @@ void WMIsosurface::moduleMain()
m_moduleState.add( m_input->getDataChangedCondition() ); m_moduleState.add( m_input->getDataChangedCondition() );
m_moduleState.add( m_recompute ); m_moduleState.add( m_recompute );
// create the post-processing node which actually does the nice stuff to the rendered image
osg::ref_ptr< WGEPostprocessingNode > postNode = new WGEPostprocessingNode(
WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getCamera()
);
// provide the properties of the post-processor to the user
m_properties->addProperty( postNode->getProperties() );
// add to scene
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( postNode );
// signal ready state // signal ready state
ready(); ready();
// create shader
m_shader = osg::ref_ptr< WGEShader >( new WGEShader( "WMIsosurface", m_localPath ) );
m_shader->addPreprocessor( WGEShaderPreprocessor::SPtr(
new WGEShaderPropertyDefineOptions< WPropBool >( m_useTextureProp, "COLORMAPPING_DISABLED", "COLORMAPPING_ENABLED" ) )
);
m_moduleNode = new WGEManagedGroupNode( m_active ); m_moduleNode = new WGEManagedGroupNode( m_active );
m_moduleNode->getOrCreateStateSet()->addUniform( new WGEPropertyUniform< WPropInt >( "u_opacity", m_opacityProp ) );
// add it to postproc node and register shader
postNode->insert( m_moduleNode, m_shader );
// loop until the module container requests the module to quit // loop until the module container requests the module to quit
while( !m_shutdownFlag() ) while( !m_shutdownFlag() )
...@@ -177,7 +198,7 @@ void WMIsosurface::moduleMain() ...@@ -177,7 +198,7 @@ void WMIsosurface::moduleMain()
progress->finish(); progress->finish();
} }
WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getScene()->remove( m_moduleNode ); WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getScene()->remove( postNode );
} }
void WMIsosurface::connectors() void WMIsosurface::connectors()
...@@ -431,29 +452,15 @@ void WMIsosurface::renderMesh() ...@@ -431,29 +452,15 @@ void WMIsosurface::renderMesh()
surfaceGeometry->setUseDisplayList( false ); surfaceGeometry->setUseDisplayList( false );
surfaceGeometry->setUseVertexBufferObjects( true ); surfaceGeometry->setUseVertexBufferObjects( true );
// ------------------------------------------------ m_shader->apply( m_surfaceGeode );
// Shader stuff
osg::ref_ptr< WGEShader > shader = osg::ref_ptr< WGEShader >( new WGEShader( "WMIsosurface", m_localPath ) );
shader->addPreprocessor( WGEShaderPreprocessor::SPtr(
new WGEShaderPropertyDefineOptions< WPropBool >( m_useTextureProp, "COLORMAPPING_DISABLED", "COLORMAPPING_ENABLED" ) )
);
state->addUniform( new WGEPropertyUniform< WPropInt >( "u_opacity", m_opacityProp ) );
shader->apply( m_surfaceGeode );
// enable transparency // enable transparency
wge::enableTransparency( m_surfaceGeode ); wge::enableTransparency( m_surfaceGeode );
// Colormapping // Colormapping
WGEColormapping::apply( m_surfaceGeode, shader ); WGEColormapping::apply( m_surfaceGeode, m_shader );
m_moduleNode->insert( m_surfaceGeode ); m_moduleNode->insert( m_surfaceGeode );
if( !m_moduleNodeInserted )
{
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( m_moduleNode );
m_moduleNodeInserted = true;
}
m_moduleNode->addUpdateCallback( new WGEFunctorCallback< osg::Node >( boost::bind( &WMIsosurface::updateGraphicsCallback, this ) ) ); m_moduleNode->addUpdateCallback( new WGEFunctorCallback< osg::Node >( boost::bind( &WMIsosurface::updateGraphicsCallback, this ) ) );
} }
......
...@@ -158,6 +158,11 @@ private: ...@@ -158,6 +158,11 @@ private:
bool m_moduleNodeInserted; //!< ensures that the above module node gets inserted once the first triangle mesh has been calculated. bool m_moduleNodeInserted; //!< ensures that the above module node gets inserted once the first triangle mesh has been calculated.
osg::ref_ptr< osg::Geode > m_surfaceGeode; //!< Pointer to geode containing the surface. osg::ref_ptr< osg::Geode > m_surfaceGeode; //!< Pointer to geode containing the surface.
/**
* The shader
*/
osg::ref_ptr< WGEShader > m_shader;
}; };
#endif // WMISOSURFACE_H #endif // WMISOSURFACE_H
...@@ -25,7 +25,8 @@ ...@@ -25,7 +25,8 @@
#version 120 #version 120
#include "WGEColormapping-fragment.glsl" #include "WGEColormapping-fragment.glsl"
#include "WGETextureTools.glsl"
#include "WGEPostprocessing.glsl"
#include "WGEShadingTools.glsl" #include "WGEShadingTools.glsl"
// opacity in percent // opacity in percent
...@@ -34,6 +35,9 @@ uniform int u_opacity; ...@@ -34,6 +35,9 @@ uniform int u_opacity;
// The surface normal // The surface normal
varying vec3 v_normal; varying vec3 v_normal;
// modelview matrix' scaling factor
varying float v_worldScale;
void main() void main()
{ {
vec4 col = gl_Color; vec4 col = gl_Color;
...@@ -48,5 +52,12 @@ void main() ...@@ -48,5 +52,12 @@ void main()
// opacity of the surface // opacity of the surface
col.rgb = light * col.rgb; col.rgb = light * col.rgb;
col.a = float( u_opacity ) * 0.01; col.a = float( u_opacity ) * 0.01;
gl_FragColor = col;
// finally set the color and depth
wgeInitGBuffer();
wge_FragColor = col;
wge_FragNormal = textureNormalize( normalize( v_normal ) );
wge_FragZoom = v_worldScale;
wge_FragTangent = textureNormalize( v_normal );
} }
...@@ -25,10 +25,14 @@ ...@@ -25,10 +25,14 @@
#version 120 #version 120
#include "WGEColormapping-vertex.glsl" #include "WGEColormapping-vertex.glsl"
#include "WGETransformationTools.glsl"
// The surface normal // The surface normal
varying vec3 v_normal; varying vec3 v_normal;
// modelview matrix' scaling factor
varying float v_worldScale;
void main() void main()
{ {
// prepare colormapping // prepare colormapping
...@@ -37,6 +41,9 @@ void main() ...@@ -37,6 +41,9 @@ void main()
// prepare light // prepare light
v_normal = gl_NormalMatrix * gl_Normal; v_normal = gl_NormalMatrix * gl_Normal;
// Calc the scaling factor in the MV matrix
v_worldScale = getModelViewScale();
gl_FrontColor = gl_Color; gl_FrontColor = gl_Color;
gl_Position = ftransform(); 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