Table of Contents

Class CaveCoverMath

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.dll

The cave cover's pure arithmetic: the hashes, the habitat a vertex carries, a type's density there, the rings and the levels. FishCaveCover.compute mirrors every function here line for line (change both together); the tests pin them.

public static class CaveCoverMath
Inheritance
CaveCoverMath
Inherited Members

Fields

FadeBand

The share of the keep over which a thinned candidate dissolves (FishCaveCover.compute COVER_THIN_BAND).

public const float FadeBand = 0.08

Field Value

float

MaxPerTriangle

The most candidates one triangle offers one type (FishCaveCover.compute COVER_MAX_PER_TRIANGLE).

public const int MaxPerTriangle = 128

Field Value

int

Unknown

The habitat a mesh read with no habitat channels stands for: a modest damp, silted, faintly glowing cave.

public static readonly CaveCoverHabitat Unknown

Field Value

CaveCoverHabitat

Methods

Barycentric(float, float)

A point on a triangle from two units: barycentric (1 − u − v, u, v), folded into the triangle.

public static Vector3 Barycentric(float u, float v)

Parameters

u float
v float

Returns

Vector3

Candidate(uint, uint, uint)

A candidate's hash: the triangle, the type's salt, the candidate's index.

public static uint Candidate(uint triangle, uint salt, uint k)

Parameters

triangle uint
salt uint
k uint

Returns

uint

Candidates(float, float)

How many candidates a triangle offers a type: its area × density rounded up, capped at MaxPerTriangle.

public static int Candidates(float area, float density)

Parameters

area float
density float

Returns

int

ClassWeights(float)

How much floor, wall and roof a face is by its outward (into the void) normal's y: floor above ~0.55, roof below ~−0.5, smooth between; the three add to one.

public static Vector3 ClassWeights(float ny)

Parameters

ny float

Returns

Vector3

Density(in CaveCoverTypeInfo, in CaveCoverHabitat, float, float)

A type's instances per m² at a point in the nearest ring: its density × habitat × class × the scale.

public static float Density(in CaveCoverTypeInfo t, in CaveCoverHabitat h, float normalY, float scale)

Parameters

t CaveCoverTypeInfo
h CaveCoverHabitat
normalY float
scale float

Returns

float

Exists(float, int, float)

Whether candidate k (with its coin) of a triangle exists: the triangle offers n = area × density candidates, the whole ones always and the last by its coin, so the expected count is exactly n. Nothing here depends on the camera.

public static bool Exists(float n, int k, float coin)

Parameters

n float
k int
coin float

Returns

bool

HabitatOf(Color, Vector2, bool)

The habitat a vertex carries (COLOR = wet, daylight, sediment, trodden; TEXCOORD3 = organic, glow). An old mesh's white colour is Unknown (all six: neither half was written); a colour with no TEXCOORD3 has no organic or glow.

public static CaveCoverHabitat HabitatOf(Color colour, Vector2 uv3, bool hasUv3)

Parameters

colour Color
uv3 Vector2
hasUv3 bool

Returns

CaveCoverHabitat

HabitatWeight(in CaveCoverTypeInfo, in CaveCoverHabitat)

A type's habitat weight at a point, 0..1 (before its class).

public static float HabitatWeight(in CaveCoverTypeInfo t, in CaveCoverHabitat h)

Parameters

t CaveCoverTypeInfo
h CaveCoverHabitat

Returns

float

IsUnknown(Color)

Whether a vertex colour is the mesher's old plain white: no habitat written.

public static bool IsUnknown(Color colour)

Parameters

colour Color

Returns

bool

Keep(float, Vector2[], int)

The share kept at a distance: piecewise linear through the rings (metres, keep), whole before the first, nothing past the last. Rings must rise in metres. The same at every candidate of a triangle at one distance, and falling with distance, so the far rings' instances are a subset of the near ones'.

public static float Keep(float d, Vector2[] rings, int count)

Parameters

d float
rings Vector2[]
count int

Returns

float

LevelOf(float, float, float, float)

The level of detail a candidate draws at: 0 within lod1 × reach, 1 within lod2 × reach, else 2.

public static int LevelOf(float d, float reach, float lod1, float lod2)

Parameters

d float
reach float
lod1 float
lod2 float

Returns

int

Mix(uint)

public static uint Mix(uint x)

Parameters

x uint

Returns

uint

Salt(CaveCoverType)

A type's salt.

public static uint Salt(CaveCoverType type)

Parameters

type CaveCoverType

Returns

uint

SmoothStep(float, float, float)

Hermite smoothstep as HLSL's (edges may be reversed).

public static float SmoothStep(float a, float b, float x)

Parameters

a float
b float
x float

Returns

float

ThinFade(float, float)

The thinning with distance, as the detail scatter's (FishDetailScatter.compute ThinFade): a candidate whose hash is under the keep is drawn, fading out (dithered) over the last FadeBand of it; returns the share faded out, 1 gone. The same candidate drops at the same keep from every camera, so the far rings' instances are a subset of the near ones'.

public static float ThinFade(float keep, float hash)

Parameters

keep float
hash float

Returns

float

TriangleKey(Vector3)

A triangle's key: its world centroid to the centimetre, so the same rock gives the same cover on every client.

public static uint TriangleKey(Vector3 centroid)

Parameters

centroid Vector3

Returns

uint

Unit(uint, uint)

A unit value of a hash's stream, [0, 1).

public static float Unit(uint hash, uint stream)

Parameters

hash uint
stream uint

Returns

float