OpenWalnut  1.4.0
WGEPostprocessorEdgeEnhance.cpp
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #include <osg/Camera>
00026 
00027 #include "../shaders/WGEPropertyUniform.h"
00028 #include "../shaders/WGEShaderPropertyDefineOptions.h"
00029 
00030 #include "WGEPostprocessorEdgeEnhance.h"
00031 
00032 WGEPostprocessorEdgeEnhance::WGEPostprocessorEdgeEnhance():
00033     WGEPostprocessor( "Edge Enhance",
00034                       "Edge detection filter to emphasize edges in complex geometry." )
00035 {
00036 }
00037 
00038 WGEPostprocessorEdgeEnhance::WGEPostprocessorEdgeEnhance( osg::ref_ptr< WGEOffscreenRenderNode > offscreen,
00039                                                           const WGEPostprocessor::PostprocessorInput& gbuffer ):
00040     WGEPostprocessor( "Edge Enhance",
00041                       "Edge detection filter to emphasize edges in complex geometry." )
00042 {
00043     // we also provide a property
00044     WPropBool whiteEdge = m_properties->addProperty( "White Edge", "If set, the edge is drawn in white instead of black.", false );
00045     WPropDouble edgeThresholdL = m_properties->addProperty( "Edge Lower Threshold", "Define the edge threshold. Filters way \"weak\" edges.", 0.0 );
00046     WPropDouble edgeThresholdU = m_properties->addProperty( "Edge Upper Threshold", "Define the edge threshold. Filters way \"weak\" edges.", 1.0 );
00047     edgeThresholdL->setMin( 0.0 );
00048     edgeThresholdL->setMax( 1.0 );
00049     edgeThresholdU->setMin( 0.0 );
00050     edgeThresholdU->setMax( 1.0 );
00051 
00052     // Use the standard postprocessor uber-shader
00053     WGEShader::RefPtr s = new WGEShader( "WGEPostprocessor" );
00054     s->setDefine( "WGE_POSTPROCESSOR_EDGE" );
00055 
00056     // also add the m_effectOnly property as shader preprocessor
00057     s->addPreprocessor( m_effectOnlyPreprocessor );
00058     s->addPreprocessor( WGEShaderPreprocessor::SPtr(
00059         new WGEShaderPropertyDefineOptions< WPropBool >( whiteEdge, "WGE_POSTPROCESSOR_EDGE_BLACKEDGE", "WGE_POSTPROCESSOR_EDGE_WHITEEDGE" ) )
00060     );
00061 
00062     // create the rendering pass
00063     osg::ref_ptr< WGEOffscreenTexturePass > pass = offscreen->addTextureProcessingPass( s, "Edge Detection" );
00064     pass->getOrCreateStateSet()->addUniform( new WGEPropertyUniform< WPropDouble >( "u_edgeEdgeThresholdUpper", edgeThresholdU ) );
00065     pass->getOrCreateStateSet()->addUniform( new WGEPropertyUniform< WPropDouble >( "u_edgeEdgeThresholdLower", edgeThresholdL ) );
00066 
00067     // attach color0 output
00068     m_resultTextures.push_back( pass->attach( WGECamera::COLOR_BUFFER0, GL_RGB ) );
00069 
00070     // provide the Gbuffer input
00071     gbuffer.bind( pass );
00072 }
00073 
00074 WGEPostprocessorEdgeEnhance::~WGEPostprocessorEdgeEnhance()
00075 {
00076     // cleanup
00077 }
00078 
00079 WGEPostprocessor::SPtr WGEPostprocessorEdgeEnhance::create( osg::ref_ptr< WGEOffscreenRenderNode > offscreen,
00080     const WGEPostprocessor::PostprocessorInput& gbuffer ) const
00081 {
00082     return WGEPostprocessor::SPtr( new WGEPostprocessorEdgeEnhance( offscreen, gbuffer ) );
00083 }