OpenWalnut  1.5.0dev
WGEPostprocessingNode.h
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 #ifndef WGEPOSTPROCESSINGNODE_H
26 #define WGEPOSTPROCESSINGNODE_H
27 
28 #include <map>
29 #include <utility>
30 
31 #include <osg/Switch>
32 
33 #include "../../common/WPropertyVariable.h"
34 #include "../../common/WItemSelection.h"
35 #include "../../common/WSharedAssociativeContainer.h"
36 
37 #include "../offscreen/WGEOffscreenRenderNode.h"
38 #include "../offscreen/WGEOffscreenRenderPass.h"
39 #include "../offscreen/WGEOffscreenFinalPass.h"
40 #include "../callbacks/WGESwitchCallback.h"
41 #include "../callbacks/WGENodeMaskCallback.h"
42 #include "../WGEGroupNode.h"
43 #include "../WGECamera.h"
44 
45 #include "WGEPostprocessor.h"
46 
47 /**
48  * This class enables you to add arbitrary nodes that get post-processed in screen space. The only thing you need to take care of is your shader.
49  * You need some special parts in it. Please see the all-in-one super-shader-example module WMShaderExample in modules/template.
50  *
51  * \note Although this is an osg::Switch node, you should avoid using its inherited API unless you know what you do. Using the osg::Switch API
52  * might be useful for those who want to modify the post-processing pipeline.
53  */
54 class WGEPostprocessingNode: public osg::Switch // NOLINT
55 {
56 public:
57  /**
58  * Convenience typedef for an osg::ref_ptr
59  */
60  typedef osg::ref_ptr< WGEPostprocessingNode > RefPtr;
61 
62  /**
63  * Convenience typedef for an osg::ref_ptr; const
64  */
65  typedef osg::ref_ptr< const WGEPostprocessingNode > ConstRefPtr;
66 
67  /**
68  * Create a new post-processing node. It uses the WGEOffscreenRenderNode to setup an offscreen, shader-based post-processing for rendered
69  * images. This is not limited to geometry but can also be used for ray-traced images.
70  *
71  * \note The width and hight define the offscreen texture size. The viewport if each rendering is automatically set to the one of the
72  * reference camera. This means, width and height only define the maximal supported resolution without upscaling of your postprocessor.
73  *
74  * \param reference camera used as reference
75  * \param width the width of the textures used in this rendering. Must be in [8,4096] and a power of two.
76  * \param height the height of the textures used in this rendering. Must be in [8,4096] and a power of two.
77  * \param noHud If true, no hud gets displayed showing the created and used textures.
78  */
79  WGEPostprocessingNode( osg::ref_ptr< WGECamera > reference, size_t width = 2048, size_t height = 2048, bool noHud = false );
80 
81  /**
82  * Destructor.
83  */
84  virtual ~WGEPostprocessingNode();
85 
86  /**
87  * Returns the set of properties controlling the post-processing node. You can use them to provide them to the user for example.
88  *
89  * \return the properties as a group.
90  */
91  WPropGroup getProperties() const;
92 
93  /**
94  * Inserts a node to the post-processor and injects the needed code to the specified shader. See class documentation for further details on
95  * how the shader gets modified. If you are using an group node, be yourself aware that all nodes in this group need to have the same shader!
96  * If not, post-processing will not work properly.
97  *
98  * \note this is thread-safe and can be done from every thread
99  * \note it does NOT apply the shader.
100  *
101  * \param node the node to post-process
102  * \param shader the shader used for the node
103  */
104  void insert( osg::ref_ptr< osg::Node > node, WGEShader::RefPtr shader = NULL );
105 
106  /**
107  * Removes the node from the post-processing. If it is not in the post-processing pipeline, nothing happens.
108  *
109  * \note this is thread-safe and can be done from every thread
110  *
111  * \param node the node to remove
112  */
113  void remove( osg::ref_ptr< osg::Node > node );
114 
115  /**
116  * Removes all associated nodes.
117  *
118  * \note this is thread-safe and can be done from every thread
119  */
120  void clear();
121 
122  /**
123  * The post processor currently in use.
124  *
125  * \return the current post processor
126  */
128 protected:
129 private:
130  /**
131  * This type is used to actually store the association between a node and its associated shader and custom preprocessor.
132  */
134  std::map<
135  osg::ref_ptr< osg::Node >,
136  std::pair<
139  >
140  >
142 
143  /**
144  * List of nodes and their corresponding shader and preprocessor.
145  */
147 
148  /**
149  * The group of child nodes to post-process.
150  */
151  osg::ref_ptr< WGEGroupNode > m_childs;
152 
153  /**
154  * All the properties of the post-processor.
155  */
156  WPropGroup m_properties;
157 
158  /**
159  * If true, post-processing is enabled.
160  */
161  WPropBool m_active;
162 
163  /**
164  * Activate to show the texture HUDs
165  */
166  WPropBool m_showHud;
167 
168  /**
169  * Activate depth based darkening
170  */
171  WPropBool m_shadeByDepth;
172 
173  /**
174  * Lower depth threshold -> lower depth is background.
175  */
176  WPropDouble m_depthThresholdL;
177 
178  /**
179  * Upper depth threshold -> higher depth is foreground.
180  */
181  WPropDouble m_depthThresholdU;
182 
183  /**
184  * Lower depth shade threshold -> how dark to get
185  */
186  WPropDouble m_depthShadeL;
187 
188  /**
189  * Upper depth threshold -> how bright to get.
190  */
191  WPropDouble m_depthShadeU;
192 
193  /**
194  * Group these depth-shading props.
195  */
196  WPropGroup m_depthGroup;
197 
198  /**
199  * The property containing the currently active method or a combination.
200  */
201  WPropSelection m_activePostprocessor;
202 
203  /**
204  * The postprocessors.
205  */
207 
208  /**
209  * Callback for changes in m_activePostprocessor.
210  */
211  void postprocessorSelected();
212 };
213 
214 #endif // WGEPOSTPROCESSINGNODE_H
215 
This class enables you to add arbitrary nodes that get post-processed in screen space.
WGEPostprocessor::SPtr getCurrentPostprocessor() const
The post processor currently in use.
WPropDouble m_depthShadeU
Upper depth threshold -> how bright to get.
WSharedAssociativeContainer< std::map< osg::ref_ptr< osg::Node >, std::pair< WGEShader::RefPtr, WGEShaderPreprocessor::SPtr > > > NodeShaderAssociation
This type is used to actually store the association between a node and its associated shader and cust...
osg::ref_ptr< const WGEPostprocessingNode > ConstRefPtr
Convenience typedef for an osg::ref_ptr; const.
WPropGroup m_depthGroup
Group these depth-shading props.
virtual ~WGEPostprocessingNode()
Destructor.
WPropBool m_shadeByDepth
Activate depth based darkening.
WPropBool m_showHud
Activate to show the texture HUDs.
WPropDouble m_depthShadeL
Lower depth shade threshold -> how dark to get.
WPropSelection m_activePostprocessor
The property containing the currently active method or a combination.
WPropDouble m_depthThresholdU
Upper depth threshold -> higher depth is foreground.
void postprocessorSelected()
Callback for changes in m_activePostprocessor.
WGEPostprocessingNode(osg::ref_ptr< WGECamera > reference, size_t width=2048, size_t height=2048, bool noHud=false)
Create a new post-processing node.
osg::ref_ptr< WGEGroupNode > m_childs
The group of child nodes to post-process.
WPropDouble m_depthThresholdL
Lower depth threshold -> lower depth is background.
void insert(osg::ref_ptr< osg::Node > node, WGEShader::RefPtr shader=NULL)
Inserts a node to the post-processor and injects the needed code to the specified shader.
NodeShaderAssociation m_nodeShaderAssociation
List of nodes and their corresponding shader and preprocessor.
WPropGroup m_properties
All the properties of the post-processor.
void clear()
Removes all associated nodes.
WGEPostprocessor::ProcessorList m_postprocs
The postprocessors.
void remove(osg::ref_ptr< osg::Node > node)
Removes the node from the post-processing.
WPropGroup getProperties() const
Returns the set of properties controlling the post-processing node.
WPropBool m_active
If true, post-processing is enabled.
osg::ref_ptr< WGEPostprocessingNode > RefPtr
Convenience typedef for an osg::ref_ptr.
std::shared_ptr< WGEPostprocessor > SPtr
Convenience typedef for an osg::ref_ptr< WGEPostprocessor >.
std::vector< WGEPostprocessor::SPtr > ProcessorList
Type used for returning lists of postprocessor prototypes.
std::shared_ptr< WGEShaderPreprocessor > SPtr
Shared pointer for this class.
osg::ref_ptr< WGEShader > RefPtr
Convenience typedef for an osg::ref_ptr.
Definition: WGEShader.h:53
This class provides a common interface for thread-safe access to associative containers (set,...