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 #include <osg/Camera> 00026 00027 #include "../shaders/WGEPropertyUniform.h" 00028 #include "../shaders/WGEShaderPropertyDefineOptions.h" 00029 00030 #include "WGEPostprocessorGauss.h" 00031 00032 WGEPostprocessorGauss::WGEPostprocessorGauss(): 00033 WGEPostprocessor( "Gauss Filtering", 00034 "Gauss filter all specified input textures." ) 00035 { 00036 } 00037 00038 WGEPostprocessorGauss::WGEPostprocessorGauss( osg::ref_ptr< WGEOffscreenRenderNode > offscreen, 00039 osg::ref_ptr< osg::Texture2D > tex0, 00040 osg::ref_ptr< osg::Texture2D > tex1, 00041 osg::ref_ptr< osg::Texture2D > tex2, 00042 osg::ref_ptr< osg::Texture2D > tex3, 00043 osg::ref_ptr< osg::Texture2D > tex4, 00044 osg::ref_ptr< osg::Texture2D > tex5, 00045 osg::ref_ptr< osg::Texture2D > tex6, 00046 osg::ref_ptr< osg::Texture2D > tex7 ): 00047 WGEPostprocessor( "Gauss Filtering", 00048 "Gauss filter all specified input textures." ) 00049 { 00050 // Use the standard postprocessor uber-shader 00051 WGEShader::RefPtr s = new WGEShader( "WGEPostprocessor" ); 00052 s->setDefine( "WGE_POSTPROCESSOR_GAUSS" ); 00053 00054 // also add the m_effectOnly property as shader preprocessor 00055 s->addPreprocessor( m_effectOnlyPreprocessor ); 00056 00057 // create the rendering pass 00058 osg::ref_ptr< WGEOffscreenTexturePass > pass = offscreen->addTextureProcessingPass( s, "Gauss Filter" ); 00059 00060 // for each of the textures do: 00061 00062 // attach color0 output and bind tex0 00063 m_resultTextures.push_back( pass->attach( WGECamera::COLOR_BUFFER0, GL_RGBA ) ); 00064 pass->bind( tex0, 0 ); 00065 s->setDefine( "WGE_POSTPROCESSOR_GAUSS_UNIT0" ); 00066 00067 // attach color1 output and bind tex1 00068 if( tex1 ) 00069 { 00070 m_resultTextures.push_back( pass->attach( WGECamera::COLOR_BUFFER1, GL_RGBA ) ); 00071 pass->bind( tex1, 1 ); 00072 s->setDefine( "WGE_POSTPROCESSOR_GAUSS_UNIT1" ); 00073 } 00074 // attach color2 output and bind tex2 00075 if( tex2 ) 00076 { 00077 m_resultTextures.push_back( pass->attach( WGECamera::COLOR_BUFFER2, GL_RGBA ) ); 00078 pass->bind( tex2, 2 ); 00079 s->setDefine( "WGE_POSTPROCESSOR_GAUSS_UNIT2" ); 00080 } 00081 // attach color3 output and bind tex3 00082 if( tex3 ) 00083 { 00084 m_resultTextures.push_back( pass->attach( WGECamera::COLOR_BUFFER3, GL_RGBA ) ); 00085 pass->bind( tex3, 3 ); 00086 s->setDefine( "WGE_POSTPROCESSOR_GAUSS_UNIT3" ); 00087 } 00088 // attach color4 output and bind tex4 00089 if( tex4 ) 00090 { 00091 m_resultTextures.push_back( pass->attach( WGECamera::COLOR_BUFFER4, GL_RGBA ) ); 00092 pass->bind( tex4, 4 ); 00093 s->setDefine( "WGE_POSTPROCESSOR_GAUSS_UNIT4" ); 00094 } 00095 // attach color5 output and bind tex5 00096 if( tex5 ) 00097 { 00098 m_resultTextures.push_back( pass->attach( WGECamera::COLOR_BUFFER5, GL_RGBA ) ); 00099 pass->bind( tex5, 5 ); 00100 s->setDefine( "WGE_POSTPROCESSOR_GAUSS_UNIT5" ); 00101 } 00102 // attach color6 output and bind tex6 00103 if( tex6 ) 00104 { 00105 m_resultTextures.push_back( pass->attach( WGECamera::COLOR_BUFFER6, GL_RGBA ) ); 00106 pass->bind( tex6, 6 ); 00107 s->setDefine( "WGE_POSTPROCESSOR_GAUSS_UNIT6" ); 00108 } 00109 // attach color7 output and bind tex7 00110 if( tex7 ) 00111 { 00112 m_resultTextures.push_back( pass->attach( WGECamera::COLOR_BUFFER7, GL_RGBA ) ); 00113 pass->bind( tex7, 7 ); 00114 s->setDefine( "WGE_POSTPROCESSOR_GAUSS_UNIT7" ); 00115 } 00116 } 00117 00118 WGEPostprocessorGauss::~WGEPostprocessorGauss() 00119 { 00120 // cleanup 00121 } 00122 00123 WGEPostprocessor::SPtr WGEPostprocessorGauss::create( osg::ref_ptr< WGEOffscreenRenderNode > offscreen, 00124 const WGEPostprocessor::PostprocessorInput& gbuffer ) const 00125 { 00126 return WGEPostprocessor::SPtr( new WGEPostprocessorGauss( offscreen, gbuffer.m_colorTexture ) ); 00127 } 00128