OpenWalnut  1.5.0dev
WGEPostprocessorGauss.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 "WGEPostprocessorGauss.h"
31 
33  WGEPostprocessor( "Gauss Filtering",
34  "Gauss filter all specified input textures." )
35 {
36 }
37 
38 WGEPostprocessorGauss::WGEPostprocessorGauss( osg::ref_ptr< WGEOffscreenRenderNode > offscreen,
39  osg::ref_ptr< osg::Texture2D > tex0,
40  osg::ref_ptr< osg::Texture2D > tex1,
41  osg::ref_ptr< osg::Texture2D > tex2,
42  osg::ref_ptr< osg::Texture2D > tex3,
43  osg::ref_ptr< osg::Texture2D > tex4,
44  osg::ref_ptr< osg::Texture2D > tex5,
45  osg::ref_ptr< osg::Texture2D > tex6,
46  osg::ref_ptr< osg::Texture2D > tex7 ):
47  WGEPostprocessor( "Gauss Filtering",
48  "Gauss filter all specified input textures." )
49 {
50  // Use the standard postprocessor uber-shader
51  WGEShader::RefPtr s = new WGEShader( "WGEPostprocessor" );
52  s->setDefine( "WGE_POSTPROCESSOR_GAUSS" );
53 
54  // also add the m_effectOnly property as shader preprocessor
55  s->addPreprocessor( m_effectOnlyPreprocessor );
56 
57  // create the rendering pass
58  osg::ref_ptr< WGEOffscreenTexturePass > pass = offscreen->addTextureProcessingPass( s, "Gauss Filter" );
59 
60  // for each of the textures do:
61 
62  // attach color0 output and bind tex0
63  m_resultTextures.push_back( pass->attach( WGECamera::COLOR_BUFFER0, GL_RGBA ) );
64  pass->bind( tex0, 0 );
65  s->setDefine( "WGE_POSTPROCESSOR_GAUSS_UNIT0" );
66 
67  // attach color1 output and bind tex1
68  if( tex1 )
69  {
70  m_resultTextures.push_back( pass->attach( WGECamera::COLOR_BUFFER1, GL_RGBA ) );
71  pass->bind( tex1, 1 );
72  s->setDefine( "WGE_POSTPROCESSOR_GAUSS_UNIT1" );
73  }
74  // attach color2 output and bind tex2
75  if( tex2 )
76  {
77  m_resultTextures.push_back( pass->attach( WGECamera::COLOR_BUFFER2, GL_RGBA ) );
78  pass->bind( tex2, 2 );
79  s->setDefine( "WGE_POSTPROCESSOR_GAUSS_UNIT2" );
80  }
81  // attach color3 output and bind tex3
82  if( tex3 )
83  {
84  m_resultTextures.push_back( pass->attach( WGECamera::COLOR_BUFFER3, GL_RGBA ) );
85  pass->bind( tex3, 3 );
86  s->setDefine( "WGE_POSTPROCESSOR_GAUSS_UNIT3" );
87  }
88  // attach color4 output and bind tex4
89  if( tex4 )
90  {
91  m_resultTextures.push_back( pass->attach( WGECamera::COLOR_BUFFER4, GL_RGBA ) );
92  pass->bind( tex4, 4 );
93  s->setDefine( "WGE_POSTPROCESSOR_GAUSS_UNIT4" );
94  }
95  // attach color5 output and bind tex5
96  if( tex5 )
97  {
98  m_resultTextures.push_back( pass->attach( WGECamera::COLOR_BUFFER5, GL_RGBA ) );
99  pass->bind( tex5, 5 );
100  s->setDefine( "WGE_POSTPROCESSOR_GAUSS_UNIT5" );
101  }
102  // attach color6 output and bind tex6
103  if( tex6 )
104  {
105  m_resultTextures.push_back( pass->attach( WGECamera::COLOR_BUFFER6, GL_RGBA ) );
106  pass->bind( tex6, 6 );
107  s->setDefine( "WGE_POSTPROCESSOR_GAUSS_UNIT6" );
108  }
109  // attach color7 output and bind tex7
110  if( tex7 )
111  {
112  m_resultTextures.push_back( pass->attach( WGECamera::COLOR_BUFFER7, GL_RGBA ) );
113  pass->bind( tex7, 7 );
114  s->setDefine( "WGE_POSTPROCESSOR_GAUSS_UNIT7" );
115  }
116 }
117 
119 {
120  // cleanup
121 }
122 
123 WGEPostprocessor::SPtr WGEPostprocessorGauss::create( osg::ref_ptr< WGEOffscreenRenderNode > offscreen,
124  const WGEPostprocessor::PostprocessorInput& gbuffer ) const
125 {
126  return WGEPostprocessor::SPtr( new WGEPostprocessorGauss( offscreen, gbuffer.m_colorTexture ) );
127 }
128 
virtual ~WGEPostprocessorGauss()
Destructor.
WGEPostprocessorGauss()
Default constructor.
virtual WGEPostprocessor::SPtr create(osg::ref_ptr< WGEOffscreenRenderNode > offscreen, const PostprocessorInput &gbuffer) const
Create instance.
This class encapsulates a G-Buffer.
osg::ref_ptr< osg::Texture2D > m_colorTexture
Color in RGBA.
The base class for all custom post-processors.
WGEShaderPreprocessor::SPtr m_effectOnlyPreprocessor
For convenience, this is a shader preprocessor controlled by m_effectOnly property.
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 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