OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 "../WExportWGE.h"
44 
45 /**
46  * 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.
47  * You need some special parts in it. Please see the all-in-one super-shader-example module WMShaderExample in modules/template.
48  *
49  * \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
50  * might be useful for those who want to modify the post-processing pipeline.
51  */
52 class WGE_EXPORT WGEPostprocessingNode: public osg::Switch // NOLINT
53 {
54 public:
55 
56  /**
57  * Convenience typedef for an osg::ref_ptr
58  */
59  typedef osg::ref_ptr< WGEPostprocessingNode > RefPtr;
60 
61  /**
62  * Convenience typedef for an osg::ref_ptr; const
63  */
64  typedef osg::ref_ptr< const WGEPostprocessingNode > ConstRefPtr;
65 
66  /**
67  * Create a new post-processing node. It used the WGEOffscreenRenderNode to setup an offscreen, shader-based post-processing for rendered
68  * images. This is not limited to geometry but can also be used for ray-traced images.
69  *
70  * \param reference camera used as reference
71  * \param width the width of the textures used in this rendering
72  * \param height the height of the textures used in this rendering*
73  * \param noHud If true, no hud gets displayed showing the created and used textures.
74  */
75  WGEPostprocessingNode( osg::ref_ptr< osg::Camera > reference, size_t width = 2048, size_t height = 2048, bool noHud = false );
76 
77  /**
78  * Destructor.
79  */
80  virtual ~WGEPostprocessingNode();
81 
82  /**
83  * Returns the set of properties controlling the post-processing node. You can use them to provide them to the user for example.
84  *
85  * \return the properties as a group.
86  */
87  WPropGroup getProperties() const;
88 
89  /**
90  * Inserts a node to the post-processor and injects the needed code to the specified shader. See class documentation for further details on
91  * 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!
92  * If not, post-processing will not work properly.
93  *
94  * \note this is thread-safe and can be done from every thread
95  * \note it does NOT apply the shader.
96  *
97  * \param node the node to post-process
98  * \param shader the shader used for the node
99  */
100  void insert( osg::ref_ptr< osg::Node > node, WGEShader::RefPtr shader = NULL );
101 
102  /**
103  * Removes the node from the post-processing. If it is not in the post-processing pipeline, nothing happens.
104  *
105  * \note this is thread-safe and can be done from every thread
106  *
107  * \param node the node to remove
108  */
109  void remove( osg::ref_ptr< osg::Node > node );
110 
111  /**
112  * Removes all associated nodes.
113  *
114  * \note this is thread-safe and can be done from every thread
115  */
116  void clear();
117 
118  /**
119  * Activates/Deactivates the post-processing. This is a shortcut for getProperties()->getProperty( "Enable" )->toPropBool()->set( enable ).
120  *
121  * \param enable if true, post-processing is active-
122  */
123  void setEnabled( bool enable = true );
124 
125 protected:
126 
127 private:
128 
129  /**
130  * This type is used to actually store the association between a node and its associated shader and custom preprocessor.
131  */
133  std::map<
134  osg::ref_ptr< osg::Node >,
135  std::pair<
138  >
139  >
141 
142  /**
143  * List of nodes and their corresponding shader and preprocessor.
144  */
146 
147  /**
148  * The actual offscreen render node.
149  */
150  osg::ref_ptr< WGEOffscreenRenderNode > m_offscreen;
151 
152  /**
153  * The group of child nodes to post-process.
154  */
155  osg::ref_ptr< WGEGroupNode > m_childs;
156 
157  /**
158  * The first pass, rendering.
159  */
160  osg::ref_ptr< WGEOffscreenRenderPass > m_render;
161 
162  /**
163  * The actual post-processing.
164  */
165  osg::ref_ptr< WGEOffscreenFinalPass > m_postprocess;
166 
167  /**
168  * This shader actually does post-processing in screen space.
169  */
171 
172  /**
173  * All the properties of the post-processor.
174  */
175  WPropGroup m_properties;
176 
177  /**
178  * If true, post-processing is enabled.
179  */
180  WPropBool m_active;
181 
182  /**
183  * If true, a HUD with intermediate textures is shown.
184  */
185  WPropBool m_showHUD;
186 
187  /**
188  * The property containing the currently active method or a combination.
189  */
190  WPropSelection m_activePostprocessors;
191 
192  /**
193  * Possible post-processors.
194  */
195  boost::shared_ptr< WItemSelection > m_possiblePostprocessors;
196 
197  /**
198  * Some text denoting that this is not yet completely done.
199  */
200  WPropString m_infoText;
201 };
202 
203 #endif // WGEPOSTPROCESSINGNODE_H
204