Skip to content

Ground and cliffs ​

How the ground is painted: tiles (grass, dirt, road…) made from patterns or pictures, blended by height where they meet, cliffs with rock walls and ragged tops, and optional sharper ground. Nothing is laid on your game by itself: you take the client's presets or give your own.

Quick start ​

ts
import { SHARP_GROUND, TILE_LOOKS } from '@v12-engine/client'

export const view: GameView = {
	units: { looks: {} },
	ground: { ...SHARP_GROUND, tiles: TILE_LOOKS } // melee's ground
}
// in the rules: the engine's tiles of an RTS
tiles: [...presetTiles, ...own]

That gives the client's grass, dark grass, dirt, road, sand, rock and snow, with sharper textures, relief lighting, a colour tint against repeats and shaped cliffs.

Common tasks ​

Add a tile of your own ​

ts
ground: {
	tiles: {
		...TILE_LOOKS,
		moss: { color: [0.3, 0.45, 0.2], pattern: 'moss', recipe: { params: { seams: 1.2 } } },
		snow: { ...TILE_LOOKS.snow, cliff: { color: [0.7, 0.75, 0.8], pattern: 'ice' } } // its cliffs in ice
	}
}

Write a pattern of your own ​

ts
ground: {
	patterns: {
		bark: { name: 'Bark', params: {}, shade: (params, noise) => noise.layered([8, 16, 32]) } // a PatternDef: lightness 0..1 at (u, v)
	}
}

Or give pixels: pixels: (size, color, seed, params) => …. The Ground editor offers yours before the client's, each parameter a slider.

Make tiles meet crisply or softly ​

ts
tiles: { grass: { ...TILE_LOOKS.grass, blendDepth: 0.1, height: 'grass_h.png' } } // small is crisp, 1 a soft fade

Shape the cliffs ​

ts
ground: { cliffShape: { detail: 4, roughness: 0.18, style: 'strata', rocks: { density: 0.3, where: 'foot' } } }

A map overrides it (MapCliff.shape, field by field; false for flat walls), set in the Look panel's Cliffs.

Paint a cliff look on some walls ​

ts
const north = editor.look.addCliffLook({ name: 'North face', shape: { style: 'columns', rocks: {} } })
editor.look.paintCliffLook(north, area) // an AreaShape; 0 takes looks off
editor.paintCliffLook(north) // the brush

Write a cliff style ​

ts
import { defineCliffStyle } from '@v12-engine/client/ground'

ground: { cliffStyles: { ridges: defineCliffStyle({ name: 'Ridges', params: {}, push: (params, noise) => (at) => Math.sin(at.y * 4) }) } }

at is a point of the wall and how far up it is; noise has value, layered, ridged and Worley noise in 3D; return about −1 to 1.

Draw circles on the ground ​

ts
kit.optional(GROUND_RINGS)?.set('aura', { x: 40, z: 60, radius: 6, width: 0.2, color: [0.4, 0.8, 1], alpha: 0.6 })
kit.optional(GROUND_RINGS)?.set('aura', null) // take it away

Drawn by the ground's material, so a circle across a cliff lies on its wall. Up to GROUND_RINGS_MAX (16); past that, a ring as before.

Colour unpainted ground ​

ts
ground: { colors: { lush, dry, dirt, rock, bed, dryHeight } } // or a function of slope and height

Unpainted ground is lush low down, dry high up, dirt on slopes, rock on the steepest, a bed under water.

Editor ​

  1. Open the Look panel's Ground section to pick patterns and tune their sliders.
  2. Cliffs sets the map's cliff shape, style and rocks, and its cliff looks.
  3. Paint cliff looks with their brush on the walls you want.
  4. Changes show at once; each is one undo step.

Reference ​

Patterns (PATTERNS) ​

grass, dirt, gravel, sand, rock, snow, plain, cobbles, cracked earth, mud, moss, ice, lava, planks, flagstones, each with parameters (recipe: { params }). Yours go in GameView.ground.patterns (a PatternDef: shade, pixels, height). A tile can stack layers (patterns or pictures, blended everywhere, in patches, or by lightness); groundTextures.layGround of @v12-engine/client/ground and layeredPixels of @v12-engine/client/common do it to your own pixels.

