Latest Posts

Changes in HelpTerrains

Revision Differences of Revision 8

[TOC] ¶

Terrains are somne of the base graphics in widelands. This page describes how they are implemented and should help with creating new terrains. ¶

# Properties of the terrain patterns ¶

The patterns for terrains
do have some restrictions: ¶

1. Width/height: 64 pixel ¶
2. They must be color indexed ¶
3. They couldn't get transparent areas ¶

# Implementing ¶

The surface of the widelands terrain consists of a lot of triangles. See [geometry](https://wl.widelands.org/docs/wl/geometry/)
fonr more about this issue. Each triangle of the surface is called "field". The squared terrain patterns are therefore splitted into triangles to fit the fields of the surface. This terrainst pattern shows how the splitting is made: ¶

![test.png](/wlmedia//wlimages/test.png) ¶

The
pattefourn icolors sreplittred isento 4the triangles, in which arthe reprattesernted wis splith the different colors. Wwhile rendering. oOnly one of those triangles are displayed for each field: ¶

![terrain_split_2.jpg](/wlmedia//wlimages/terrain_split_2.jpg) ¶

Note that the red and white triangles of the original pattern are assembled from two patterns to get one big red and one big white triangle. In the above picture the patterns are knowingly spread, to help distuinguish the single patterns
of each field. If all patterns are close together, it looks like this: ¶

![terrain_split_1.jpg](/wlmedia//wlimages/terrain_split_3.jpg) ¶

The patterns do have allways the same area where they adjoin: ¶

Testpattern 2 | Result ¶
---------- | ---------- ¶
![test_2.png](/wlmedia//wlimages/test_2.png) | ![terrain_split_4.jpg](/wlmedia//wlimages/terrain_split_4.jpg) ¶

This is importand if you want to create terrains patterns which do not have visible edges if the patterns of the same type adjoin. ¶

# Dithering ¶

Different types of terrains do not have hard edges if they adjoin. This is made with dithering, a technique which blur the edges from one terrain type to another. Dithering could result in different results: ¶

![dithering_1.jpg](/wlmedia//wlimages/dithering_1.jpg) ¶

The above left example shows, that the testpatterns overlaps with the meadow terrain. The right one shows the opposit: The blue terrain overlaps the testpattern. If we use the blue terrain for all edges, the visible area of the testpattern shrinks drastically. Who decides which terrain dither over the other? ¶

## Dithering is half configurable ¶
The dithering is configured in the file *"`widelands/world/terrains/init.lua`"* with the variable `dither_layer`. Each terrain has its own dither_layer value. Terrains with higher values let the terrain dither over terrains with lesser values. Is the dither_layer value the same, no dithering is made. Examples which are used in chapter [dithering](#dithering): ¶

Terrain | dither_layer | consequence ¶
-------- | --------- | ------------ ¶
testpattern | 220 | This overlaps the meadow terrain ¶
meadow | 120 | This pattern is covered by the testpattern ¶
blue | 240 | This terrain overlaps meadow and the testpattern ¶

The values for dither_layer in the file *"`widelands/world/terrains/init.lua`"* are valid for the whole game. It is not possible to change this value during map creation or adjust it for each map different! ¶