OpenWalnut  1.5.0dev
WGEPostprocessorCelShading.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 
29 #include "WGEPostprocessorCelShading.h"
30 
32  WGEPostprocessor( "Cel Shading",
33  "This postprocessor reduces color by binning colors." )
34 {
35 }
36 
37 WGEPostprocessorCelShading::WGEPostprocessorCelShading( osg::ref_ptr< WGEOffscreenRenderNode > offscreen,
38  const WGEPostprocessor::PostprocessorInput& gbuffer ):
39  WGEPostprocessor( "Cel Shading",
40  "This postprocessor reduces color by binning colors." )
41 {
42  // we also provide a property
43  WPropInt bins = m_properties->addProperty( "Number of Bins", "The number of color bins used for cel shading.", 10 );
44  bins->setMin( 1 );
45  bins->setMax( 100 );
46 
47  // hide m_effectOnly since this is not useful for Cel Shading
48  m_effectOnly->setHidden( true );
49 
50  // construct pipeline
51 
52  // Use the standard postprocessor uber-shader
53  WGEShader::RefPtr s = new WGEShader( "WGEPostprocessor" );
54  s->setDefine( "WGE_POSTPROCESSOR_CEL" );
55 
56  // also add the m_effectOnly property as shader preprocessor
57  s->addPreprocessor( m_effectOnlyPreprocessor );
58 
59  // create the rendering pass
60  osg::ref_ptr< WGEOffscreenTexturePass > pass = offscreen->addTextureProcessingPass( s, "Cel Shading" );
61  pass->getOrCreateStateSet()->addUniform( new WGEPropertyUniform< WPropInt >( "u_celShadingBins", bins ) );
62 
63  // attach color0 output
64  m_resultTextures.push_back( pass->attach( WGECamera::COLOR_BUFFER0, GL_RGBA ) );
65 
66  // provide the Gbuffer input
67  gbuffer.bind( pass );
68 }
69 
71 {
72  // cleanup
73 }
74 
75 WGEPostprocessor::SPtr WGEPostprocessorCelShading::create( osg::ref_ptr< WGEOffscreenRenderNode > offscreen,
76  const WGEPostprocessor::PostprocessorInput& gbuffer ) const
77 {
78  return WGEPostprocessor::SPtr( new WGEPostprocessorCelShading( offscreen, gbuffer ) );
79 }
virtual WGEPostprocessor::SPtr create(osg::ref_ptr< WGEOffscreenRenderNode > offscreen, const PostprocessorInput &gbuffer) const
Create instance.
virtual ~WGEPostprocessorCelShading()
Destructor.
WGEPostprocessorCelShading()
Default constructor.
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.
WPropBool m_effectOnly
A flag denoting whether the effect should be combined with color or not.
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.
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