Table of Contents

Class TerrainRenderer

Namespace
Valheim.Testing
Assembly
Valheim.Testing.dll

Renders an ITerrain into an RGB image for review. The image covers Area with square pixels of MetresPerPixel; +x points right and +z points up (north up). Each pixel shows the terrain sampled once at its centre. Contours are drawn over the terrain, then polylines in the order added, then points. The same inputs give the same bytes on every platform, provided the terrain itself answers the same heights. A terrain that refuses a coordinate (outside a grid, an uncaptured replay sample, a missing biome layer) fails the render; nothing is painted in its place. A picture of an input is not evidence the game agrees.

public sealed class TerrainRenderer
Inheritance
object
TerrainRenderer

Constructors

TerrainRenderer(TerrainArea, float)

The area's width and depth must each be a whole number of pixels.

public TerrainRenderer(TerrainArea area, float metresPerPixel)

Parameters

area TerrainArea
metresPerPixel float

Fields

MaxPixels

Largest width or height in pixels, to refuse accidentally huge renders.

public const int MaxPixels = 8192

Field Value

int

Properties

Area

public TerrainArea Area { get; }

Property Value

TerrainArea

Coloring

public TerrainColoring Coloring { get; set; }

Property Value

TerrainColoring

Height

public int Height { get; }

Property Value

int

HighHeight

Height mode: the height drawn white.

public float HighHeight { get; set; }

Property Value

float

LowHeight

Height mode: the height drawn darkest (deep water, or the lowest land without water).

public float LowHeight { get; set; }

Property Value

float

MetresPerPixel

public float MetresPerPixel { get; }

Property Value

float

WaterLevel

Height mode: heights below this are drawn as water; null draws every height as land. The game's sea level is 30.

public float? WaterLevel { get; set; }

Property Value

float?

Width

public int Width { get; }

Property Value

int

Methods

BiomeColor(TerrainBiome)

Biome mode colour: one fixed colour per biome; Unknown is magenta.

public static RenderColor BiomeColor(TerrainBiome biome)

Parameters

biome TerrainBiome

Returns

RenderColor

Contours(float, RenderColor)

Adds contour lines at WaterLevel (the game's sea level, 30 m, when it is null) and every interval metres above and below it. A pixel is drawn when a 4-neighbour's height lies below a level its own height reaches, so each line is one pixel wide on its uphill side and the coastline is always one of the lines. Heights are the pixel-centre samples the terrain answers, in either colouring mode; between nodes of a grid those are its interpolation, not the game's.

public TerrainRenderer Contours(float interval, RenderColor color)

Parameters

interval float
color RenderColor

Returns

TerrainRenderer

HeightColor(float)

Height mode colour. Water (below WaterLevel) runs from light blue at the water level to dark blue at LowHeight. Land runs green, brown, white from the water level (or LowHeight) to HighHeight, brown at the midpoint. Heights beyond the range take the end colour.

public RenderColor HeightColor(float height)

Parameters

height float

Returns

RenderColor

PixelX(int)

World x of a pixel column's centre.

public float PixelX(int px)

Parameters

px int

Returns

float

PixelZ(int)

World z of a pixel row's centre; row 0 is the top (largest z).

public float PixelZ(int py)

Parameters

py int

Returns

float

Point(float, float, RenderColor, int)

Adds a filled disc: every pixel whose offset (dx, dy) from the point's pixel has dxdx + dydy <= radius*radius.

public TerrainRenderer Point(float x, float z, RenderColor color, int radius = 2)

Parameters

x float
z float
color RenderColor
radius int

Returns

TerrainRenderer

Polyline(IEnumerable<(float x, float z)>, RenderColor)

Adds straight one-pixel segments (Bresenham) between the pixels holding consecutive points.

public TerrainRenderer Polyline(IEnumerable<(float x, float z)> points, RenderColor color)

Parameters

points IEnumerable<(float x, float z)>
color RenderColor

Returns

TerrainRenderer

Render(ITerrain)

public TerrainImage Render(ITerrain terrain)

Parameters

terrain ITerrain

Returns

TerrainImage

ToPixel(float, float)

The pixel holding a world position; may lie outside the image, where drawing is clipped.

public (int px, int py) ToPixel(float x, float z)

Parameters

x float
z float

Returns

(int px, int py)