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

[ADD #222] added postproc and colormapping to voxelizer module. Disabled...

[ADD #222] added postproc and colormapping to voxelizer module. Disabled transparency since this nearly always creates wrong results without depth sorting.
parent f954049c
......@@ -44,9 +44,15 @@
#include "core/dataHandler/WDataSetScalar.h"
#include "core/dataHandler/WSubject.h"
#include "core/dataHandler/WGridTransformOrtho.h"
#include "core/graphicsEngine/WGEColormapping.h"
#include "core/graphicsEngine/WGEGeodeUtils.h"
#include "core/graphicsEngine/WGEGeometryUtils.h"
#include "core/graphicsEngine/WGEManagedGroupNode.h"
#include "core/graphicsEngine/shaders/WGEShaderDefineOptions.h"
#include "core/graphicsEngine/shaders/WGEShaderPropertyDefineOptions.h"
#include "core/graphicsEngine/shaders/WGEShaderPropertyDefine.h"
#include "core/graphicsEngine/shaders/WGEPropertyUniform.h"
#include "core/graphicsEngine/postprocessing/WGEPostprocessingNode.h"
#include "core/graphicsEngine/WGEUtils.h"
#include "core/kernel/WKernel.h"
#include "core/kernel/WModuleInputData.h"
......@@ -105,6 +111,9 @@ void WMVoxelizer::properties()
WPropertyHelper::PC_SELECTONLYONE::addTo( m_rasterAlgo );
WPropertyHelper::PC_NOTEMPTY::addTo( m_rasterAlgo );
m_phongShading = m_properties->addProperty( "Phong shading", "If enabled, Phong shading gets applied on a per-pixel basis.", true );
m_colorMapping = m_properties->addProperty( "Colormapping", "If enabled, colormapping gets applied on a per-pixel basis.", false );
WModule::properties();
}
......@@ -125,9 +134,33 @@ void WMVoxelizer::moduleMain()
m_moduleState.add( m_clusterIC->getDataChangedCondition() );
m_moduleState.add( m_fullUpdate );
// 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() );
// create the root node containing everything
m_rootNode = new WGEManagedGroupNode( m_active );
m_rootNode->getOrCreateStateSet()->setMode( GL_BLEND, osg::StateAttribute::ON );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( m_rootNode );
// create sheader
osg::ref_ptr< WGEShader > shader( new WGEShader( "WMVoxelizer", m_localPath ) );
shader->addPreprocessor( WGEShaderPreprocessor::SPtr(
new WGEShaderPropertyDefineOptions< WPropBool >( m_phongShading, "PHONGSHADING_DISABLED", "PHONGSHADING_ENABLED" ) )
);
shader->addPreprocessor( WGEShaderPreprocessor::SPtr(
new WGEShaderPropertyDefineOptions< WPropBool >( m_colorMapping, "COLORMAPPING_DISABLED", "COLORMAPPING_ENABLED" ) )
);
// apply colormapping
WGEColormapping::apply( m_rootNode, shader );
// add it to postproc node and register shader
postNode->insert( m_rootNode, shader );
// add to scene
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( postNode );
ready();
......@@ -163,9 +196,9 @@ void WMVoxelizer::moduleMain()
m_moduleState.wait(); // waits for firing of m_moduleState ( dataChanged, shutdown, etc. )
}
// clean up scene
m_rootNode->clear();
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->remove( m_rootNode );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->remove( postNode );
}
boost::shared_ptr< WGridRegular3D > WMVoxelizer::constructGrid( boost::shared_ptr< const WDataSetFibers > tracts,
......@@ -357,18 +390,19 @@ osg::ref_ptr< osg::Geode > WMVoxelizer::genDataSetGeode( boost::shared_ptr< WDat
osg::StateSet* state = geode->getOrCreateStateSet();
// Without depth-sorting, this nearly always creates wrong results. Thus we disable it for now.
// Enable blending, select transparent bin.
state->setMode( GL_BLEND, osg::StateAttribute::ON );
state->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
// state->setMode( GL_BLEND, osg::StateAttribute::ON );
// state->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
//
// Enable depth test so that an opaque polygon will occlude a transparent one behind it.
state->setMode( GL_DEPTH_TEST, osg::StateAttribute::ON );
// state->setMode( GL_DEPTH_TEST, osg::StateAttribute::ON );
//
// Conversely, disable writing to depth buffer so that a transparent polygon will allow polygons behind it to shine through.
// OSG renders transparent polygons after opaque ones.
osg::Depth* depth = new osg::Depth;
depth->setWriteMask( false );
state->setAttributeAndModes( depth, osg::StateAttribute::ON );
// osg::Depth* depth = new osg::Depth;
// depth->setWriteMask( false );
// state->setAttributeAndModes( depth, osg::StateAttribute::ON );
return geode;
}
......@@ -257,6 +257,16 @@ private:
* The actually selected parameterization algorithm.
*/
WPropSelection m_parameterAlgo;
/**
* add colormapping
*/
WPropBool m_colorMapping;
/**
* Add lighting to the scene
*/
WPropBool m_phongShading;
};
inline const std::string WMVoxelizer::getName() const
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#version 120
#include "WGEColormapping-fragment.glsl"
#include "WGETextureTools.glsl"
#include "WGEPostprocessing.glsl"
#include "WGEShadingTools.glsl"
// The surface normal
varying vec3 v_normal;
// modelview matrix' scaling factor
varying float v_worldScale;
void main()
{
vec4 col = gl_Color;
#ifdef COLORMAPPING_ENABLED
col = colormapping();
#endif
float light = 1.0;
#ifdef PHONGSHADING_ENABLED
// do light
light = blinnPhongIlluminationIntensity( normalize( v_normal ) );
#endif
// opacity of the surface
col.rgb = light * col.rgb;
// 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 );
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#version 120
#include "WGEColormapping-vertex.glsl"
#include "WGETransformationTools.glsl"
// The surface normal
varying vec3 v_normal;
// modelview matrix' scaling factor
varying float v_worldScale;
void main()
{
// prepare colormapping
colormapping();
// prepare light
v_normal = gl_NormalMatrix * gl_Normal;
// Calc the scaling factor in the MV matrix
v_worldScale = getModelViewScale();
gl_FrontColor = gl_Color;
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