Class TerrainHoleMask
A terrain's painted holes (GetHoles(int, int, int, int)) as the detail renderers read them: the blade grass (folded into its water line, GrassTerrain.Freeboard), the GPU detail scatter (a mask slice beside its heights; every mesh kind since the CPU chunk renderer went, 2026-10-27). Unity's own detail drawing is off on every terrain they drive, so nothing else keeps a plant out of a cave mouth: the detail layers under a hole still hold whatever the biome scatter painted before the hole was cut, and the 2 m density texels and scatter blocks reach past the hole's edge even where they do not.
public sealed class TerrainHoleMask
- Inheritance
-
TerrainHoleMask
- Inherited Members
Remarks
One cell per heightmap cell (UnityEngine.TerrainData.holesResolution = heightmap resolution − 1), cell (x, z) spanning heightmap samples x..x+1 and z..z+1; the terrain shader clips a whole texel (ClipHoles), so a point test of the cell under a root matches the drawn edge.
Constructors
TerrainHoleMask(TerrainData)
public TerrainHoleMask(TerrainData data)
Parameters
dataTerrainData
Fields
CellMetres
One cell's side, metres (the terrain's width over Resolution).
public readonly float CellMetres
Field Value
PlantClearMetres
How far past a hole's edge no plant roots, metres (2026-10-27, Moron 2: "the ground details don't overlap the hole itself"): the 2 m density texels and scatter blocks spread what the cells beside an opening hold up to its edge, and a blade, a bush or a scattered stone rooted on that edge leans or spreads out over the opening. The cut clears the detail cells round every cave opening wider still (PointOfInterestCaveOpeningClearance.DetailMargin); this is the plants' own margin at every hole, which also keeps them out from under a canyon wall's or a cloud island's rim of rock.
public const float PlantClearMetres = 1.5
Field Value
Resolution
Cells per side.
public readonly int Resolution
Field Value
StripRows
Rows read per ReadStrip(TerrainData), as the builders read their other layers.
public const int StripRows = 64
Field Value
Properties
Any
True once any cell read so far is a hole.
public bool Any { get; }
Property Value
Complete
True once every row has been read.
public bool Complete { get; }
Property Value
Methods
HoleAt(float, float)
Whether the point at normalised terrain coordinates (0..1 across each side) lies in a hole.
public bool HoleAt(float nx, float nz)
Parameters
Returns
HoleAtCell(int, int)
Whether cell (x, z) is a hole (clamped to the terrain).
public bool HoleAtCell(int x, int z)
Parameters
Returns
HoleAtSample(int, int)
Whether heightmap sample (x, z) is a corner of any hole cell: the samples whose water line the grass pulls under so its bilinear zero falls on the hole's edge.
public bool HoleAtSample(int x, int z)
Parameters
Returns
KeepClear(bool[], int, float, float)
Turns every solid cell whose square comes within metres of a hole cell's square into a hole, in place
(solid row z first, true solid; the holes as they were before the call decide, so it never spreads
further). Pure.
public static void KeepClear(bool[] solid, int resolution, float cellMetres, float metres)
Parameters
KeepPlantsClear()
Counts every cell within PlantClearMetres of a hole as one (in place, once every row is read): the mask the plant builders read (the blade grass and the GPU detail scatter), never the terrain's own holes, which the clouds and the ambient life read through a mask of their own.
public void KeepPlantsClear()
Read(TerrainData)
The whole mask at once; null when the terrain has no hole.
public static TerrainHoleMask Read(TerrainData data)
Parameters
dataTerrainData
Returns
ReadForPlants(TerrainData)
Read(TerrainData) with the plants' margin round every hole (KeepPlantsClear()); null when the terrain has no hole.
public static TerrainHoleMask ReadForPlants(TerrainData data)
Parameters
dataTerrainData
Returns
ReadStrip(TerrainData)
Reads the next StripRows rows.
public void ReadStrip(TerrainData data)
Parameters
dataTerrainData
ToTexels(int)
The mask as R8 texels at the heightmap's resolution (cell (x, z) at texel (x, z), 0 a hole, 255 solid; the last row and column solid), the detail scatter's slice.
public byte[] ToTexels(int heightResolution)
Parameters
heightResolutionint
Returns
- byte[]