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-2013 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 
00053     class _OgreTerrainExport TerrainMaterialGeneratorA : public TerrainMaterialGenerator
00054     {
00055     public:
00056         TerrainMaterialGeneratorA();
00057         virtual ~TerrainMaterialGeneratorA();
00058 
00061         class _OgreTerrainExport SM2Profile : public TerrainMaterialGenerator::Profile
00062         {
00063         public:
00064             SM2Profile(TerrainMaterialGenerator* parent, const String& name, const String& desc);
00065             virtual ~SM2Profile();
00066             MaterialPtr generate(const Terrain* terrain);
00067             MaterialPtr generateForCompositeMap(const Terrain* terrain);
00068             uint8 getMaxLayers(const Terrain* terrain) const;
00069             void updateParams(const MaterialPtr& mat, const Terrain* terrain);
00070             void updateParamsForCompositeMap(const MaterialPtr& mat, const Terrain* terrain);
00071             void requestOptions(Terrain* terrain);
00072             bool isVertexCompressionSupported() const;
00073 
00076             bool isLayerNormalMappingEnabled() const  { return mLayerNormalMappingEnabled; }
00079             void setLayerNormalMappingEnabled(bool enabled);
00082             bool isLayerParallaxMappingEnabled() const  { return mLayerParallaxMappingEnabled; }
00085             void setLayerParallaxMappingEnabled(bool enabled);
00088             bool isLayerSpecularMappingEnabled() const  { return mLayerSpecularMappingEnabled; }
00091             void setLayerSpecularMappingEnabled(bool enabled);
00095             bool isGlobalColourMapEnabled() const  { return mGlobalColourMapEnabled; }
00099             void setGlobalColourMapEnabled(bool enabled);
00103             bool isLightmapEnabled() const  { return mLightmapEnabled; }
00107             void setLightmapEnabled(bool enabled);
00111             bool isCompositeMapEnabled() const  { return mCompositeMapEnabled; }
00115             void setCompositeMapEnabled(bool enabled);
00119             bool getReceiveDynamicShadowsEnabled() const  { return mReceiveDynamicShadows; }
00123             void setReceiveDynamicShadowsEnabled(bool enabled);
00124 
00128             void setReceiveDynamicShadowsPSSM(PSSMShadowCameraSetup* pssmSettings);
00132             PSSMShadowCameraSetup* getReceiveDynamicShadowsPSSM() const { return mPSSM; }
00135             void setReceiveDynamicShadowsDepth(bool enabled);
00138             bool getReceiveDynamicShadowsDepth() const { return mDepthShadows; }
00141             void setReceiveDynamicShadowsLowLod(bool enabled);
00144             bool getReceiveDynamicShadowsLowLod() const { return mLowLodShadows; }
00145 
00147             bool _isSM3Available() const { return mSM3Available; }
00148             bool _isSM4Available() const { return mSM4Available; }
00149             String _getShaderLanguage() const { return mShaderLanguage; }
00150         
00151         protected:
00152 
00153             enum TechniqueType
00154             {
00155                 HIGH_LOD, 
00156                 LOW_LOD, 
00157                 RENDER_COMPOSITE_MAP
00158             };
00159             void addTechnique(const MaterialPtr& mat, const Terrain* terrain, TechniqueType tt);
00160 
00162             class _OgreTerrainExport ShaderHelper : public TerrainAlloc
00163             {
00164             public:
00165                 ShaderHelper() : mShadowSamplerStartHi(0), mShadowSamplerStartLo(0) {}
00166                 virtual ~ShaderHelper() {}
00167                 virtual HighLevelGpuProgramPtr generateVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00168                 virtual HighLevelGpuProgramPtr generateFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00169                 virtual void updateParams(const SM2Profile* prof, const MaterialPtr& mat, const Terrain* terrain, bool compositeMap);
00170             protected:
00171                 virtual String getVertexProgramName(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00172                 virtual String getFragmentProgramName(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00173                 virtual HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt) = 0;
00174                 virtual HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt) = 0;
00175                 virtual void generateVertexProgramSource(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00176                 virtual void generateFragmentProgramSource(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00177                 virtual void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) = 0;
00178                 virtual void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) = 0;
00179                 virtual void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream) = 0;
00180                 virtual void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream) = 0;
00181                 virtual void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) = 0;
00182                 virtual void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) = 0;
00183                 virtual void defaultVpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const HighLevelGpuProgramPtr& prog);
00184                 virtual void defaultFpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const HighLevelGpuProgramPtr& prog);
00185                 virtual void updateVpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const GpuProgramParametersSharedPtr& params);
00186                 virtual void updateFpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const GpuProgramParametersSharedPtr& params);
00187                 static String getChannel(uint idx);
00188 
00189                 size_t mShadowSamplerStartHi;
00190                 size_t mShadowSamplerStartLo;
00191             };
00192 
00194             class _OgreTerrainExport ShaderHelperCg : public ShaderHelper
00195             {
00196             protected:
00197                 HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00198                 HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00199                 void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00200                 void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00201                 void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream);
00202                 void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream);
00203                 void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00204                 void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00205                 uint generateVpDynamicShadowsParams(uint texCoordStart, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00206                 void generateVpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00207                 void generateFpDynamicShadowsHelpers(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00208                 void generateFpDynamicShadowsParams(uint* texCoord, uint* sampler, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00209                 void generateFpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00210             };
00211 
00212             class _OgreTerrainExport ShaderHelperHLSL : public ShaderHelperCg
00213             {
00214             protected:
00215                 HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00216                 HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00217             };
00218 
00220             class _OgreTerrainExport ShaderHelperGLSL : public ShaderHelper
00221             {
00222             protected:
00223                 HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00224                 HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00225                 void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00226                 void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00227                 void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream);
00228                 void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream);
00229                 void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00230                 void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00231                 uint generateVpDynamicShadowsParams(uint texCoordStart, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00232                 void generateVpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00233                 void generateFpDynamicShadowsHelpers(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00234                 void generateFpDynamicShadowsParams(uint* texCoord, uint* sampler, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00235                 void generateFpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00236             };
00237 
00239             class ShaderHelperGLSLES : public ShaderHelper
00240             {
00241             protected:
00242                 HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00243                 HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
00244                 void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00245                 void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00246                 void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream);
00247                 void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream);
00248                 void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00249                 void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00250                 uint generateVpDynamicShadowsParams(uint texCoordStart, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00251                 void generateVpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00252                 void generateFpDynamicShadowsHelpers(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00253                 void generateFpDynamicShadowsParams(uint* texCoord, uint* sampler, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00254                 void generateFpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
00255             };
00256 
00257             ShaderHelper* mShaderGen;
00258             bool mLayerNormalMappingEnabled;
00259             bool mLayerParallaxMappingEnabled;
00260             bool mLayerSpecularMappingEnabled;
00261             bool mGlobalColourMapEnabled;
00262             bool mLightmapEnabled;
00263             bool mCompositeMapEnabled;
00264             bool mReceiveDynamicShadows;
00265             PSSMShadowCameraSetup* mPSSM;
00266             bool mDepthShadows;
00267             bool mLowLodShadows;
00268             bool mSM3Available;
00269             bool mSM4Available;
00270             String mShaderLanguage;
00271 
00272             bool isShadowingEnabled(TechniqueType tt, const Terrain* terrain) const;
00273         };
00274     };
00277 }
00278 
00279 #endif
00280 

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:48