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
The shape and coloration of the terrain in your scene is computed from a heightmap, a terrain texture and a 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 terrain.png 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. The -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).
The Terrain Scene Manager is configured via the terrain.cfg script.
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 nxn 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 n. 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 n.
- 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.
- MaxMipMapLevel: 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.
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.
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.
You can use custom materials to render your terrain. If your material contains a vertex program, the following parameters are available:
- 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.
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§1b3b06d47f3c619f4e8e9c15f11e8d62§n)+1 PageSize=513 # How large is each tile? Must be (2§55ca3dcc90d60a1b22222a241ab00611§n)+1 and be smaller than PageSize TileSize=129
- The terrain is composed of PageSize^2 vertices
- World coordinates range from (0, 0, 0) to (PageWorldX, MaxHeight, PageWorldZ)
- The 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
- Ogre API for TerrainSceneManager
- Basic Tutorial 3 - about Terrain, Sky, Fog, and the Root object
- Terrain Alpha Splatting - a working example using the standard terrain scenemanager, complete with CG shader
- its Terrain Configuration File - an example configuration
- Paging Scene Manager
- Terrain Howto
- Ogre Compatible HeightMap - code snippet for function getHeightAt(x,z)