OpenWalnut  1.3.1
WGEPostprocessor.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 <string>
26 #include <vector>
27 
28 #include "WGEPostprocessorEdgeEnhance.h"
29 #include "WGEPostprocessorCelShading.h"
30 #include "WGEPostprocessorGauss.h"
31 #include "WGEPostprocessorSSAO.h"
32 #include "WGEPostprocessorLineAO.h"
33 
34 #include "WGEPostprocessor.h"
35 
36 WGEPostprocessor::WGEPostprocessor( std::string name, std::string description ):
37  WPrototyped(),
38  m_resultTextures(),
39  m_depthTexture(),
40  m_properties( boost::shared_ptr< WProperties >( new WProperties( "Settings for " + name, "Post-processing properties" ) ) ),
41  m_name( name ),
42  m_description( description )
43 {
44  // there is always one property:
45  m_effectOnly = m_properties->addProperty( "Effect Only", "If active, the plain effect will be shown instead a combination of effect "
46  "and color. This settings does not affect all postprocessors.", false );
47 
48  // for convenience, also create a preprocessor for this property
50  "WGE_POSTPROCESSOR_OUTPUT_COMBINE", "WGE_POSTPROCESSOR_OUTPUT_EFFECT_ONLY" ) );
51 }
52 
54 {
55  // cleanup
56 }
57 
59 {
60  return m_properties;
61 }
62 
63 osg::ref_ptr< osg::Texture2D > WGEPostprocessor::getOutput( size_t idx ) const
64 {
65  return m_resultTextures[ idx ];
66 }
67 
68 const std::vector< osg::ref_ptr< osg::Texture2D > >& WGEPostprocessor::getOutputList() const
69 {
70  return m_resultTextures;
71 }
72 
73 osg::ref_ptr< osg::Texture2D > WGEPostprocessor::getDepth() const
74 {
75  return m_depthTexture;
76 }
77 
79 {
80  // leave them uni-initialized
81 }
82 
83 WGEPostprocessor::PostprocessorInput::PostprocessorInput( std::vector< osg::ref_ptr< osg::Texture2D > > from )
84 {
85  if( from.size() > 0 )
86  {
87  m_colorTexture = from[0];
88  }
89  if( from.size() > 1 )
90  {
91  m_normalTexture = from[1];
92  }
93  if( from.size() > 2 )
94  {
95  m_parameterTexture = from[2];
96  }
97  if( from.size() > 3 )
98  {
99  m_tangentTexture = from[3];
100  }
101  if( from.size() > 4 )
102  {
103  m_depthTexture = from[4];
104  }
105 }
106 WGEPostprocessor::PostprocessorInput::PostprocessorInput( osg::ref_ptr< osg::Texture2D > color,
107  osg::ref_ptr< osg::Texture2D > normal,
108  osg::ref_ptr< osg::Texture2D > parameter,
109  osg::ref_ptr< osg::Texture2D > tangent,
110  osg::ref_ptr< osg::Texture2D > depth ):
111  m_colorTexture( color ),
112  m_normalTexture( normal ),
113  m_parameterTexture( parameter ),
114  m_tangentTexture( tangent ),
115  m_depthTexture( depth )
116 {
117 }
118 
120 {
121  PostprocessorInput buf;
122  buf.m_colorTexture = from->attach( osg::Camera::COLOR_BUFFER0 );
123  buf.m_normalTexture = from->attach( osg::Camera::COLOR_BUFFER1, GL_RGB );
124  buf.m_parameterTexture = from->attach( osg::Camera::COLOR_BUFFER2, GL_LUMINANCE );
125  buf.m_tangentTexture = from->attach( osg::Camera::COLOR_BUFFER3, GL_RGB );
126  buf.m_depthTexture = from->attach( osg::Camera::DEPTH_BUFFER );
127 
128  return buf;
129 }
130 
131 size_t WGEPostprocessor::PostprocessorInput::bind( osg::ref_ptr< WGEOffscreenRenderPass > to ) const
132 {
133  to->bind( m_colorTexture, 0 );
134  to->bind( m_normalTexture, 1 );
135  to->bind( m_parameterTexture, 2 );
136  to->bind( m_depthTexture, 3 );
137  to->bind( m_tangentTexture, 4 );
138 
139  return 5;
140 }
141 
143 {
145 
146  // create prototypes of the postprocessors OW knows about
147  postprocs.push_back( WGEPostprocessor::SPtr( new WGEPostprocessorEdgeEnhance() ) );
148  postprocs.push_back( WGEPostprocessor::SPtr( new WGEPostprocessorCelShading() ) );
149  postprocs.push_back( WGEPostprocessor::SPtr( new WGEPostprocessorGauss() ) );
150  postprocs.push_back( WGEPostprocessor::SPtr( new WGEPostprocessorSSAO() ) );
151  postprocs.push_back( WGEPostprocessor::SPtr( new WGEPostprocessorLineAO() ) );
152  return postprocs;
153 }
154 
155 const std::string WGEPostprocessor::getName() const
156 {
157  return m_name;
158 }
159 
160 const std::string WGEPostprocessor::getDescription() const
161 {
162  return m_description;
163 }
164