# 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
    00053     class _OgreTerrainExport TerrainMaterialGeneratorA : public TerrainMaterialGenerator
    00054     {
    00055     public:
    00056         TerrainMaterialGeneratorA();
    00057         ~TerrainMaterialGeneratorA();
    00058
    00061         class _OgreTerrainExport SM2Profile : public TerrainMaterialGenerator::Profile
    00062         {
    00063         public:
    00064             SM2Profile(TerrainMaterialGenerator* parent, const String& name, const String& desc);
    00065             ~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
    00075             bool isLayerNormalMappingEnabled() const  { return mLayerNormalMappingEnabled; }
    00078             void setLayerNormalMappingEnabled(bool enabled);
    00081             bool isLayerParallaxMappingEnabled() const  { return mLayerParallaxMappingEnabled; }
    00084             void setLayerParallaxMappingEnabled(bool enabled);
    00087             bool isLayerSpecularMappingEnabled() const  { return mLayerSpecularMappingEnabled; }
    00090             void setLayerSpecularMappingEnabled(bool enabled);
    00094             bool isGlobalColourMapEnabled() const  { return mGlobalColourMapEnabled; }
    00098             void setGlobalColourMapEnabled(bool enabled);
    00102             bool isLightmapEnabled() const  { return mLightmapEnabled; }
    00106             void setLightmapEnabled(bool enabled);
    00110             bool isCompositeMapEnabled() const  { return mCompositeMapEnabled; }
    00114             void setCompositeMapEnabled(bool enabled);
    00118             bool getReceiveDynamicShadowsEnabled() const  { return mReceiveDynamicShadows; }
    00122             void setReceiveDynamicShadowsEnabled(bool enabled);
    00123
    00127             void setReceiveDynamicShadowsPSSM(PSSMShadowCameraSetup* pssmSettings);
    00131             PSSMShadowCameraSetup* getReceiveDynamicShadowsPSSM() const { return mPSSM; }
    00134             void setReceiveDynamicShadowsDepth(bool enabled);
    00137             bool getReceiveDynamicShadowsDepth() const { return mDepthShadows; }
    00140             void setReceiveDynamicShadowsLowLod(bool enabled);
    00143             bool getReceiveDynamicShadowsLowLod() const { return mLowLodShadows; }
    00144
    00146             bool _isSM3Available() const { return mSM3Available; }
    00147
    00148         protected:
    00149
    00150             enum TechniqueType
    00151             {
    00152                 HIGH_LOD,
    00153                 LOW_LOD,
    00154                 RENDER_COMPOSITE_MAP
    00155             };
    00156             void addTechnique(const MaterialPtr& mat, const Terrain* terrain, TechniqueType tt);
    00157
    00159             class _OgreTerrainExport ShaderHelper : public TerrainAlloc
    00160             {
    00161             public:
    00162                 ShaderHelper() {}
    00163                 virtual ~ShaderHelper() {}
    00164                 virtual HighLevelGpuProgramPtr generateVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
    00165                 virtual HighLevelGpuProgramPtr generateFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
    00166                 virtual void updateParams(const SM2Profile* prof, const MaterialPtr& mat, const Terrain* terrain, bool compositeMap);
    00167             protected:
    00168                 virtual String getVertexProgramName(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
    00169                 virtual String getFragmentProgramName(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
    00170                 virtual HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt) = 0;
    00171                 virtual HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt) = 0;
    00172                 virtual void generateVertexProgramSource(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
    00173                 virtual void generateFragmentProgramSource(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
    00174                 virtual void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) = 0;
    00175                 virtual void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) = 0;
    00176                 virtual void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream) = 0;
    00177                 virtual void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream) = 0;
    00178                 virtual void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) = 0;
    00179                 virtual void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) = 0;
    00180                 virtual void defaultVpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const HighLevelGpuProgramPtr& prog);
    00181                 virtual void defaultFpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const HighLevelGpuProgramPtr& prog);
    00182                 virtual void updateVpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const GpuProgramParametersSharedPtr& params);
    00183                 virtual void updateFpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const GpuProgramParametersSharedPtr& params);
    00184                 static String getChannel(uint idx);
    00185
    00186                 size_t mShadowSamplerStartHi;
    00187                 size_t mShadowSamplerStartLo;
    00188
    00189             };
    00190
    00192             class _OgreTerrainExport ShaderHelperCg : public ShaderHelper
    00193             {
    00194             protected:
    00195                 HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
    00196                 HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
    00197                 void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
    00198                 void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
    00199                 void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream);
    00200                 void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream);
    00201                 void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
    00202                 void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
    00203                 uint generateVpDynamicShadowsParams(uint texCoordStart, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
    00204                 void generateVpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
    00205                 void generateFpDynamicShadowsHelpers(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
    00206                 void generateFpDynamicShadowsParams(uint* texCoord, uint* sampler, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
    00207                 void generateFpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream);
    00208             };
    00209
    00210             class _OgreTerrainExport ShaderHelperHLSL : public ShaderHelperCg
    00211             {
    00212             protected:
    00213                 HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
    00214                 HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
    00215             };
    00216
    00218             class _OgreTerrainExport ShaderHelperGLSL : public ShaderHelper
    00219             {
    00220             protected:
    00221                 HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
    00222                 HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
    00223                 void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) {}
    00224                 void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) {}
    00225                 void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream) {}
    00226                 void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream) {}
    00227                 void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) {}
    00228                 void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) {}
    00229             };
    00230
    00231             ShaderHelper* mShaderGen;
    00232             bool mLayerNormalMappingEnabled;
    00233             bool mLayerParallaxMappingEnabled;
    00234             bool mLayerSpecularMappingEnabled;
    00235             bool mGlobalColourMapEnabled;
    00236             bool mLightmapEnabled;
    00237             bool mCompositeMapEnabled;
    00238             bool mReceiveDynamicShadows;
    00239             PSSMShadowCameraSetup* mPSSM;
    00240             bool mDepthShadows;
    00241             bool mLowLodShadows;
    00242             bool mSM3Available;
    00243
    00244             bool isShadowingEnabled(TechniqueType tt, const Terrain* terrain) const;
    00245
    00246         };
    00247
    00248
    00249
    00250
    00251     };
    00252
    00253
    00254
    00259 }
    00260
    00261 #endif
    00262

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun May 8 2011 20:28:09