OpenWalnut  1.5.0dev
WGEPostprocessorEdgeEnhance.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <osg/Camera>
26 
27 #include "../shaders/WGEPropertyUniform.h"
28 #include "../shaders/WGEShaderPropertyDefineOptions.h"
29 
30 #include "WGEPostprocessorEdgeEnhance.h"
31 
33  WGEPostprocessor( "Edge Enhance",
34  "Edge detection filter to emphasize edges in complex geometry." )
35 {
36 }
37 
38 WGEPostprocessorEdgeEnhance::WGEPostprocessorEdgeEnhance( osg::ref_ptr< WGEOffscreenRenderNode > offscreen,
39  const WGEPostprocessor::PostprocessorInput& gbuffer ):
40  WGEPostprocessor( "Edge Enhance",
41  "Edge detection filter to emphasize edges in complex geometry." )
42 {
43  // we also provide a property
44  WPropBool whiteEdge = m_properties->addProperty( "White Edge", "If set, the edge is drawn in white instead of black.", false );
45  WPropDouble edgeThresholdL = m_properties->addProperty( "Edge Lower Threshold", "Define the edge threshold. Filters way \"weak\" edges.", 0.0 );
46  WPropDouble edgeThresholdU = m_properties->addProperty( "Edge Upper Threshold", "Define the edge threshold. Filters way \"weak\" edges.", 1.0 );
47  edgeThresholdL->setMin( 0.0 );
48  edgeThresholdL->setMax( 1.0 );
49  edgeThresholdU->setMin( 0.0 );
50  edgeThresholdU->setMax( 1.0 );
51 
52  // Use the standard postprocessor uber-shader
53  WGEShader::RefPtr s = new WGEShader( "WGEPostprocessor" );
54  s->setDefine( "WGE_POSTPROCESSOR_EDGE" );
55 
56  // also add the m_effectOnly property as shader preprocessor
57  s->addPreprocessor( m_effectOnlyPreprocessor );
58  s->addPreprocessor( WGEShaderPreprocessor::SPtr(
59  new WGEShaderPropertyDefineOptions< WPropBool >( whiteEdge, "WGE_POSTPROCESSOR_EDGE_BLACKEDGE", "WGE_POSTPROCESSOR_EDGE_WHITEEDGE" ) )
60  );
61 
62  // create the rendering pass
63  osg::ref_ptr< WGEOffscreenTexturePass > pass = offscreen->addTextureProcessingPass( s, "Edge Detection" );
64  pass->getOrCreateStateSet()->addUniform( new WGEPropertyUniform< WPropDouble >( "u_edgeEdgeThresholdUpper", edgeThresholdU ) );
65  pass->getOrCreateStateSet()->addUniform( new WGEPropertyUniform< WPropDouble >( "u_edgeEdgeThresholdLower", edgeThresholdL ) );
66 
67  // attach color0 output
68  m_resultTextures.push_back( pass->attach( WGECamera::COLOR_BUFFER0, GL_RGB ) );
69 
70  // provide the Gbuffer input
71  gbuffer.bind( pass );
72 }
73 
75 {
76  // cleanup
77 }
78 
79 WGEPostprocessor::SPtr WGEPostprocessorEdgeEnhance::create( osg::ref_ptr< WGEOffscreenRenderNode > offscreen,
80  const WGEPostprocessor::PostprocessorInput& gbuffer ) const
81 {
82  return WGEPostprocessor::SPtr( new WGEPostprocessorEdgeEnhance( offscreen, gbuffer ) );
83 }
WGEPostprocessorEdgeEnhance()
Default constructor.
virtual ~WGEPostprocessorEdgeEnhance()
Destructor.
virtual WGEPostprocessor::SPtr create(osg::ref_ptr< WGEOffscreenRenderNode > offscreen, const PostprocessorInput &gbuffer) const
Create instance.
This class encapsulates a G-Buffer.
size_t bind(osg::ref_ptr< WGEOffscreenRenderPass > to) const
Attaches these textures to the specified renderpass.
The base class for all custom post-processors.
WGEShaderPreprocessor::SPtr m_effectOnlyPreprocessor
For convenience, this is a shader preprocessor controlled by m_effectOnly property.
WPropGroup m_properties
All the properties of the post-processor.
std::shared_ptr< WGEPostprocessor > SPtr
Convenience typedef for an osg::ref_ptr< WGEPostprocessor >.
std::vector< osg::ref_ptr< osg::Texture2D > > m_resultTextures
The textures contain the result.
Class implementing a uniform which can be controlled by a property instance.
std::shared_ptr< WGEShaderPreprocessor > SPtr
Shared pointer for this class.
This is a WGEShaderDefineOptions class which additionally uses a property to automatically control th...
Class encapsulating the OSG Program class for a more convenient way of adding and modifying shader.
Definition: WGEShader.h:48
osg::ref_ptr< WGEShader > RefPtr
Convenience typedef for an osg::ref_ptr.
Definition: WGEShader.h:53