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

**URL:** https://forum.castle-engine.io/t/new-components-to-generate-terrains-along-with-a-demo-including-water-and-planting-trees/631
**Category:** News
**Created:** [August 21, 2022, 5:27am UTC](https://forum.castle-engine.io/t/new-components-to-generate-terrains-along-with-a-demo-including-water-and-planting-trees/631 "2022-08-21T05:27:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [August 21, 2022, 5:27am UTC](https://forum.castle-engine.io/t/new-components-to-generate-terrains-along-with-a-demo-including-water-and-planting-trees/631/1 "2022-08-21T05:27:18Z")

</div>

| [![Terrain, water, trees designed in Castle Game Engine editor](https://forum.castle-engine.io/uploads/default/original/1X/c5d326718a161c7ff82667d5ea6d7a2bdadcf2fa.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2022/08/1.png?ssl=1 "Terrain, water, trees designed in Castle Game Engine editor") |
| [![Terrain, water, trees designed in Castle Game Engine editor](https://forum.castle-engine.io/uploads/default/original/1X/68fa218251c14cea815607aba107be7b39d396d4.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2022/08/2.png?ssl=1 "Terrain, water, trees designed in Castle Game Engine editor") |
| [![Water reflections](https://forum.castle-engine.io/uploads/default/original/1X/96c4d10093627abb421d6f71fbce06ac18dcfd04.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2022/08/3.png?ssl=1 "Water reflections") |
| [![Terrain wireframe, water rect underneath](https://forum.castle-engine.io/uploads/default/original/1X/8fc4a2a5ddc35df4c149dea1924d6377df3f2f1c.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2022/08/3.5_terrain_wireframe.png?ssl=1 "Terrain wireframe, water rect underneath") |
| [![Terrain with one size larger (and visible fog in the distance)](https://forum.castle-engine.io/uploads/default/original/1X/2ec6d8555161c8b5c475919f2ee36bcebc848a86.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2022/08/4_size.png?ssl=1 "Terrain with one size larger (and visible fog in the distance)") |
| [![Trees planted with TCastleStickToSurface to stick on terrain](https://forum.castle-engine.io/uploads/default/original/1X/ac335082bbb783749c0aba4504ec0b0d2b8e4d20.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2022/08/5_trees.png?ssl=1 "Trees planted with TCastleStickToSurface to stick on terrain") |
| [![Alternative emphasis for steep texture layer](https://forum.castle-engine.io/uploads/default/original/1X/094f46fb44c6cfc5a2685b769a8b0508cea66965.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2022/08/6_trees_steep_tex.png?ssl=1 "Alternative emphasis for steep texture layer") |
| [![Terrain heights from a simple image](https://forum.castle-engine.io/uploads/default/original/1X/e6f20a9306c1ebfc298a04a0e6f4ffb7cd9449e9.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2022/08/7_terrain_image_simple.png?ssl=1 "Terrain heights from a simple image") |
| [![Terrain heights from a simple image](https://forum.castle-engine.io/uploads/default/original/1X/e25482d0d2479e18ae18d29e8020415c2b2aa68d.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2022/08/8_image_1.png?ssl=1 "Terrain heights from a simple image") |
| [![Terrain heights from a simple image](https://forum.castle-engine.io/uploads/default/original/1X/781325d1fe967a2412a716e4cd71c30e668a7457.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2022/08/9_image_2.png?ssl=1 "Terrain heights from a simple image") |
| [![Terrain heights from a simple image](https://forum.castle-engine.io/uploads/default/original/1X/a3772b4dbd2717137622f7394c6e15eb0831e665.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2022/08/10_image.png?ssl=1 "Terrain heights from a simple image") |
| [![Combining terrain heights from image with noise](https://forum.castle-engine.io/uploads/default/original/1X/5196bbfeeb74fdd867b2cfc22764469d87049f19.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2022/08/11_combine1.png?ssl=1 "Combining terrain heights from image with noise") |
| [![Combining terrain heights from image with noise](https://forum.castle-engine.io/uploads/default/original/1X/40b0adee32e259227d7246e6c7d80dd8837ccb3a.png)](https://i0.wp.com/castle-engine.io/wp/wp-content/uploads/2022/08/12_combine2.png?ssl=1 "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/](https://github.com/castle-engine/castle-engine/tree/master/examples/terrain) now presents a terrain made using this technique. Terrains of course can be combined with [skybox (TCastleBackground)](https://castle-engine.io/background), [fog (TCastleFog)](https://castle-engine.io/fog), 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.

---

<div class="post-metadata">

### Author: ![chikega](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/chikega/32/712_2.png) [@chikega](https://forum.castle-engine.io/u/chikega)
#### Post date: [August 23, 2022, 10:57pm UTC](https://forum.castle-engine.io/t/new-components-to-generate-terrains-along-with-a-demo-including-water-and-planting-trees/631/2 "2022-08-23T22:57:39Z")

</div>

Awesome! 👍
