Here is some information about the Terrain Scene Manager. 

**Note: The scene manager will work up to Ogre 1.7.** Ogre 1.8 and newer versions won't support this scene manager, because of the new Ogre Terrain System with many improvements (which released with Ogre 1.7). 

### Table of contents

    * Configuration Parameters
      * Basic Configuration Parameters
      * Advanced Configuration Parameters
      * More Advanced Parameters
    * Using Custom Materials
    * Dirty notes



The shape and coloration of the terrain in your scene is computed from a _heightmap_ , a _terrain texture_ _detail texture_. The heightmap is a simple greyscale image in which each pixel represents a height value, where 0 is ground level and 255 (resp. 65535 at 16 bit) represents the highest point in your terrain. The samples include a heightmap called  which you can use for experimentation. 

The terrain is textured with an image that is stretched over the terrain. These _terrain textures_ are typically mottled brown, green, white or grey for earth, grass, snow or rock terrain. Since terrain textures are normally much smaller than the terrain being covered, terrain normally appears blurred when viewed close up. To help with this, a _detail texture_ is used, which is blended with the terrain texture when viewed from close distances. The detail texture is not stretched as much as the terrain texture, removing the blurriness of terrains viewed close up. The samples include textures called _terrain_texture.jpg_ and _terrain_detail.jpg_ which you can use for experimentation. 

Terrains are divided into a grid of _terrain tiles_. Terrain tiles may be displayed by the scene manager at a differing level of detail, depending on the topology of the tile and the distance from the viewer. 

The entire terrain is projected within a world coordinate space which specifies the dimensions of the terrain in 3-space. 

The -LOD calculation for the Terrain Scene Manager is based on this paper. 

Terrain Scene Manager uses GeoMipmapping-LOD of the terrain chunks are chosen based on camera distance, and they are organised and culled inside an Octree (since the TerrainSceneManager builds on the OctreeSceneManager). 

##  Configuration Parameters

The Terrain Scene Manager is configured via the _terrain.cfg_ script. 

