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 #include <string> 00026 #include <vector> 00027 00028 #include "WGEPostprocessorEdgeEnhance.h" 00029 #include "WGEPostprocessorCelShading.h" 00030 #include "WGEPostprocessorGauss.h" 00031 #include "WGEPostprocessorSSAO.h" 00032 #include "WGEPostprocessorLineAO.h" 00033 00034 #include "WGEPostprocessor.h" 00035 00036 WGEPostprocessor::WGEPostprocessor( std::string name, std::string description ): 00037 WPrototyped(), 00038 m_resultTextures(), 00039 m_depthTexture(), 00040 m_properties( boost::shared_ptr< WProperties >( new WProperties( "Settings for " + name, "Post-processing properties" ) ) ), 00041 m_name( name ), 00042 m_description( description ) 00043 { 00044 // there is always one property: 00045 m_effectOnly = m_properties->addProperty( "Effect Only", "If active, the plain effect will be shown instead a combination of effect " 00046 "and color. This settings does not affect all postprocessors.", false ); 00047 00048 // for convenience, also create a preprocessor for this property 00049 m_effectOnlyPreprocessor = WGEShaderPreprocessor::SPtr( new WGEShaderPropertyDefineOptions< WPropBool >( m_effectOnly, 00050 "WGE_POSTPROCESSOR_OUTPUT_COMBINE", "WGE_POSTPROCESSOR_OUTPUT_EFFECT_ONLY" ) ); 00051 } 00052 00053 WGEPostprocessor::~WGEPostprocessor() 00054 { 00055 // cleanup 00056 } 00057 00058 WPropGroup WGEPostprocessor::getProperties() const 00059 { 00060 return m_properties; 00061 } 00062 00063 osg::ref_ptr< osg::Texture2D > WGEPostprocessor::getOutput( size_t idx ) const 00064 { 00065 return m_resultTextures[ idx ]; 00066 } 00067 00068 const std::vector< osg::ref_ptr< osg::Texture2D > >& WGEPostprocessor::getOutputList() const 00069 { 00070 return m_resultTextures; 00071 } 00072 00073 osg::ref_ptr< osg::Texture2D > WGEPostprocessor::getDepth() const 00074 { 00075 return m_depthTexture; 00076 } 00077 00078 WGEPostprocessor::PostprocessorInput::PostprocessorInput() 00079 { 00080 // leave them uni-initialized 00081 } 00082 00083 WGEPostprocessor::PostprocessorInput::PostprocessorInput( std::vector< osg::ref_ptr< osg::Texture2D > > from ) 00084 { 00085 if( from.size() > 0 ) 00086 { 00087 m_colorTexture = from[0]; 00088 } 00089 if( from.size() > 1 ) 00090 { 00091 m_normalTexture = from[1]; 00092 } 00093 if( from.size() > 2 ) 00094 { 00095 m_parameterTexture = from[2]; 00096 } 00097 if( from.size() > 3 ) 00098 { 00099 m_tangentTexture = from[3]; 00100 } 00101 if( from.size() > 4 ) 00102 { 00103 m_depthTexture = from[4]; 00104 } 00105 } 00106 WGEPostprocessor::PostprocessorInput::PostprocessorInput( osg::ref_ptr< osg::Texture2D > color, 00107 osg::ref_ptr< osg::Texture2D > normal, 00108 osg::ref_ptr< osg::Texture2D > parameter, 00109 osg::ref_ptr< osg::Texture2D > tangent, 00110 osg::ref_ptr< osg::Texture2D > depth ): 00111 m_colorTexture( color ), 00112 m_normalTexture( normal ), 00113 m_parameterTexture( parameter ), 00114 m_tangentTexture( tangent ), 00115 m_depthTexture( depth ) 00116 { 00117 } 00118 00119 WGEPostprocessor::PostprocessorInput WGEPostprocessor::PostprocessorInput::attach( osg::ref_ptr< WGEOffscreenRenderPass > from ) 00120 { 00121 PostprocessorInput buf; 00122 buf.m_colorTexture = from->attach( osg::Camera::COLOR_BUFFER0 ); 00123 buf.m_normalTexture = from->attach( osg::Camera::COLOR_BUFFER1, GL_RGB ); 00124 buf.m_parameterTexture = from->attach( osg::Camera::COLOR_BUFFER2, GL_LUMINANCE ); 00125 buf.m_tangentTexture = from->attach( osg::Camera::COLOR_BUFFER3, GL_RGB ); 00126 buf.m_depthTexture = from->attach( osg::Camera::DEPTH_BUFFER ); 00127 00128 return buf; 00129 } 00130 00131 size_t WGEPostprocessor::PostprocessorInput::bind( osg::ref_ptr< WGEOffscreenRenderPass > to ) const 00132 { 00133 to->bind( m_colorTexture, 0 ); 00134 to->bind( m_normalTexture, 1 ); 00135 to->bind( m_parameterTexture, 2 ); 00136 to->bind( m_depthTexture, 3 ); 00137 to->bind( m_tangentTexture, 4 ); 00138 00139 return 5; 00140 } 00141 00142 WGEPostprocessor::ProcessorList WGEPostprocessor::getPostprocessors() 00143 { 00144 WGEPostprocessor::ProcessorList postprocs; 00145 00146 // create prototypes of the postprocessors OW knows about 00147 postprocs.push_back( WGEPostprocessor::SPtr( new WGEPostprocessorEdgeEnhance() ) ); 00148 postprocs.push_back( WGEPostprocessor::SPtr( new WGEPostprocessorCelShading() ) ); 00149 postprocs.push_back( WGEPostprocessor::SPtr( new WGEPostprocessorGauss() ) ); 00150 postprocs.push_back( WGEPostprocessor::SPtr( new WGEPostprocessorSSAO() ) ); 00151 postprocs.push_back( WGEPostprocessor::SPtr( new WGEPostprocessorLineAO() ) ); 00152 return postprocs; 00153 } 00154 00155 const std::string WGEPostprocessor::getName() const 00156 { 00157 return m_name; 00158 } 00159 00160 const std::string WGEPostprocessor::getDescription() const 00161 { 00162 return m_description; 00163 } 00164