OpenWalnut
1.2.5
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WGEPOSTPROCESSINGNODE_H 00026 #define WGEPOSTPROCESSINGNODE_H 00027 00028 #include <map> 00029 #include <utility> 00030 00031 #include <osg/Switch> 00032 00033 #include "../../common/WPropertyVariable.h" 00034 #include "../../common/WItemSelection.h" 00035 #include "../../common/WSharedAssociativeContainer.h" 00036 00037 #include "../offscreen/WGEOffscreenRenderNode.h" 00038 #include "../offscreen/WGEOffscreenRenderPass.h" 00039 #include "../offscreen/WGEOffscreenFinalPass.h" 00040 #include "../callbacks/WGESwitchCallback.h" 00041 #include "../callbacks/WGENodeMaskCallback.h" 00042 #include "../WGEGroupNode.h" 00043 #include "../WExportWGE.h" 00044 00045 /** 00046 * 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. 00047 * You need some special parts in it. Please see the all-in-one super-shader-example module WMShaderExample in modules/template. 00048 * 00049 * \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 00050 * might be useful for those who want to modify the post-processing pipeline. 00051 */ 00052 class WGE_EXPORT WGEPostprocessingNode: public osg::Switch // NOLINT 00053 { 00054 public: 00055 00056 /** 00057 * Convenience typedef for an osg::ref_ptr 00058 */ 00059 typedef osg::ref_ptr< WGEPostprocessingNode > RefPtr; 00060 00061 /** 00062 * Convenience typedef for an osg::ref_ptr; const 00063 */ 00064 typedef osg::ref_ptr< const WGEPostprocessingNode > ConstRefPtr; 00065 00066 /** 00067 * Create a new post-processing node. It used the WGEOffscreenRenderNode to setup an offscreen, shader-based post-processing for rendered 00068 * images. This is not limited to geometry but can also be used for ray-traced images. 00069 * 00070 * \param reference camera used as reference 00071 * \param width the width of the textures used in this rendering 00072 * \param height the height of the textures used in this rendering* 00073 * \param noHud If true, no hud gets displayed showing the created and used textures. 00074 */ 00075 WGEPostprocessingNode( osg::ref_ptr< osg::Camera > reference, size_t width = 2048, size_t height = 2048, bool noHud = false ); 00076 00077 /** 00078 * Destructor. 00079 */ 00080 virtual ~WGEPostprocessingNode(); 00081 00082 /** 00083 * Returns the set of properties controlling the post-processing node. You can use them to provide them to the user for example. 00084 * 00085 * \return the properties as a group. 00086 */ 00087 WPropGroup getProperties() const; 00088 00089 /** 00090 * Inserts a node to the post-processor and injects the needed code to the specified shader. See class documentation for further details on 00091 * 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! 00092 * If not, post-processing will not work properly. 00093 * 00094 * \note this is thread-safe and can be done from every thread 00095 * \note it does NOT apply the shader. 00096 * 00097 * \param node the node to post-process 00098 * \param shader the shader used for the node 00099 */ 00100 void insert( osg::ref_ptr< osg::Node > node, WGEShader::RefPtr shader = NULL ); 00101 00102 /** 00103 * Removes the node from the post-processing. If it is not in the post-processing pipeline, nothing happens. 00104 * 00105 * \note this is thread-safe and can be done from every thread 00106 * 00107 * \param node the node to remove 00108 */ 00109 void remove( osg::ref_ptr< osg::Node > node ); 00110 00111 /** 00112 * Removes all associated nodes. 00113 * 00114 * \note this is thread-safe and can be done from every thread 00115 */ 00116 void clear(); 00117 00118 /** 00119 * Activates/Deactivates the post-processing. This is a shortcut for getProperties()->getProperty( "Enable" )->toPropBool()->set( enable ). 00120 * 00121 * \param enable if true, post-processing is active- 00122 */ 00123 void setEnabled( bool enable = true ); 00124 00125 protected: 00126 00127 private: 00128 00129 /** 00130 * This type is used to actually store the association between a node and its associated shader and custom preprocessor. 00131 */ 00132 typedef WSharedAssociativeContainer< 00133 std::map< 00134 osg::ref_ptr< osg::Node >, 00135 std::pair< 00136 WGEShader::RefPtr, 00137 WGEShaderPreprocessor::SPtr 00138 > 00139 > 00140 > NodeShaderAssociation; 00141 00142 /** 00143 * List of nodes and their corresponding shader and preprocessor. 00144 */ 00145 NodeShaderAssociation m_nodeShaderAssociation; 00146 00147 /** 00148 * The actual offscreen render node. 00149 */ 00150 osg::ref_ptr< WGEOffscreenRenderNode > m_offscreen; 00151 00152 /** 00153 * The group of child nodes to post-process. 00154 */ 00155 osg::ref_ptr< WGEGroupNode > m_childs; 00156 00157 /** 00158 * The first pass, rendering. 00159 */ 00160 osg::ref_ptr< WGEOffscreenRenderPass > m_render; 00161 00162 /** 00163 * The actual post-processing. 00164 */ 00165 osg::ref_ptr< WGEOffscreenFinalPass > m_postprocess; 00166 00167 /** 00168 * This shader actually does post-processing in screen space. 00169 */ 00170 WGEShader::RefPtr m_postProcessShader; 00171 00172 /** 00173 * All the properties of the post-processor. 00174 */ 00175 WPropGroup m_properties; 00176 00177 /** 00178 * If true, post-processing is enabled. 00179 */ 00180 WPropBool m_active; 00181 00182 /** 00183 * If true, a HUD with intermediate textures is shown. 00184 */ 00185 WPropBool m_showHUD; 00186 00187 /** 00188 * The property containing the currently active method or a combination. 00189 */ 00190 WPropSelection m_activePostprocessors; 00191 00192 /** 00193 * Possible post-processors. 00194 */ 00195 boost::shared_ptr< WItemSelection > m_possiblePostprocessors; 00196 00197 /** 00198 * Some text denoting that this is not yet completely done. 00199 */ 00200 WPropString m_infoText; 00201 }; 00202 00203 #endif // WGEPOSTPROCESSINGNODE_H 00204