terrainSystem.package
- ..
- README.md12.0 KB
- about.yaml507 B
- behavior.luau72.4 KB
- inspector.luau14.6 KB
- type.yaml5.3 KB
This package holds more than this page lists. See all of its files in its world.
README.md
terrainData
A landscape's baked data, as one asset.
A terrain is never a single image. It is a heightfield, the control textures
saying which surface covers where, a mask of where there is no ground at all,
the water surface standing over it, and the table of what those surfaces are.
Every one of those is an ordinary .texture the renderer already knows how to
sample; this container holds them together and names their roles, so a Terrain
component references a landscape rather than a handful of loose images, and a
heightfield never turns up in the picker beside an albedo map.
dunes.terrainData/
terrain.yaml the manifest: where the ground stands, and role -> child (required)
README.md what landscape this holds (required)
.metadata description and tags (required)
height.texture/ rgba32f: R metres, G/B gradient, A coverage
normal.texture/ uastc with mips: the ground normal, R x, G z, B y as n * 0.5 + 0.5
ground.texture/ uastc with mips: R the sky the ground sees, G wetness, B convexity, A deposit
macro.texture/ uastc with mips, sRGB: the colour of the far ground
holes.texture/ uastc with mips: R non-zero where there IS ground
water.texture/ rgba32f: R the surface's world Y, G its coverage
water_shade.texture/ uastc with mips: R the water column over the deepest column, G coverage
control0.texture/ uastc with mips: four layer weights, one per channel
control1.texture/ uastc with mips: layers 5-8
slice_albedo_0.texture/ uastc with mips: one layer texture per distinct albedo
slice_normal_0.texture/ uastc with mips: one per distinct normal map
slice_mask_0.texture/ uastc with mips: one per distinct mask map
surfaces/ the textures a graph made for the layers: <layer>_<role>.texture (optional)
graphs/ the graph that makes this ground and the parts it calls: .procGraph assets (optional)
The children are written by the same asset.create every other texture goes
through and placed inside the container by dest, the way a bundle carries the
meshes it assembles. A container holds holes, water and the slice_* children
only when the landscape has them.
A landscape that carries its graph
asset.create("terrainData", "Vale") makes a container with a starter graph under graphs/ (256 by 256 m at one metre a
cell, the inputs seed and relief), names it in the manifest (graph: "~.graphs.ground", version 2) and cooks it when it
registers. ~ inside the container means the container.
Where it lands: at the source root as Vale.terrainData, in a folder with folder, or at a path of its own with dest.
dest is the path of the container itself, so it ends in .terrainData; a dest that names a plain folder is refused,
naming the folder that places the container inside it.
asset.create("terrainData", "Vale") -- /source/Vale.terrainData
asset.create("terrainData", "Vale", { folder = "terrain" }) -- /source/terrain/Vale.terrainData
asset.create("terrainData", "Vale", { dest = "/source/terrain/Vale.terrainData" }) -- the same, by full path
terrainRef:cook() runs the graph and writes what it makes into
the container itself, the children in place and the manifest once at the end, on the background lane a slice of each frame
at a time, so the ground standing in a scene is drawn until the new one lands and each Terrain standing on it rebuilds
once. terrainRef:inputs() states the graph's inputs with the values the manifest gives them, setInputs({ relief = 80 })
changes them, and in edit mode a change to the inputs or the graph cooks once, a moment after the last edit.
bakeState() says where the ground stands (state, revision, stale). terrain.write into a container that names a
graph is refused: its ground is what the graph makes. asset.create("terrainData", name, { graph = false }) makes the
bake-only container terrain.write fills, which is version 1 and never cooks.
version: 2
graph: "~.graphs.ground" # the graph that makes this ground
output: landscape # the graph output the cook takes (landscape when left out)
inputs: { relief: 55 } # values for the graph's inputs, by name
bake: { revision: 7, graph: 3141592653, inputs: 271828182 } # what the children were cooked from
The manifest
version: 1
size: [4000, 4000] # metres of ground, along world X and Z
origin: [0, 0] # world centre of that rect
heightRange: [-8.1, 63.4] # the vertical reach the geometry declares
height: height.texture
normal: normal.texture
ground: ground.texture
macro: macro.texture
holes: holes.texture
water: water.texture
waterShade: { file: water_shade.texture, depthMax: 12.5 }
controls: [control0.texture, control1.texture]
layers:
- { name: sand, tint: [0.62, 0.56, 0.42], tiling: 12, albedoSlice: 0, normalSlice: 0, maskSlice: -1 }
- { name: rock, tiling: 8, albedoSlice: 1, normalSlice: -1, maskSlice: -1 }
slices:
albedo: [slice_albedo_0.texture, slice_albedo_1.texture]
normal: [slice_normal_0.texture]
size: [1024, 1024]
Children are named relative to the container, so a landscape that is moved or renamed carries its own textures with it.
The payloads
The heightfield is rgba32f: R the height in metres, G and B its
gradient along world X and Z, A coverage. Metres and not a normalized 16-bit
ramp, because relief is often a few metres inside a range of hundreds and eight
or sixteen bits band that into terraces. The gradient is what a surface normal
comes out of without differencing the height four more times.
The control textures are uastc with mips, one channel per surface layer, four layers
a texture and another texture for every four after that. A texel holds how much
of each layer covers it, and the weights are normalized to sum to one when
they are written: a texel covered half by sand and half by rock reads 128/128,
whatever the two masks happened to evaluate to. A uastc block holds the four
channels to within a step of that sum, so the surface renormalizes the weights
it samples. Layer n is channel ((n - 1) % 4) + 1 of control texture
ceil(n / 4); :layerSlot(name) answers that for a named layer.
The holes mask is uastc with mips, R non-zero where there is ground. Terrain a
cave mouth or a quarry has been cut out of has holes, and a hole is absence
rather than a height of zero.
The water surface is rgba32f: R the world Y the surface stands at, in
metres, G whether a surface covers that texel. A sea, a lake and a river are the
same thing here: a level and where it reaches. water_shade is its filterable
uastc companion that the water's material reads per pixel, R the column over
depthMax and G coverage.
The layer table says what each control channel stands for: its tint, its
albedo, its normal map, its mask map (R metallic, G ambient occlusion, B height,
A smoothness), and the metres one repeat of them covers (tiling).
The layer slices are the layers' own textures, one child per distinct texture
per role (albedo, normal, mask), all resampled to one square edge (slices.size).
Every slice is written uastc with mips, srgb for the albedo and linear for the
normal and mask maps. A surface binds each role's slices as one texture array, and each layer's
albedoSlice, normalSlice and maskSlice says which slice it reads (0-based,
-1 for none). A slot per layer per map would be twenty-four sampled textures in
one bind group, past what a fragment stage is guaranteed; three arrays cost three
slots whatever the layer count, and every slice wraps on its own.
Filling one
terrain.write in a procgen graph writes the manifest and every child in one
step, and answers the reference to the container. It takes:
raster: the ground; itsheightlayer becomes the heightfield.name: the container's identity, a bare identifier (duneswritesdunes.terrainData).folderordestplaces it.layers: the names of the raster layers holding each surface's coverage, in channel order, separated by commas ("sand, rock"). Coverage per surface is an ordinary mask layer written byterrain.mask.surfaces: optional records of{ name, tint?, albedo?, normal?, mask?, tiling? }matched to a layer byname, saying what each surface is shaded with.albedo,normalandmaskeach take a texture the graph made (atexture.*node wired straight in, or theTexturevalue a Luau script gives theterrain.writeop: the bake writes it assurfaces/<layer>_<role>.texture, and a re-bake removes thesurfaces/textures and slice children it no longer writes), anAssetRef<texture>, the identity, guid or path of a texture asset, or nothing. Any other value is refused naming the layer and the role.holes/solid: a mask layer marking where ground is cut out, or where it exists.height,water,waterMask: the raster layers read for the heightfield and the water surface.resolutionandlayerResolution: the texel size of the maps and the edge of one layer slice.
A surface that names no texture is shaded by its tint. Writing the same name
again re-bakes in place and keeps the guid, so every reference already pointing
at that landscape stays resolved.
Reading one
| Method | |
|---|---|
:placement() | { size, origin, heightRange }: where the ground stands and how far it reaches. |
:height() | The heightfield texture. |
:normal() | The ground normal texture, or nil for a landscape written without one. |
:ground() | The ground masks texture (R the sky the ground sees, G wetness, B convexity, A deposit), or nil for a landscape written without one: asset.validate warns terrainData.no_ground for a cooked graph that has none. |
:macro() | The colour of the far ground, or nil for a landscape written without one or with no layer. |
:holes() | The holes mask, or nil when the ground is solid everywhere. |
:water() | The water surface texture, or nil when the landscape is dry. |
:waterShade() | { texture, depthMax }, or nil for a landscape carrying no water. |
:control(i) / :controls() | The weight textures, in channel order. |
:layers() | The surface table. |
:slices() | { albedo?, normal?, mask?, size }: the layer textures per role, or nil when no layer carries a texture. |
:layerSlot(name) | Which control texture and channel a named layer is in. |
:manifest() | The whole thing, decoded. |
:instantiate(target?, opts?) | An entity carrying a Terrain component bound to this asset. |
:setChild(role, file) / :setPlacement(p) / :setLayers(t) / :setSlices(s) / :setWaterShade(file, depthMax) | What terrain.write fills it through. |
The placement travels with the landscape, so a Terrain component standing on
one does not re-state how big it is.
Validation
asset.validate (and the publish gate) refuse a container whose manifest does
not decode, that does not say where its ground stands, that names a child which
is not there, or that declares more layers than its control textures can carry. A file in
surfaces/ that is not a .texture is reported as terrainData.surfaces_foreign.
A landscape whose heightfield is missing is ground nothing can stand on, and
that is worth catching before it is published rather than when an entity tries
to load it.
In the Inspector
Selecting a terrain opens its Terrain section: its size, origin and height range, the heightfield's resolution once one is written, a table of its material layers (name, tiling, whether it has an albedo), and a link to each child texture (heightfield, holes, water, control maps). A terrain not yet sculpted says it has no child textures.