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-2012 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 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 00150 protected: 00151 00152 enum TechniqueType 00153 { 00154 HIGH_LOD, 00155 LOW_LOD, 00156 RENDER_COMPOSITE_MAP 00157 }; 00158 void addTechnique(const MaterialPtr& mat, const Terrain* terrain, TechniqueType tt); 00159 00161 class _OgreTerrainExport ShaderHelper : public TerrainAlloc 00162 { 00163 public: 00164 ShaderHelper() {} 00165 virtual ~ShaderHelper() {} 00166 virtual HighLevelGpuProgramPtr generateVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt); 00167 virtual HighLevelGpuProgramPtr generateFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt); 00168 virtual void updateParams(const SM2Profile* prof, const MaterialPtr& mat, const Terrain* terrain, bool compositeMap); 00169 protected: 00170 virtual String getVertexProgramName(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt); 00171 virtual String getFragmentProgramName(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt); 00172 virtual HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt) = 0; 00173 virtual HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt) = 0; 00174 virtual void generateVertexProgramSource(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream); 00175 virtual void generateFragmentProgramSource(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream); 00176 virtual void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) = 0; 00177 virtual void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) = 0; 00178 virtual void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream) = 0; 00179 virtual void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream) = 0; 00180 virtual void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) = 0; 00181 virtual void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) = 0; 00182 virtual void defaultVpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const HighLevelGpuProgramPtr& prog); 00183 virtual void defaultFpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const HighLevelGpuProgramPtr& prog); 00184 virtual void updateVpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const GpuProgramParametersSharedPtr& params); 00185 virtual void updateFpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const GpuProgramParametersSharedPtr& params); 00186 static String getChannel(uint idx); 00187 00188 size_t mShadowSamplerStartHi; 00189 size_t mShadowSamplerStartLo; 00190 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 }; 00232 00234 class ShaderHelperGLSLES : public ShaderHelper 00235 { 00236 protected: 00237 HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt); 00238 HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt); 00239 void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) {} 00240 void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) {} 00241 void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream) {} 00242 void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringUtil::StrStreamType& outStream) {} 00243 void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) {} 00244 void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringUtil::StrStreamType& outStream) {} 00245 }; 00246 00247 ShaderHelper* mShaderGen; 00248 bool mLayerNormalMappingEnabled; 00249 bool mLayerParallaxMappingEnabled; 00250 bool mLayerSpecularMappingEnabled; 00251 bool mGlobalColourMapEnabled; 00252 bool mLightmapEnabled; 00253 bool mCompositeMapEnabled; 00254 bool mReceiveDynamicShadows; 00255 PSSMShadowCameraSetup* mPSSM; 00256 bool mDepthShadows; 00257 bool mLowLodShadows; 00258 bool mSM3Available; 00259 bool mSM4Available; 00260 00261 bool isShadowingEnabled(TechniqueType tt, const Terrain* terrain) const; 00262 00263 }; 00264 00265 00266 00267 00268 }; 00269 00270 00271 00276 } 00277 00278 #endif 00279
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:28 2012