OpenWalnut  1.4.0
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 
37 
38 WGEPostprocessor::WGEPostprocessor( std::string name, std::string description ):
39  WPrototyped(),
40  m_resultTextures(),
41  m_depthTexture(),
42  m_properties( boost::shared_ptr< WProperties >( new WProperties( "Settings for " + name, "Post-processing properties" ) ) ),
43  m_name( name ),
44  m_description( description )
45 {
46  // there is always one property:
47  m_effectOnly = m_properties->addProperty( "Effect Only", "If active, the plain effect will be shown instead a combination of effect "
48  "and color. This settings does not affect all postprocessors.", false );
49  m_effectScale = m_properties->addProperty( "Effect Scaling", "Use this to overemphasize an effect or to weaken it. Technically spoken, this "
50  "factor determines the pre-multiplication done prior to blending with the input color.", 1.0,
51  true );
52  m_effectScale->setMin( 0.0 );
53  m_effectScale->setMax( 10.0 );
54 
55  // for convenience, also create a preprocessor for this property
57  "WGE_POSTPROCESSOR_OUTPUT_COMBINE", "WGE_POSTPROCESSOR_OUTPUT_EFFECT_ONLY" ) );
58 }
59 
61 {
62  // cleanup
63 }
64 
66 {
67  return m_properties;
68 }
69 
70 osg::ref_ptr< osg::Texture2D > WGEPostprocessor::getOutput( size_t idx ) const
71 {
72  return m_resultTextures[ idx ];
73 }
74 
75 const std::vector< osg::ref_ptr< osg::Texture2D > >& WGEPostprocessor::getOutputList() const
76 {
77  return m_resultTextures;
78 }
79 
80 osg::ref_ptr< osg::Texture2D > WGEPostprocessor::getDepth() const
81 {
82  return m_depthTexture;
83 }
84 
86 {
87  // leave them uni-initialized
88 }
89 
90 WGEPostprocessor::PostprocessorInput::PostprocessorInput( std::vector< osg::ref_ptr< osg::Texture2D > > from )
91 {
92  if( from.size() > 0 )
93  {
94  m_colorTexture = from[0];
95  }
96  if( from.size() > 1 )
97  {
98  m_normalTexture = from[1];
99  }
100  if( from.size() > 2 )
101  {
102  m_parameterTexture = from[2];
103  }
104  if( from.size() > 3 )
105  {
106  m_tangentTexture = from[3];
107  }
108  if( from.size() > 4 )
109  {
110  m_depthTexture = from[4];
111  }
112 }
113 
114 WGEPostprocessor::PostprocessorInput::PostprocessorInput( osg::ref_ptr< osg::Texture2D > color,
115  osg::ref_ptr< osg::Texture2D > normal,
116  osg::ref_ptr< osg::Texture2D > parameter,
117  osg::ref_ptr< osg::Texture2D > tangent,
118  osg::ref_ptr< osg::Texture2D > depth ):
119  m_colorTexture( color ),
120  m_normalTexture( normal ),
121  m_parameterTexture( parameter ),
122  m_tangentTexture( tangent ),
123  m_depthTexture( depth )
124 {
125 }
126 
128 {
129  PostprocessorInput buf;
130  buf.m_colorTexture = from->attach( WGECamera::COLOR_BUFFER0 );
131  buf.m_normalTexture = from->attach( WGECamera::COLOR_BUFFER1, GL_RGB );
132  buf.m_parameterTexture = from->attach( WGECamera::COLOR_BUFFER2, GL_R32F );
133  buf.m_tangentTexture = from->attach( WGECamera::COLOR_BUFFER3, GL_RGB );
134  buf.m_depthTexture = from->attach( WGECamera::DEPTH_BUFFER );
135 
136  return buf;
137 }
138 
139 size_t WGEPostprocessor::PostprocessorInput::bind( osg::ref_ptr< WGEOffscreenRenderPass > to ) const
140 {
141  to->bind( m_colorTexture, 0 );
142  to->bind( m_normalTexture, 1 );
143  to->bind( m_parameterTexture, 2 );
144  to->bind( m_depthTexture, 3 );
145  to->bind( m_tangentTexture, 4 );
146 
147  return 5;
148 }
149 
151 {
152  return m_postProcessors;
153 }
154 
156 {
157  // create prototypes of the postprocessors we know.
163 }
164 
166 {
167  m_postProcessors.push_back( processor );
168  return m_postProcessors.size() - 1;
169 }
170 
171 const std::string WGEPostprocessor::getName() const
172 {
173  return m_name;
174 }
175 
176 const std::string WGEPostprocessor::getDescription() const
177 {
178  return m_description;
179 }
180 
182 {
183  return false;
184 }
osg::ref_ptr< osg::Texture2D > m_depthTexture
Depth.
virtual const std::string getName() const
Gets the name of this postprocessor.
virtual bool getFixedViewportSize() const
When this returns true, the viewport size is fixed to the size of the target texture.
LineAO implementation.
virtual osg::ref_ptr< osg::Texture2D > getOutput(size_t idx=0) const
Returns the result texture.
osg::ref_ptr< osg::Texture2D > m_parameterTexture
Some not yet defined parameter texture, LUMINANCE only.
This class encapsulates a G-Buffer.
std::string m_name
Name string.
WPropBool m_effectOnly
A flag denoting whether the effect should be combined with color or not.
std::vector< WGEPostprocessor::SPtr > ProcessorList
Type used for returning lists of postprocessor prototypes.
boost::shared_ptr< WGEPostprocessor > SPtr
Convenience typedef for an osg::ref_ptr< WGEPostprocessor >.
Gauss filtering of the input.
virtual const std::string getDescription() const
Gets the description for this postprocessor.
This is a WGEShaderDefineOptions class which additionally uses a property to automatically control th...
WGEPostprocessor(std::string name, std::string description)
Create named prototype.
WPropDouble m_effectScale
Scale the effect prior to blending it.
WGEShaderPreprocessor::SPtr m_effectOnlyPreprocessor
For convenience, this is a shader preprocessor controlled by m_effectOnly property.
Interface class for the concept "Prototype".
Definition: WPrototyped.h:37
PostprocessorInput()
Constructor creates empty GBuffer.
static void initPostprocessors()
Needs to be called prior to any "getPostprocessors" call.
virtual osg::ref_ptr< osg::Texture2D > getDepth() const
Returns the new depth texture.
size_t bind(osg::ref_ptr< WGEOffscreenRenderPass > to) const
Attaches these textures to the specified renderpass.
osg::ref_ptr< osg::Texture2D > m_normalTexture
Normal in RGB.
Class to manage properties of an object and to provide convenience methods for easy access and manipu...
Cel shading effect postprocessor.
static size_t addPostprocessor(SPtr processor)
Allows adding a postprocessor.
std::vector< osg::ref_ptr< osg::Texture2D > > m_resultTextures
The textures contain the result.
osg::ref_ptr< osg::Texture2D > m_depthTexture
The texture contains the new depth.
std::string m_description
Description string.
boost::shared_ptr< WGEShaderPreprocessor > SPtr
Shared pointer for this class.
const std::vector< osg::ref_ptr< osg::Texture2D > > & getOutputList() const
This processor can produce multiple outputs.
static PostprocessorInput attach(osg::ref_ptr< WGEOffscreenRenderPass > from)
Attaches the needed textures to the specified render pass and returns the G-Buffer.
osg::ref_ptr< osg::Texture2D > m_colorTexture
Color in RGBA.
virtual ~WGEPostprocessor()
Destructor.
static ProcessorList m_postProcessors
List of all postprocessors.
Edge enhancing postprocessor.
osg::ref_ptr< osg::Texture2D > m_tangentTexture
Tangent in RGB.
virtual WPropGroup getProperties() const
Returns the set of properties controlling the post-processing node.
static ProcessorList getPostprocessors()
Returns a list of all known postprocessor prototypes.
WPropGroup m_properties
All the properties of the post-processor.
Naive SSAO implementation.