OpenWalnut
1.4.0
|
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 "../WGECamera.h" 00044 00045 #include "WGEPostprocessor.h" 00046 00047 /** 00048 * 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. 00049 * You need some special parts in it. Please see the all-in-one super-shader-example module WMShaderExample in modules/template. 00050 * 00051 * \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 00052 * might be useful for those who want to modify the post-processing pipeline. 00053 */ 00054 class WGEPostprocessingNode: public osg::Switch // NOLINT 00055 { 00056 public: 00057 /** 00058 * Convenience typedef for an osg::ref_ptr 00059 */ 00060 typedef osg::ref_ptr< WGEPostprocessingNode > RefPtr; 00061 00062 /** 00063 * Convenience typedef for an osg::ref_ptr; const 00064 */ 00065 typedef osg::ref_ptr< const WGEPostprocessingNode > ConstRefPtr; 00066 00067 /** 00068 * Create a new post-processing node. It uses the WGEOffscreenRenderNode to setup an offscreen, shader-based post-processing for rendered 00069 * images. This is not limited to geometry but can also be used for ray-traced images. 00070 * 00071 * \note The width and hight define the offscreen texture size. The viewport if each rendering is automatically set to the one of the 00072 * reference camera. This means, width and height only define the maximal supported resolution without upscaling of your postprocessor. 00073 * 00074 * \param reference camera used as reference 00075 * \param width the width of the textures used in this rendering. Must be in [8,4096] and a power of two. 00076 * \param height the height of the textures used in this rendering. Must be in [8,4096] and a power of two. 00077 * \param noHud If true, no hud gets displayed showing the created and used textures. 00078 */ 00079 WGEPostprocessingNode( osg::ref_ptr< WGECamera > reference, size_t width = 2048, size_t height = 2048, bool noHud = false ); 00080 00081 /** 00082 * Destructor. 00083 */ 00084 virtual ~WGEPostprocessingNode(); 00085 00086 /** 00087 * Returns the set of properties controlling the post-processing node. You can use them to provide them to the user for example. 00088 * 00089 * \return the properties as a group. 00090 */ 00091 WPropGroup getProperties() const; 00092 00093 /** 00094 * Inserts a node to the post-processor and injects the needed code to the specified shader. See class documentation for further details on 00095 * 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! 00096 * If not, post-processing will not work properly. 00097 * 00098 * \note this is thread-safe and can be done from every thread 00099 * \note it does NOT apply the shader. 00100 * 00101 * \param node the node to post-process 00102 * \param shader the shader used for the node 00103 */ 00104 void insert( osg::ref_ptr< osg::Node > node, WGEShader::RefPtr shader = NULL ); 00105 00106 /** 00107 * Removes the node from the post-processing. If it is not in the post-processing pipeline, nothing happens. 00108 * 00109 * \note this is thread-safe and can be done from every thread 00110 * 00111 * \param node the node to remove 00112 */ 00113 void remove( osg::ref_ptr< osg::Node > node ); 00114 00115 /** 00116 * Removes all associated nodes. 00117 * 00118 * \note this is thread-safe and can be done from every thread 00119 */ 00120 void clear(); 00121 00122 /** 00123 * The post processor currently in use. 00124 * 00125 * \return the current post processor 00126 */ 00127 WGEPostprocessor::SPtr getCurrentPostprocessor() const; 00128 protected: 00129 private: 00130 /** 00131 * This type is used to actually store the association between a node and its associated shader and custom preprocessor. 00132 */ 00133 typedef WSharedAssociativeContainer< 00134 std::map< 00135 osg::ref_ptr< osg::Node >, 00136 std::pair< 00137 WGEShader::RefPtr, 00138 WGEShaderPreprocessor::SPtr 00139 > 00140 > 00141 > NodeShaderAssociation; 00142 00143 /** 00144 * List of nodes and their corresponding shader and preprocessor. 00145 */ 00146 NodeShaderAssociation m_nodeShaderAssociation; 00147 00148 /** 00149 * The group of child nodes to post-process. 00150 */ 00151 osg::ref_ptr< WGEGroupNode > m_childs; 00152 00153 /** 00154 * All the properties of the post-processor. 00155 */ 00156 WPropGroup m_properties; 00157 00158 /** 00159 * If true, post-processing is enabled. 00160 */ 00161 WPropBool m_active; 00162 00163 /** 00164 * Activate to show the texture HUDs 00165 */ 00166 WPropBool m_showHud; 00167 00168 /** 00169 * The property containing the currently active method or a combination. 00170 */ 00171 WPropSelection m_activePostprocessor; 00172 00173 /** 00174 * The postprocessors. 00175 */ 00176 WGEPostprocessor::ProcessorList m_postprocs; 00177 00178 /** 00179 * Callback for changes in m_activePostprocessor. 00180 */ 00181 void postprocessorSelected(); 00182 }; 00183 00184 #endif // WGEPOSTPROCESSINGNODE_H 00185