Class CaveCoverMath
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
MaxPerTriangle
The most candidates one triangle offers one type (FishCaveCover.compute COVER_MAX_PER_TRIANGLE).
public const int MaxPerTriangle = 128
Field Value
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
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
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
Returns
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
Returns
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
nyfloat
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
tCaveCoverTypeInfohCaveCoverHabitatnormalYfloatscalefloat
Returns
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
Returns
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
colourColoruv3Vector2hasUv3bool
Returns
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
Returns
IsUnknown(Color)
Whether a vertex colour is the mesher's old plain white: no habitat written.
public static bool IsUnknown(Color colour)
Parameters
colourColor
Returns
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
Returns
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
Returns
Mix(uint)
public static uint Mix(uint x)
Parameters
xuint
Returns
Salt(CaveCoverType)
A type's salt.
public static uint Salt(CaveCoverType type)
Parameters
typeCaveCoverType
Returns
SmoothStep(float, float, float)
Hermite smoothstep as HLSL's (edges may be reversed).
public static float SmoothStep(float a, float b, float x)
Parameters
Returns
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
Returns
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
centroidVector3
Returns
Unit(uint, uint)
A unit value of a hash's stream, [0, 1).
public static float Unit(uint hash, uint stream)