I’m proud to announce a new Castle Game Engine feature: terrain components! A new
TCastleTerrain component (
TCastleTransform descendant) allows to visually design a terrain and you can of course use it from code or from editor and play with all the properties visually.
Terrain height data may come from:
A smooth noise, generated with
TCastleTerrainNoise. This employs a few techniques for nice terrain generation, summing a few octaves of noise and adding simple tricks to make it smooth and heterogeneous.
An image (height map from image intensities), with
TCastleTerrainImage. This is great to edit the heights in any 2D image editor – GIMP, Photoshop, or just Paint 🙂 etc.
A combination of the above (sum, min, max, multiplication) using
TCastleTerrainCombine. This effectively allows to make an “expression tree” to calculate terrain as a combination of multiple
TCastleTerrainNoise. E.g. you could use
TCastleTerrainImageto force some particular mountain or valley, or use
TCastleTerrainImageto make the borders of the noise go smoothly to 0 (to seamlessly connect terrain to a perfectly flat plane).
The terrain component features a ready visualization that combines 4 layers of materials (colors, textures, with per-layer setting for metallic, roughness) in an interesting manner. Height and slope (how steep is the terrain here) decide what mixture of layers to show at each point. See
TCastleTerrain component docs for details.
The example in examples/terrain/ now presents a terrain made using this technique. Terrains of course can be combined with skybox (TCastleBackground), fog (TCastleFog), trees (make multiple instances of a tree using
TCastleTransformReference to make them ultra-light on resources), and water (using CGE shader effects in OpenGL Shading Language in X3D).
We also have a new behavior, esp. useful for trees on a terrain:
TCastleStickToSurface. Use this when you want an object to stick to another object’s surface, even when one of them is moving. Nice to position trees on the surface of terrain.
Have fun with it! And note that this is just the beginning 🙂 I’m aware that to make terrains really nice to use we need a few more features. In particular on TODO are:
tools to edit the terrain heights within CGE editor.
tools to edit the terrain textures mixture (splatmap) within CGE editor.
tools to plant trees and grass in CGE editor. You can kind of do it now, but it’s very manual.
more specialized and efficient rendering algorithm. Right now terrain in the end is just a simple big mesh of triangles. It’s actually quite fast to render (because modern GPUs can handle big shapes) but it’s not a sustainable way to render huge terrains.
Continue the discussion at Castle Game Engine Forum