Class ScenePathField
A scene's paths rasterised for the GPU: a distance field half a metre a texel, kept only in the 16 m pages a path passes through. What the terrain, the grass and the details read to draw, thin and clear a path (FishGroundPaths.hlsl).
public sealed class ScenePathField
- Inheritance
-
ScenePathField
- Inherited Members
Remarks
Why a distance field. The splat is two metres a texel: a trail under a metre wide painted there is a smear four metres across. A distance to the nearest path's EDGE, bilinearly filtered, is exact along a straight stretch at any magnification, so the shader can cut a crisp edge, fray it with noise, lay two wheel ruts a gauge apart and leave grass between them — none of which a weight could say.
Why pages. Paths cover a few percent of a scene. A whole-scene field at this resolution would be hundreds of megabytes; the pages a path touches are a few thousand, packed into one atlas. A page table (one texel a page) says where each page is in the atlas; a page holds 32 × 32 texels plus a one-texel border copied from its neighbours' ground, so a bilinear fetch never reads another page's texels.
A texel (RGBA8, linear): r the signed distance to the nearest path's edge (−8 m inside … +3 m outside), g that path's half width (÷ 8 m), b its wear, a its surface code (SurfaceCode(ScenePathSurface)).
Where two paths meet the edge is the nearer of theirs, and the rest is a blend of every way whose edge lies within BlendMetres of it, the nearer weighing more: a trail's earth runs on into the road it joins and thins into the gravel, rather than stopping at the line where the two edges are equally far (2026-10-19: "hard texture cuts" — the nearest way alone took the texel, so surface, wear and width all switched across one texel). Except inside a building's floor (Floor), whose wear and surface nothing else drawn over it blends into (a door path's round end or a well's apron reaching through the wall would bring its lower wear, and so its grass, indoors); its edge is still the deepest of them, so the floor is as bare as the apron round it.
Pure data, built by the cut and baked to two textures beside the terrain (ScenePathBake), which ScenePathSurfaceBinder binds.
Fields
Atlas
Atlas texels (RGBA32), AtlasPages × StoredTexels a side.
public Color32[] Atlas
Field Value
- Color32[]
AtlasPages
The atlas's size, pages a side (square).
public int AtlasPages
Field Value
BlendMetres
How much further than the nearest edge another way's edge may be and still blend into a texel, metres: across a junction's seam its ways mix over about this width, past it the nearer's alone.
public const float BlendMetres = 2
Field Value
Dropped
Pages that did not fit the atlas (should be zero; reported, never silent).
public int Dropped
Field Value
Encoding
The field's encoding, baked as the binder's Parameters.w (the shader reads it): 1 the first (nearest way only, earth coded 0 and track ⅓), 2 blended junctions with the track coded 0 (SurfaceCode(ScenePathSurface)).
public const float Encoding = 2
Field Value
HalfWidthRange
public const float HalfWidthRange = 8
Field Value
InsideMetres
The encoded range of the edge distance: InsideMetres inside the edge to OutsideMetres outside it.
public const float InsideMetres = 8
Field Value
MaxAtlasPagesPerSide
The most pages one side of the atlas holds: its coordinates are 8-bit in the page table.
public const int MaxAtlasPagesPerSide = 240
Field Value
Origin
World x/z of page (0, 0)'s corner.
public Vector2 Origin
Field Value
- Vector2
OutsideMetres
public const float OutsideMetres = 3
Field Value
PageCount
public int PageCount
Field Value
PageMetres
public const float PageMetres = 16
Field Value
PageTexels
public const int PageTexels = 32
Field Value
StoredTexels
A page's stored side: its texels and a one-texel border.
public const int StoredTexels = 34
Field Value
Table
Page table texels (RGBA32): r, g the page's atlas column and row, a 255 where the page is stored.
public Color32[] Table
Field Value
- Color32[]
TableDepth
The page table's size, pages.
public int TableDepth
Field Value
TableWidth
The page table's size, pages.
public int TableWidth
Field Value
TexelMetres
public const float TexelMetres = 0.5
Field Value
Properties
AtlasTexels
public int AtlasTexels { get; }
Property Value
Methods
BlendWeight(float)
How much a way whose edge lies beyond metres past a texel's nearest edge weighs in its blend:
1 for the nearest, falling smoothly to nothing at BlendMetres, so two ways equally near mix evenly.
public static float BlendWeight(float beyond)
Parameters
beyondfloat
Returns
Build(IEnumerable<ScenePath>)
Rasterises paths. Stretches on a bridge are left out (the deck is the way there, not the river bed under it).
public static ScenePathField Build(IEnumerable<ScenePath> paths)
Parameters
pathsIEnumerable<ScenePath>Every path the scene draws.
Returns
DecodeEdge(byte)
public static float DecodeEdge(byte r)
Parameters
rbyte
Returns
EncodeEdge(float)
Encodes an edge distance (metres, negative inside) as the r byte.
public static byte EncodeEdge(float edge)
Parameters
edgefloat
Returns
EndFade(ScenePath, out float[], out float[])
The half widths and wears a path is drawn with: its own, narrowed to nothing and worn away over the last few metres of each end that stops in a site, so a way peters out into the ground instead of ending in a full-width round cap (2026-10-11). An end that joins another way (FromId −1) and a settlement's streets are drawn as they are: a junction must meet, and a street runs to its walls.
public static void EndFade(ScenePath path, out float[] half, out float[] wear)
Parameters
EndFadeMetres(ScenePath)
How far a dead end peters out, metres: a few widths, within bounds.
public static float EndFadeMetres(ScenePath path)
Parameters
pathScenePath
Returns
Sample(float, float, out float, out float, out float, out float)
The field at a world point as the shader reads it (bilinear inside the page), for tests and tools: false where no page is stored. Edge in metres (negative inside), half width in metres, wear and surface code 0 … 1.
public bool Sample(float x, float z, out float edge, out float halfWidth, out float wear, out float surface)