Terrain

From Leadwerks Developer Wiki

Jump to: navigation, search

Contents

Introduction

Terrain can be used to render large outdoors areas. Leadwerks Engine 2 supports large terrains with LOD rendering, using up to 33 million polygons.

Multiple texture layers may be used on a terrain. The first layer is sometimes referred to as the base layer. Additional layers may be added and blended onto the layers below. An RGBA texture called an alpha map is used to control blending. When an alpha map is loaded with index 0, one color channel corresponds to each of the first four layers. See LoadTerrainAlphamap for more information. If you are working in the sandbox, alpha maps are automatically created and managed when you add new texture layers.

5 layers are currently supported. There may be only one terrain atm.

Commands

Creation & Loading

CreateTerrain

  • C: TTerrain CreateTerrain( int resolution=2048 )
  • C++:
    • Terrain::Terrain( TEntity ent )
    • Terrain::Terrain( int resolution = 2048 )
    • virtual void Create( int resolution = 2048 )
  • BlitzMax: CreateTerrain:TTerrain( resolution:Int=2048 )
  • Pascal: function CreateTerrain ( resolution:Integer=2048 ): THandle;
Creates a new terrain. A power-of-two size must be used for the resolution or the command will fail and return Null. To further scale the terrain, use the ScaleEntity command.
[Examples]

LoadTerrainHeightmap

  • C: int LoadTerrainHeightmap( TEntity terrain, str path )
  • C++: virtual bool Terrain::LoadHeightmap( const std::string& path )
  • BlitzMax: LoadTerrainHeightmap( terrain:TTerrain, path$ )
  • Pascal: function LoadTerrainHeightmap ( terrain:THandle; name:PAnsiChar ): Integer;
Loads a heightmap onto the terrain and returns 1 is successful. Heightmaps can be in .png, .bmp, .jpg, .tga, or 16-bit .raw format. RAW files provide the greatest precision, but must be the same dimensions as the terrain resolution. Other images will be resized to fit the terrain.
[Examples]

LoadTerrainAlphamap

  • C: int LoadTerrainAlphamap( TEntity terrain, str path, int index )
  • C++: virtual bool Terrain::LoadAlphamap(const std::string& path )
  • BlitzMax: LoadTerrainAlphamap%( terrain:TTerrain, path$ [, index=0 ] )
  • Pascal: function LoadTerrainAlphamap ( terrain:THandle; name:PAnsiChar; layer:Integer=0 ): Integer;
Loads an alpha map onto the terrain and returns 1 is successful. Alpha maps can be .dds, .png, .bmp, .jpg, or .tga format. If the index parameter is 0, the alpha map RGBA channels will be used to control the alpha levels of the first four terrain layers. If an index value greater then 0 is used, the alpha map will be loaded onto nth terrain layer.
[Examples]

Settings

UpdateTerrainNormals

  • C: void UpdateTerrainNormals( TEntity terrain, int x=-1, int y=-1, int width=1, int height=1 )
  • C++: void Terrain::UpdateNormals( int x=-1, int y=-1, int width=1, int height=1 )
  • BlitzMax: UpdateTerrainNormals( terrain:TTerrain,x:Int=-1,y:Int=-1,width:Int=1,height:Int=1 )
  • Pascal: procedure UpdateTerrainNormals ( terrain:THandle,x,y,width,height );
Updates all terrain point normals.
[Examples]

