OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreTerrainMaterialGeneratorA.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 
29 #ifndef __Ogre_TerrainMaterialGeneratorA_H__
30 #define __Ogre_TerrainMaterialGeneratorA_H__
31 
34 
35 namespace Ogre
36 {
37  class PSSMShadowCameraSetup;
38 
53  {
54  public:
56  virtual ~TerrainMaterialGeneratorA();
57 
61  {
62  public:
63  SM2Profile(TerrainMaterialGenerator* parent, const String& name, const String& desc);
64  virtual ~SM2Profile();
65  MaterialPtr generate(const Terrain* terrain);
66  MaterialPtr generateForCompositeMap(const Terrain* terrain);
67  uint8 getMaxLayers(const Terrain* terrain) const;
68  void updateParams(const MaterialPtr& mat, const Terrain* terrain);
69  void updateParamsForCompositeMap(const MaterialPtr& mat, const Terrain* terrain);
70  void requestOptions(Terrain* terrain);
71  bool isVertexCompressionSupported() const;
72 
75  bool isLayerNormalMappingEnabled() const { return mLayerNormalMappingEnabled; }
78  void setLayerNormalMappingEnabled(bool enabled);
81  bool isLayerParallaxMappingEnabled() const { return mLayerParallaxMappingEnabled; }
84  void setLayerParallaxMappingEnabled(bool enabled);
87  bool isLayerSpecularMappingEnabled() const { return mLayerSpecularMappingEnabled; }
90  void setLayerSpecularMappingEnabled(bool enabled);
94  bool isGlobalColourMapEnabled() const { return mGlobalColourMapEnabled; }
98  void setGlobalColourMapEnabled(bool enabled);
102  bool isLightmapEnabled() const { return mLightmapEnabled; }
106  void setLightmapEnabled(bool enabled);
110  bool isCompositeMapEnabled() const { return mCompositeMapEnabled; }
114  void setCompositeMapEnabled(bool enabled);
118  bool getReceiveDynamicShadowsEnabled() const { return mReceiveDynamicShadows; }
122  void setReceiveDynamicShadowsEnabled(bool enabled);
123 
127  void setReceiveDynamicShadowsPSSM(PSSMShadowCameraSetup* pssmSettings);
134  void setReceiveDynamicShadowsDepth(bool enabled);
137  bool getReceiveDynamicShadowsDepth() const { return mDepthShadows; }
140  void setReceiveDynamicShadowsLowLod(bool enabled);
143  bool getReceiveDynamicShadowsLowLod() const { return mLowLodShadows; }
144 
146  bool _isSM3Available() const { return mSM3Available; }
147  bool _isSM4Available() const { return mSM4Available; }
148  String _getShaderLanguage() const { return mShaderLanguage; }
149 
150  protected:
152 
154  {
157  RENDER_COMPOSITE_MAP
158  };
159  void addTechnique(const MaterialPtr& mat, const Terrain* terrain, TechniqueType tt);
160 
163  {
164  public:
165  ShaderHelper() : mShadowSamplerStartHi(0), mShadowSamplerStartLo(0) {}
166  virtual ~ShaderHelper() {}
167  virtual HighLevelGpuProgramPtr generateVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
168  virtual HighLevelGpuProgramPtr generateFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
169  virtual void updateParams(const SM2Profile* prof, const MaterialPtr& mat, const Terrain* terrain, bool compositeMap);
170  protected:
171  virtual String getVertexProgramName(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
172  virtual String getFragmentProgramName(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
173  virtual HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt) = 0;
174  virtual HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt) = 0;
175  virtual void generateVertexProgramSource(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
176  virtual void generateFragmentProgramSource(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
177  virtual void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream) = 0;
178  virtual void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream) = 0;
179  virtual void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringStream& outStream) = 0;
180  virtual void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringStream& outStream) = 0;
181  virtual void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream) = 0;
182  virtual void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream) = 0;
183  virtual void defaultVpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const HighLevelGpuProgramPtr& prog);
184  virtual void defaultFpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const HighLevelGpuProgramPtr& prog);
185  virtual void updateVpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const GpuProgramParametersSharedPtr& params);
186  virtual void updateFpParams(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const GpuProgramParametersSharedPtr& params);
187  static String getChannel(uint idx);
188 
191  };
192 
195  {
196  protected:
197  HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
198  HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
199  void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
200  void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
201  void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringStream& outStream);
202  void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringStream& outStream);
203  void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
204  void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
205  uint generateVpDynamicShadowsParams(uint texCoordStart, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
206  void generateVpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
207  void generateFpDynamicShadowsHelpers(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
208  void generateFpDynamicShadowsParams(uint* texCoord, uint* sampler, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
209  void generateFpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
210  };
211 
213  {
214  protected:
215  HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
216  HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
217  void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
218  void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
219  void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringStream& outStream);
220  void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringStream& outStream);
221  void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
222  void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
223  uint generateVpDynamicShadowsParams(uint texCoordStart, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
224  void generateVpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
225  void generateFpDynamicShadowsHelpers(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
226  void generateFpDynamicShadowsParams(uint* texCoord, uint* sampler, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
227  void generateFpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
228  };
229 
232  {
233  protected:
234  HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
235  HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
236  void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
237  void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
238  void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringStream& outStream);
239  void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringStream& outStream);
240  void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
241  void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
242  uint generateVpDynamicShadowsParams(uint texCoordStart, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
243  void generateVpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
244  void generateFpDynamicShadowsHelpers(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
245  void generateFpDynamicShadowsParams(uint* texCoord, uint* sampler, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
246  void generateFpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
247  };
248 
251  {
252  protected:
253  HighLevelGpuProgramPtr createVertexProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
254  HighLevelGpuProgramPtr createFragmentProgram(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt);
255  void generateVpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
256  void generateFpHeader(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
257  void generateVpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringStream& outStream);
258  void generateFpLayer(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, uint layer, StringStream& outStream);
259  void generateVpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
260  void generateFpFooter(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
261  uint generateVpDynamicShadowsParams(uint texCoordStart, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
262  void generateVpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
263  void generateFpDynamicShadowsHelpers(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
264  void generateFpDynamicShadowsParams(uint* texCoord, uint* sampler, const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
265  void generateFpDynamicShadows(const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, StringStream& outStream);
266  };
267 
282 
283  bool isShadowingEnabled(TechniqueType tt, const Terrain* terrain) const;
284  };
285  };
288 }
289 
290 #endif
291 
unsigned char uint8
Definition: OgrePlatform.h:422
bool isCompositeMapEnabled() const
Whether to use the composite map to provide a lower LOD technique in the distance (default true)...
Class that provides functionality to generate materials for use with a terrain.
The main containing class for a chunk of terrain.
Definition: OgreTerrain.h:265
bool isLayerParallaxMappingEnabled() const
Whether to support parallax mapping per layer in the shader (default true).
Utility class to help with generating shaders for GLSL ES.
PSSMShadowCameraSetup * getReceiveDynamicShadowsPSSM() const
Whether to use PSSM support dynamic texture shadows, and if so the settings to use (default 0)...
Interface definition for helper class to generate shaders.
bool getReceiveDynamicShadowsEnabled() const
Whether to support dynamic texture shadows received from other objects, on the terrain (default true)...
_StringStreamBase StringStream
bool getReceiveDynamicShadowsDepth() const
Whether to use depth shadows (default false).
bool isLayerNormalMappingEnabled() const
Whether to support normal mapping per layer in the shader (default true).
Utility class to help with generating shaders for GLSL.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
A TerrainMaterialGenerator which can cope with normal mapped, specular mapped terrain.
bool getReceiveDynamicShadowsLowLod() const
Whether to use shadows on low LOD material rendering (when using composite map) (default false)...
#define _OgreTerrainExport
Parallel Split Shadow Map (PSSM) shadow camera setup.
bool isLayerSpecularMappingEnabled() const
Whether to support specular mapping per layer in the shader (default true).
bool isGlobalColourMapEnabled() const
Whether to support a global colour map over the terrain in the shader, if it's present (default true)...
Utility class to help with generating shaders for Cg / HLSL.
_StringBase String
Definition: OgreCommon.h:53
Inner class which should also be subclassed to provide profile-specific material generation.
bool isLightmapEnabled() const
Whether to support a light map over the terrain in the shader, if it's present (default true)...
unsigned int uint