OpenWalnut 1.3.1
|
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 WGEPOSTPROCESSOR_H 00026 #define WGEPOSTPROCESSOR_H 00027 00028 #include <vector> 00029 #include <string> 00030 00031 #include <boost/shared_ptr.hpp> 00032 00033 #include <osg/ref_ptr> 00034 #include <osg/Node> 00035 #include <osg/Camera> 00036 #include <osg/Texture> 00037 00038 #include "../offscreen/WGEOffscreenRenderNode.h" 00039 #include "../offscreen/WGEOffscreenRenderPass.h" 00040 #include "../offscreen/WGEOffscreenFinalPass.h" 00041 00042 #include "../shaders/WGEShaderPropertyDefineOptions.h" 00043 00044 #include "../../common/WProperties.h" 00045 #include "../../common/WPrototyped.h" 00046 00047 00048 00049 /** 00050 * The base class for all custom post-processors. It allows building an own texture processing pipeline for special processings. 00051 */ 00052 class WGEPostprocessor: public WPrototyped 00053 { 00054 public: 00055 /** 00056 * This class encapsulates a G-Buffer. Basically, this is a collection of per-pixel geometry information. 00057 */ 00058 class PostprocessorInput 00059 { 00060 public: 00061 /** 00062 * Constructs an instance from a given list of textures. The order in the list define color, normal, parameter, tangent, depth. There are 00063 * no restrictions to the input list. If textures are missing, the corresponding textures in the GBuffer are missing. 00064 * 00065 * \param from source list 00066 */ 00067 explicit PostprocessorInput( std::vector< osg::ref_ptr< osg::Texture2D > > from ); 00068 00069 /** 00070 * Construct GBuffer with an explicit list of textures. 00071 * 00072 * \param color color texture 00073 * \param normal normal texture 00074 * \param parameter parameter texture 00075 * \param tangent tangent texture 00076 * \param depth depth texture 00077 */ 00078 PostprocessorInput( osg::ref_ptr< osg::Texture2D > color, 00079 osg::ref_ptr< osg::Texture2D > normal, 00080 osg::ref_ptr< osg::Texture2D > parameter, 00081 osg::ref_ptr< osg::Texture2D > tangent, 00082 osg::ref_ptr< osg::Texture2D > depth ); 00083 00084 /** 00085 * Constructor creates empty GBuffer. All textures are un-initialized. 00086 */ 00087 PostprocessorInput(); 00088 00089 /** 00090 * Attaches the needed textures to the specified render pass and returns the G-Buffer 00091 * 00092 * \param from the renderpass to attach this to 00093 * 00094 * \return the buffer. 00095 */ 00096 static PostprocessorInput attach( osg::ref_ptr< WGEOffscreenRenderPass > from ); 00097 00098 /** 00099 * Attaches these textures to the specified renderpass 00100 * 00101 * \param to attach to this 00102 * 00103 * \return the ID of the NEXT free texture unit you can use 00104 */ 00105 size_t bind( osg::ref_ptr< WGEOffscreenRenderPass > to ) const; 00106 00107 /** 00108 * Color in RGBA 00109 */ 00110 osg::ref_ptr< osg::Texture2D > m_colorTexture; 00111 00112 /** 00113 * Normal in RGB 00114 */ 00115 osg::ref_ptr< osg::Texture2D > m_normalTexture; 00116 00117 /** 00118 * Some not yet defined parameter texture, LUMINANCE only 00119 */ 00120 osg::ref_ptr< osg::Texture2D > m_parameterTexture; 00121 00122 /** 00123 * Tangent in RGB 00124 */ 00125 osg::ref_ptr< osg::Texture2D > m_tangentTexture; 00126 00127 /** 00128 * Depth 00129 */ 00130 osg::ref_ptr< osg::Texture2D > m_depthTexture; 00131 }; 00132 00133 /** 00134 * Convenience typedef for an osg::ref_ptr< WGEPostprocessor >. 00135 */ 00136 typedef boost::shared_ptr< WGEPostprocessor > SPtr; 00137 00138 /** 00139 * Convenience typedef for an osg::ref_ptr< const WGEPostprocessor >. 00140 */ 00141 typedef boost::shared_ptr< const WGEPostprocessor > ConstSPtr; 00142 00143 /** 00144 * Type used for returning lists of postprocessor prototypes. 00145 */ 00146 typedef std::vector< WGEPostprocessor::SPtr > ProcessorList; 00147 00148 /** 00149 * Returns a list of all known postprocessor prototypes 00150 * 00151 * \return the list 00152 */ 00153 static ProcessorList getPostprocessors(); 00154 00155 /** 00156 * Create named prototype. You should call this in your prototype constructor. 00157 * 00158 * \param name name of processor 00159 * \param description description. 00160 */ 00161 WGEPostprocessor( std::string name, std::string description ); 00162 00163 /** 00164 * Destructor. 00165 */ 00166 virtual ~WGEPostprocessor(); 00167 00168 /** 00169 * Create instance. Uses the protected constructor. Implement it if you derive from this class! This is called whenever your postprocessor is 00170 * applied to the standard render-output. You can add your own constructors and creators for other cases. 00171 * 00172 * \param offscreen use this offscreen node to add your texture pass' 00173 * \param gbuffer the input textures you should use 00174 * \returns shared pointer to the created instance 00175 */ 00176 virtual SPtr create( osg::ref_ptr< WGEOffscreenRenderNode > offscreen, const PostprocessorInput& gbuffer ) const = 0; 00177 00178 /** 00179 * Returns the set of properties controlling the post-processing node. You can use them to provide them to the user for example. 00180 * 00181 * \return the properties as a group. 00182 */ 00183 virtual WPropGroup getProperties() const; 00184 00185 /** 00186 * Returns the result texture. Use this to continue processing. 00187 * 00188 * \param idx which output. Each postprocessor returns at least one texture in index 0, which also is the default value 00189 * 00190 * \return the result texture 00191 */ 00192 virtual osg::ref_ptr< osg::Texture2D > getOutput( size_t idx = 0 ) const; 00193 00194 /** 00195 * This processor can produce multiple outputs. Grab them here. This vector always contains at least the first filtered texture in unit 0. 00196 * 00197 * \return the vector as copy. 00198 */ 00199 const std::vector< osg::ref_ptr< osg::Texture2D > >& getOutputList() const; 00200 00201 /** 00202 * Returns the new depth texture. Allows you to modify the depth values. By default, this is NULL. Check this! 00203 * 00204 * \return the depth texture 00205 */ 00206 virtual osg::ref_ptr< osg::Texture2D > getDepth() const; 00207 00208 /** 00209 * Gets the name of this postprocessor. 00210 * 00211 * \return the name. 00212 */ 00213 virtual const std::string getName() const; 00214 00215 /** 00216 * Gets the description for this postprocessor 00217 * 00218 * \return the description 00219 */ 00220 virtual const std::string getDescription() const; 00221 protected: 00222 /** 00223 * The textures contain the result. Add at least one result texture 00224 */ 00225 std::vector< osg::ref_ptr< osg::Texture2D > > m_resultTextures; 00226 00227 /** 00228 * The texture contains the new depth 00229 */ 00230 osg::ref_ptr< osg::Texture2D > m_depthTexture; 00231 00232 /** 00233 * All the properties of the post-processor. 00234 */ 00235 WPropGroup m_properties; 00236 00237 /** 00238 * A flag denoting whether the effect should be combined with color or not. 00239 */ 00240 WPropBool m_effectOnly; 00241 00242 /** 00243 * For convenience, this is a shader preprocessor controlled by m_effectOnly property. 00244 */ 00245 WGEShaderPreprocessor::SPtr m_effectOnlyPreprocessor; 00246 private: 00247 /** 00248 * Name string. Set by the constructor. 00249 */ 00250 std::string m_name; 00251 00252 /** 00253 * Description string. Set by the constructor. 00254 */ 00255 std::string m_description; 00256 }; 00257 00258 #endif // WGEPOSTPROCESSOR_H 00259