CreateTerrain()
Syntax
CreateTerrain(Filename$, MaterialID, [ScaleX, ScaleY, ScaleZ, [Precision]])Description
Creates a new 3D terrain from the given 2D picture file. The picture can be in either JPEG, PNG or TGA format and has to be in 256 color mode (grayscale). Each pixel of the picture will be interpreted as the height of the terrain at this point. A fully black (R,G,B=0.0,0) pixel will be at a height of 0 and a full-scale white (R,G,B=255,255,255) pixel will be at a height of 255. Therefore it is possible to have up to 256 levels of height. If required, the terrain can be scaled when it is created using the ScaleX, ScaleY and ScaleZ optional parameters. For performance reasons, it is not possible to resize a terrain in realtime, only when it is created.
The used picture must be a sqare, where x and y sizes are powers of 2 +1, with a minimum size of 65. Possible sizes can be 65x65, 129x129, 257x257 and so on. E.g. for a terrain with 64x64 grid of squares you need 65x65 pixels.
The specified material will be used by the terrain for rendering and can be easily got using the MaterialID() function. The material usually contains two texture layers: the first one is the texture which is applied globally to the terrain and the second layer is the detail texture, which is applied several times over the terrain (to get a more precise render). The example below shows the usual material setup for a terrain.
The last optional parameter controls the precision of rendering the terrain. As there are many calculations involved, this parameter has been introduced to tune the terrain display depending on the target computer. For example, you can set the rendering to be slower but more accurate on faster computers or faster but not as good looking for slower computers.
The terrain has to be created before any cameras.
Parameters
Filename$ - A string containing the name of the picture file to create the terrain from.
MaterialID - The ID of the material to render the terrain in, which can be got using the MaterialID() function.
ScaleX - The factor to scale the terrain by in the X direction. A value of 1 means to keep the same size. A value of 2 means to double the size, 3 to triple the size and so on. Fractional values between 0 and 1 will cause the terrain to be decreased in size.
ScaleY - The factor to scale the terrain by in the Y direction. Values are the same as the ScaleX parameter.
ScaleZ - The factor to scale the terrain by in the Z direction. Values are the same as the ScaleX parameter.
Precision - This is optional, but can only be set if the Scale parameters have been used. Precision for the rendering of the terrain. Possible values range from 1 (best, but slowest) to 20 (fastest but suffers from polygon displacement when close up).
Return value
Example:CreateMaterial (0, LoadTexture(0, "Global.jpg")) ; First layer is global AddMaterialLayer(0, LoadTexture(1, "Detail.jpg"), 1) ; Second layer is detail
Supported OS
All