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