Where tiles meet ​

They blend by height, as remastered classic RTS ground does: each picture's alpha is how high it stands, and the higher shows over the lower, so grass reaches over dirt in tufts (heightBlend is the shader's sum). The depth is TileLook.blendDepth (a map's MapTile.blendDepth; BLEND_DEPTH, 0.2, by default). A picture's height is its lightness, or a height picture beside it (TileLook.height; withHeight(pixels, height) from @v12-engine/client/ground). A pattern made in code writes its own (PatternDef.height). Borders drawn with a texture (transitions) keep their alpha.

Cliffs ​

Walls are the cells below a level's edge (cliffCells, CLIFF_RISE); a slope that is no cliff turns to rock only when as steep as a wall (55° to 70°). The top's ground hangs over the lip, ragged, down to 30% of the wall (cliffUp); below it, rock to the foot, laid from three planes so it never stretches. Every cliff's look is GameView.ground.cliff (a map's MapEnvironment.cliff), or a tile's own (TileLook.cliff; a map's MapCliff.tiles over it; MapEditor.look.setCliff({ pattern: 'cobbles' }, 'grass')).

Sharper ground (SHARP_GROUND) ​

FieldWhat
textureSizeside of every ground texture, 64 to 2048 (TEXTURE_SIZE, 256). Costs memory, not frames: melee's 9 layers are 48 MB at 1024
relieflight the ground by its pictures' normals (<texture>_n.png, or made from height: heightNormals, RELIEF_SCALE); 0 flat
tintGroundTint: breaks repeats with a slow noise between two colours (low, high, size 24, amount 1)
cliffShapeCliffShape: walls as meshes (below)

Change them in code like the rest of the ground's looks: terrainView.setLooks({ ...looks, tint }) (GroundLooks).

Cliff shape (CliffShape) ​

FieldWhat
detaileach wall cell cut this many times each way (4, from 2 to 8)
roughnesshow far a style pushes, in cells (0.18; 0 smooth)
roundround outer and inner corners (yes)
stylerough (default), strata (thickness, jag), columns (width, seams), boulders (size), eroded (width, length), or yours (GameView.ground.cliffStyles)
paramsthe style's parameters
seedanother of the same
rocksrocks along walls: density, size, lumpiness, variants, where (foot, wall, both)

Only what is drawn changes: units stand, walk and are picked on the grid's heights, and a push never puts a wall over walkable ground. Walls meet with no gap.

Cliff looks (MapCliff.looks) ​

{ id, name, shape }, painted where the map's cell layer CLIFF_LOOKS_LAYER holds its id (GameMap.cells.cliffLooks). A look can have its own rock (MapCliffLook.rock), up to 15 per map. Where two looks meet, the wall between is pushed by both. In code: addCliffLook, paintCliffLook, setCliffLook, removeCliffLook. A tile's walls can have a shape too (TileLook.cliffShape; MapCliff.tiles[tile].shape).

Blight ​

presetBlight (the engine's cell layer, in ground.cellLayers) and a look of it on the ground: layers: { blight: groundPaint({ texture: 'textures/ground/blight.jpg', size: 512, scale: 14, opacity: 0.94 }) } in liteView's parts, the shared art's spoiled ground painted over the cells (as melee's view does). What blight does is your game's.

Grass and bushes ​

A layer of cells drawn as grass or your own bush models (foliage, in ground.cellLayers), with styles that hide, burn and grow back, and grass that grows on tiles by itself (on: { tiles }): see Grass and bushes.

What it costs ​

Height blending costs no more samples than a fade. A cliff look adds about a third to a map part's build time. Cliff styles cost a few ms per map part as it is built (3–5 ms at detail 4, 19 at detail 8: keep 8 for maps with few cliffs), nothing per frame beyond vertices. Rocks at one a wall cell cost 0.1–0.9 ms of a 2.5 ms frame. Rings cost nothing measurable.