###  Basic Configuration Parameters

  
The basic parameters from this script are: 

  * __WorldTexture''': Specifies the name of the terrain texture. 
  * DetailTexture: Specifies the name of the detail texture. 
  * **DetailTile** : This specifies the number of times that the detail texture will be repeated in each terrain tile. I.e., if the value is n, the detail texture will be displayed in an _n_ x _n_ grid within each terrain tile. Setting this can involve some experimentation. If this number is low, the terrain may appear blurry at close distances. If this number is high, the terrain may appear to have repeating patterns when viewed over a distance. 
  * PageSource: Specifies the source of the heightmap. By default, Heightmap. 
  * Heightmap.image: The image file from which the heightmap is drawn. Thus must be a square where each dimension is of size 2^n+1, for some integer . The larger the size of the heightmap, the more detail the terrain will have, but the more resources your application will consume (including longer application start time.) 8 bits or 16 bits height maps are supported. Important: The image format must be saved in _monochrome mode_ \- height maps in RGB mode (24bit) will throw an exception. 
  * PageSize: The terrain will be PageSize x _PageSize_ vertices large. _PageSize_ must have the same value as the dimension of the heightmap image, and so must also have a value 2^_n_ +1 for some integer . 
  * TileSize: Terrain tiles have the dimension TileSize x _TileSize_ vertices. _This number must be smaller than PageSize. TileSize must have a value 2^_ n _+1 for some integer_ n''. Making tile size too small impacts performance significantly while making tiles too large may result in unnecessarily high detail in some parts of the scene. 
  * **MaxPixelError** : This specifies the maximum error tolerated when determining which level of detail to use. Setting this value too high can result in seams in the terrain. Setting the value too low can impact performance. This is the main way to control the distance at which the terrain displays LODs — it is not a distance in world units but rather how much error can appear on the screen. The more error allowed, the less detailed the LODs can become. 
  * **PageWorldX** , **PageWorldZ** : This sets the extents of the terrain in world coordinates. The larger the terrain, the lower the detail will be in the terrain, as the number of vertices used for the terrain is based on the heightmap, not the world size. This can be used to scale the terrain to any size you want. 
  * **MaxHeight** : The maximum height of the terrain in world coordinates. The 0..255 (resp. 0..65535) range from the heightmap is scaled to 0..MaxHeight in world coordinates. 
  * : Specifies the number of levels of detail that will be used in rendering the terrain. Terrain that is distant or is relatively flat can be rendered with less detail. 



###  Advanced Configuration Parameters

Some heightmap generators save data in a raw format rather than an image format. The following parameters describe the raw format. 

  * **Heightmap.raw.size** : Specifies the dimension of one side of the heightmap. This must be a value 2^_n_ +1 for some integer _n_. 
  * **Heightmap.raw.bpp** : Specifies the _bytes_ per pixel in the file. (1 for 8 bits, 2 for 16 bits, maybe also 3 for 24 bits support?) 
  * **Heightmap.flip** : When set to true, flips the heightmap. Required for _Terragen_ heightmaps. 



  
The following parameters control other aspects of the scene manager's operation. _Can someone fill in better descriptions for these?_

  * **VertexNormals** : This makes the TerrainSceneManager calculate and set vertex normals in the hardware buffer. If you use lighting or a GPU program that requires it, you should turn this on. 
  * **VertexColours** : This makes the TerrainSceneManager calculate and set the vertex colors in the hardware buffer. Turn this on if you use a GPU program that needs this information. 
  * **UseTriStrips** : When set to yes, optimizes the order in which terrain triangles are sent to the GPU so that fewer vertices are sent (though on most newer graphics cards this does not make a difference in framerate). Because this causes "cracks" to appear in some video cards and has little or no performance benefit, it is recommended that you turn this off. 
  * **VertexProgramMorph** : Use vertex program to morph -LODs, if available. 
  * **LODMorphStart** : The proportional distance range at which the -LOD morph starts to take effect. This is as a proportion of the distance between the current LODs effective range, and the effective range of the next lower LOD. 



###  More Advanced Parameters

Instead of using the terrain and detail textures to shade the terrain, you can provide your own shading routines, specified in your own material. A typical use of this would be to provide vertex programs in your material. 

  * **MorphLODFactorParamName** : This option is used if _VertexProgramMorph_ is set to _yes_ and your custom material includes a _high-level_ vertex program. This option specifies the name of the vertex program parameter to which you wish to bind the morph LOD. This parameter is 0 when there is no adjustment (highest) to 1 when the morph takes it completely to the same position as the next lower LOD. 


  * **MorphLODFactorParamIndex** : This option is used if _VertexProgramMorph_ is set to _yes_ and your custom material includes an _assemler-level_ vertex program. This option represents the index of the vertex program parameter to which you wish to bind the morph -LOD factor. This is 0 when there is no adjustment (highest) to 1 when the morph takes it completely to the same position as the next lower LOD. 


  * **CustomMaterialName** : The name of the material you will define to shade the terrain. 



##  Using Custom Materials

You can use custom materials to render your terrain. If your material contains a vertex program, the following parameters are available: 

  * positions 
  * two sets of texture coordinates (index 0 is world texture, index 1 is detail texture) 
  * Normals, if enabled 
  * Per-vertex delta values, for morphing a higher -LOD tile into a lower -LOD tile. This is one float per vertex bound as 'blend weight'. If you want to use this you also have to provide the name or index of the parameter you wish to receive the morph factor. 



##  Dirty notes

Here are some plain notes. The style etc. has to be improved later. Also remove of redundancy. 

... some of my points got lost by a Firefox crash /-: 

  * The image dimensions of _Heightmap.image_ has to be equal to _PageSize_


  * The Terrain is constructed as a page of terrain tiles 
    * Terrain Scene Manager (TSM) has only one tile 
    * Paging Scene Manager is an improved version of TSM (right??) that support different tiles 


  * Related to the last point is a strange thing: 
    * _TileSize_ has to be defined and must be smaller than _PageSize_


    
    
    # How large is a page of tiles (in vertices)? Must be (2§25525b30243cfaa6378d30b5ec8ed892§n)+1
    PageSize=513
    # How large is each tile? Must be (2§ae22777726970b55fe2e5b1c465fb5f1§n)+1 and be smaller than PageSize
    TileSize=129

  * The terrain is composed of PageSize^2 vertices
    * This results in (TileSize-1)^2 quads 
    * Dependent to the camera distance the remoter ones are conflated to apploximated bigger quads (by -LOD algorithm) 
    * For tiles it's the same 


  * World coordinates range from (0, 0, 0) to (_PageWorldX_ , _MaxHeight_ , _PageWorldZ_) 


  * _WorldTexture_ is stretched over the entire world 
    * And for the Paging Scene Manager for each tile ?? (please fill in if you know) 
    * Common used file formats are JPG and PNG 


  * _PageSource_ can have any value that has been registered as a _TerrainPageSource_


  * TSM is a sub-class of OctreeSceneManager and uses an octree for culling. 



The mipmaps in _terrain.cfg_ are about -LOD, how many levels of -LOD to provide for the terrain tiles. 

  * _VertexNormals=yes_ makes Ogre compute normals at each vertex for use with dynamic lighting of the terrain 
  * _VertexColours=yes_ creates a vertex element for diffuse colours 
    * is implemented yet? 
    * maybe _VertexColors_ instead? (without U at colours) 
  * _UseTriStrips=yes_ as it implies, whether to use tri strips for rendering the terrain 


  * The terrain of TSM can't be used for collision detection in combination with Newton physics engine 
    * alternatively see Using PLSM2 with Newton