OgreTerrainMaterialGeneratorA.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004 (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2009 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 
00029 #ifndef __Ogre_TerrainMaterialGeneratorA_H__
00030 #define __Ogre_TerrainMaterialGeneratorA_H__
00031 
00032 #include "OgreTerrainPrerequisites.h"
00033 #include "OgreTerrainMaterialGenerator.h"
00034 #include "OgreGpuProgramParams.h"
00035 
00036 namespace Ogre
00037 {
00038     class PSSMShadowCameraSetup;
00039 
00052     class _OgreTerrainExport TerrainMaterialGeneratorA : public TerrainMaterialGenerator
00053     {
00054     public:
00055         TerrainMaterialGeneratorA();
00056         ~TerrainMaterialGeneratorA();
00057 
00060         class _OgreTerrainExport SM2Profile : public TerrainMaterialGenerator::Profile
00061         {
00062         public:
00063             SM2Profile(TerrainMaterialGenerator* parent, const String& name, const String& desc);
00064             ~SM2Profile();
00065             MaterialPtr generate(const Terrain* terrain);
00066             MaterialPtr generateForCompositeMap(const Terrain* terrain);
00067             uint8 getMaxLayers(const Terrain* terrain) const;
00068             void updateParams(const MaterialPtr& mat, const Terrain* terrain);
00069             void updateParamsForCompositeMap(const MaterialPtr& mat, const Terrain* terrain);
00070             void requestOptions(Terrain* terrain);
00071 
00074             bool isLayerNormalMappingEnabled() const  { return mLayerNormalMappingEnabled; }
00077             void setLayerNormalMappingEnabled(bool enabled);
00080             bool isLayerParallaxMappingEnabled() const  { return mLayerParallaxMappingEnabled; }
00083             void setLayerParallaxMappingEnabled(bool enabled);
00086             bool isLayerSpecularMappingEnabled() const  { return mLayerSpecularMappingEnabled; }
00089             void setLayerSpecularMappingEnabled(bool enabled);
00093             bool isGlobalColourMapEnabled() const  { return mGlobalColourMapEnabled; }
00097             void setGlobalColourMapEnabled(bool enabled);
00101             bool isLightmapEnabled() const  { return mLightmapEnabled; }
00105             void setLightmapEnabled(bool enabled);
00109             bool isCompositeMapEnabled() const  { return mCompositeMapEnabled; }
00113             void setCompositeMapEnabled(bool enabled);
00117             bool getReceiveDynamicShadowsEnabled() const  { return mReceiveDynamicShadows; }
00121             void setReceiveDynamicShadowsEnabled(bool enabled);
00122 
00126             void setReceiveDynamicShadowsPSSM(PSSMShadowCameraSetup* pssmSettings);
00130             PSSMShadowCameraSetup* getReceiveDynamicShadowsPSSM() const { return mPSSM; }
00133             void setReceiveDynamicShadowsDepth(bool enabled);
00136             bool getReceiveDynamicShadowsDepth() const { return mDepthShadows; }
00139             void setReceiveDynamicShadowsLowLod(bool enabled);
00142             bool getReceiveDynamicShadowsLowLod() const { return mLowLodShadows; }
00143 
00145             bool _isSM3Available() const { return mSM3Available; }
00146         
00147         protected:
00148 
00149             enum TechniqueType
00150             {
00151                 HIGH_LOD, 
00152                 LOW_LOD, 
00153                 RENDER_COMPOSITE_MAP
00154             };
00155             void addTechnique(const MaterialPtr& mat, const Terrain* terrain, TechniqueType tt);
00156 
00158             class _OgreTerrainExport ShaderHelper : public TerrainAlloc
00159             {
00160             public:
00161                 ShaderHelper() {}
00162                 virtual ~ShaderHelper() {}
00163                 virtual HighLevelGpuProgramPtr generateVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00164                 virtual HighLevelGpuProgramPtr generateFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00165                 virtual void updateParams(const SM2Profile* prof, const MaterialPtr& mat, const Terrain* terrain, bool compositeMap);
00166             protected:
00167                 virtual String getVertexProgramName(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00168                 virtual String getFragmentProgramName(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00169                 virtual HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt) = 0;
00170                 virtual HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt) = 0;
00171                 virtual void generateVertexProgramSource(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00172                 virtual void generateFragmentProgramSource(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00173                 virtual void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) = 0;
00174                 virtual void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) = 0;
00175                 virtual void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream) = 0;
00176                 virtual void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream) = 0;
00177                 virtual void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) = 0;
00178                 virtual void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) = 0;
00179                 virtual void defaultVpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const HighLevelGpuProgramPtr& prog);
00180                 virtual void defaultFpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const HighLevelGpuProgramPtr& prog);
00181                 virtual void updateVpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const GpuProgramParametersSharedPtr& params);
00182                 virtual void updateFpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const GpuProgramParametersSharedPtr& params);
00183                 static String getChannel(uint idx);
00184 
00185                 size_t mShadowSamplerStartHi;
00186                 size_t mShadowSamplerStartLo;
00187 
00188             };
00189 
00191             class _OgreTerrainExport ShaderHelperCg : public ShaderHelper
00192             {
00193             protected:
00194                 HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00195                 HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00196                 void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00197                 void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00198                 void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream);
00199                 void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream);
00200                 void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00201                 void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00202                 uint generateVpDynamicShadowsParams(uint texCoordStart, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00203                 void generateVpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00204                 void generateFpDynamicShadowsHelpers(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00205                 void generateFpDynamicShadowsParams(uint* texCoord, uint* sampler, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00206                 void generateFpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00207             };
00208 
00209             class _OgreTerrainExport ShaderHelperHLSL : public ShaderHelperCg
00210             {
00211             protected:
00212                 HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00213                 HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00214             };
00215 
00217             class _OgreTerrainExport ShaderHelperGLSL : public ShaderHelper
00218             {
00219             protected:
00220                 HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00221                 HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00222                 void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) {}
00223                 void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) {}
00224                 void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream) {}
00225                 void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream) {}
00226                 void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) {}
00227                 void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) {}
00228             };
00229 
00230             ShaderHelper* mShaderGen;
00231             bool mLayerNormalMappingEnabled;
00232             bool mLayerParallaxMappingEnabled;
00233             bool mLayerSpecularMappingEnabled;
00234             bool mGlobalColourMapEnabled;
00235             bool mLightmapEnabled;
00236             bool mCompositeMapEnabled;
00237             bool mReceiveDynamicShadows;
00238             PSSMShadowCameraSetup* mPSSM;
00239             bool mDepthShadows;
00240             bool mLowLodShadows;
00241             bool mSM3Available;
00242 
00243             bool isShadowingEnabled(TechniqueType tt, const Terrain* terrain) const;
00244 
00245         };
00246 
00247 
00248 
00249 
00250     };
00251 
00252 
00253 
00258 }
00259 
00260 #endif
00261 

Copyright © 2008 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Feb 28 21:10:44 2010