SetTerrainHeight

  • C: void SetTerrainHeight( TEntity terrain, long x, long y, flt height )
  • C++: void Terrain::SetHeight( int x, int y, flt height )
  • BlitzMax: SetTerrainHeight( terrain:TTerrain, x, y, height# )
  • Pascal: procedure SetTerrainHeight ( terrain:THandle; x:Integer; y:Integer; height:Single );
Sets the terrain height at the specified grid point. Height should be a number between 0 and 1.
[Examples]

SetTerrainTexture

  • C: void SetTerrainTexture(TTerrain terrain, TTexture texture, int index = 0, int layer = 0)
  • C++: void Terrain::SetTexture( const Texture& texture, int index, int layer )
  • BlitzMax: SetTerrainTexture(terrain:TTerrain,Texture:TTexture,index:Int=0,layer:Int=0)
Sets the terrain texture. If index is 0 the diffuse texture will be specified. If index is 1 the normal map will be specified. Layer can range from 0 to 4.
[Examples]

SetTerrainTextureScale

  • C: void SetTerrainTextureScale(TTerrain terrain, flt scale, int layer = 0)
  • C++: void Terrain::SetTextureScale( flt scale, int layer )
  • BlitzMax: SetTerrainTextureScale(terrain:TTerrain,scale:Float,layer:Int=0)
Scales the specified texture layer.
[Examples]

SetTerrainTextureRotation

  • C: void SetTerrainTextureRotation(TTerrain terrain, flt rotation, int layer = 0)
  • C++: void Terrain::SetTextureRotation( flt rotation, int layer )
  • BlitzMax: SetTerrainTextureRotation(terrain:TTerrain,rotation:Float,layer:Int=0)
Rotates the specified texture layer.
[Examples]

SetTerrainTextureMappingMode

  • C: void SetTerrainTextureMappingMode(TTerrain terrain, int mode, int layer = 0)
  • C++: void Terrain::SetTextureMappingMode( int mode, int layer )
  • BlitzMax: SetTerrainTextureMappingMode(terrain:TTerrain,mode:Int,layer:Int=0)
Sets the terrain texture mapping mode for the specified texture layer. Modes are:
0 - horizontal
1 - vertical
[Examples]

BlendTerrainTexture

  • C: void BlendTerrainTexture(TTerrain terrain, int x, int y, flt a, int layer)
  • C++: void Terrain::BlendTexture( int x, int y, flt a, int layer )
  • BlitzMax: BlendTerrainTexture(terrain:TTerrain,x:Int,y:Int,a:Float,layer:Int)
Sets the alpha blend for the specified layer at the given terrain point.
[Examples]

SetTerrainTextureConstraints

  • C: void SetTerrainTextureConstraints(TTerrain terrain, flt minslope, flt maxslope, flt minheight, flt maxheight, int layer)
  • C++: void Terrain::SetTextureConstraints( flt minslope, flt maxslope, flt minheight, flt maxheight, int layer)
  • BlitzMax: SetTerrainTextureConstraints(terrain:TTerrain,minslope:Float,maxslope:Float,minheight:Float,maxheight:Float,layer:Int)
Constrains texture layers so they will only appear within certain height and slope ranges. This will be AND combined with the layer's alpha map.
[Examples]

Retrieve info...

TerrainHeight

  • C: flt TerrainHeight( TEntity terrain, int x, int y )
  • C++: flt Terrain::GetHeight( int x, int y ) const
  • BlitzMax: TerrainHeight#( terrain:TTerrain, x, y )
  • Pascal: function TerrainHeight ( terrain:THandle; x:Integer; y:Integer ): Single;
Retrieves the relative terrain height at the specified grid point. This is a value between 0 and 1.
[Examples]

TerrainElevation

  • C: flt TerrainElevation( TEntity terrain, flt x, flt y )
  • C++: flt Terrain::GetElevation( flt x, flt y ) const
  • BlitzMax: TerrainElevation:Float( terrain:TTerrain, x:Float, y:Float )
  • Pascal: function TerrainElevation ( terrain:THandle; x:Integer; y:Integer ): Single;
Retrieves the terrain height at the specified position. The height will be interpolated between the nearest 4 grid points to provide a very close estimation of the terrain height at any given position.
[Examples]

TerrainNormal

  • C: TVec3 TerrainNormal( TTerrain terrain, flt x, flt y )
  • BlitzMax: TerrainNormal:TVec3( terrain:TTerrain, x#, y# )
  • Pascal: procedure TerrainNormal ( terrain:THandle; x:Single; y:Single; var normal:TVec3 );
Retrieves the terrain normal at the specified position. The normal will be interpolated between the nearest 4 grid points to provide a very close estimation of the terrain normal at any given position.
[Examples]

SaveTerrainHeightmap

  • C: int SaveTerrainHeightmap( TEntity terrain, str path )
  • C++: virtual bool Terrain::SaveHeightmap( const std::string& path ) const
  • BlitzMax: SaveTerrainHeightmap:Int( terrain:TTerrain, path:String )
  • Pascal: function SaveTerrainHeightmap ( terrain:THandle; name:PAnsiChar ): Integer;
Saves a heightmap onto the terrain and returns 1 is successful. Heightmaps can be in .png, .bmp, .jpg, .tga, or 16-bit .raw format. RAW files provide the greatest precision.
[Examples]

SaveTerrainNormalmap

  • C: int SaveTerrainNormalmap( TEntity terrain, str path )
  • C++: virtual bool Terrain::SaveNormalmap( const_str path ) const
  • BlitzMax: SaveTerrainNormalmap:Int( terrain:TTerrain, path:String )
  • Pascal: function SaveTerrainNormalmap ( terrain:THandle; name:PAnsiChar ): Integer;
Saves a normal map onto the terrain and returns 1 is successful. Normal maps can be .png, .bmp, .jpg, or .tga format.
[Examples]

SaveTerrainAlphamap

  • C: int SaveTerrainAlphamap( TEntity terrain, str path, int index )
  • C++: virtual bool Terrain::SaveAlphamap( const std::string& path ) const
  • BlitzMax: SaveTerrainAlphamap:Int( terrain:TTerrain, path:String [, index:Int=0 ] )
  • Pascal: function SaveTerrainAlphamap ( terrain:THandle; name:PAnsiChar; layer:Integer=0 ): Integer;
Saves an alpha map onto the terrain and returns 1 is successful. Alpha maps can be .png, .bmp, .jpg, or .tga format. If the index parameter is 0, the alpha map RGBA channels will be retrieved from the alpha levels of the first four terrain layers. If an index value greater then 0 is used, the alpha map will be saved from the nth terrain layer.
[Examples]

Global Settings

TerrainDetail

  • C: void TerrainDetail( int detail )
This will add the specified value to any calculated terrain LoD level. E.g. using 1 will make the usually second-highest LoD level the highest (the one used when looking at terrain closely).
This can be used to reduce terrain detail when rendering reflections (saving lots of polygons). It's not recommended to use this as a quality setting exposed to the end user since reducing the terrain resolution might cause visual errors (object floating in the air etc...), but this is not so noticeable in a reflection.
Default is 0.
[Examples]

SetVegetationShadowMode

  • C: void SetVegetationShadowMode( int mode )
Enable or disable vegetation shadows for all terrains.
To control the shadows of each vegetation layer, use the Vegetation Shadows setting in Editor.
[Examples]
Personal tools