New components to generate terrains, along with a demo including water and planting trees

Posted on

Terrain, water, trees designed in Castle Game Engine editor
Terrain, water, trees designed in Castle Game Engine editor
Water reflections
Terrain wireframe, water rect underneath
Terrain with one size larger (and visible fog in the distance)
Trees planted with TCastleStickToSurface to stick on terrain
Alternative emphasis for steep texture layer
Terrain heights from a simple image
Terrain heights from a simple image
Terrain heights from a simple image
Terrain heights from a simple image
Combining terrain heights from image with noise
Combining terrain heights from image with noise

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 TCastleTerrainImage and TCastleTerrainNoise. E.g. you could use TCastleTerrainNoise but add TCastleTerrainImage to force some particular mountain or valley, or use TCastleTerrainImage to 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.

Notable Replies

Continue the discussion at Castle Game Engine Forum


Avatar for chikega Avatar for michalis