Skip to main content

Class: ChunkMaterial

The chunk material: every face the mesher lays is drawn by one of these. Its shading is a TSL graph built per kind (and sway, and hooks) once per world: what varies per material (its texture, its weather response, its reveal, a voxel box's texel frame, a pane's side of the water) is read through material references, so any number of materials share a program.

Hierarchy​

  • NodeMaterial

    ↳ ChunkMaterial

Constructors​

constructor​

• new ChunkMaterial(shading, options): ChunkMaterial

Parameters​

NameType
shadingChunkShadingInputs
optionsChunkMaterialOptions

Returns​

ChunkMaterial

Overrides​

NodeMaterial.constructor

Properties​

_swayCrossShading​

• _swayCrossShading: number = 0


_swayMotion​

• _swayMotion: Vector4

The fixed sway's speed, amplitude times scale, y scale and rooted (0 or 1), and its cross shading, as FIXED_SWAY reads them per draw (underscored: three's material key reads every other number as on/off).


chunkReveal​

• chunkReveal: number = 1

Terrain fade-in, 0 (pure fog tint) to 1 (drawn as itself).


cutsSolidTexels​

• cutsSolidTexels: boolean = false

Whether texels at or above solidTexelCut are dropped after the alpha test: the translucent half of a see-through split (see-through-texels), whose solid texels draw with the depth writers instead.


drawsGpuSections​

• drawsGpuSections: boolean = false

Drawn by a GPU terrain bucket (gpu-terrain-bucket.ts): a vertex takes its section's origin and reveal from the bucket's records by its sectionId. A flag of its own, so such a material keys its own graph.


greedyFrame​

• greedyFrame: Object

A voxel box's frame back to where its faces were meshed.

Type declaration​

NameType
valueMatrix4

hasGreedyFrame​

• hasGreedyFrame: number = 0


hookValues​

• hookValues: Record<string, unknown> = {}

The values this material's hooks read (ChunkShadingHooks.values, by materialValue("hookValues.<name>", type)).


isChunkMaterial​

• Readonly isChunkMaterial: true


map​

• map: Texture<unknown, TextureEventMap>

The atlas (or an own-texture face's texture) this material samples.


perDrawNode​

• Readonly perDrawNode: ConstNode<"float", number> = perDrawInputs


positionUnits​

• positionUnits: number = 1

Fixed-point counts per block of the geometry's positions.


shading​

• Readonly shading: ChunkShadingInputs


solidTexelCut​

• solidTexelCut: number = 1


surfaceOpenLight​

• surfaceOpenLight: Vector2

The voxel sunlight over which its faces count as open to the sky.


surfaceResponse​

• surfaceResponse: number = 1

How far the material takes the weather (SURFACE_RESPONSE).


waterDepthSide​

• waterDepthSide: number = 0

A pane fork's side of the water (WATER_DEPTH_SIDE_*).

Accessors​

chunkOptions​

• get chunkOptions(): Readonly<{ depthOnly: boolean ; hooks: ChunkShadingHooks ; kind: ChunkMaterialKind ; sway: ChunkSwayConstants }>

The kind, sway and hooks the program is built for.

Returns​

Readonly<{ depthOnly: boolean ; hooks: ChunkShadingHooks ; kind: ChunkMaterialKind ; sway: ChunkSwayConstants }>


isSideAgnosticProgram​

• get isSideAgnosticProgram(): boolean

Whether the program never reads the side it draws, so one program serves every side: a three patched to honour it leaves the side out of the program key, and the back and front passes of a double-sided see-through draw share one build instead of building the same code twice (unpatched three ignores it). The fluid surface reads frontFacing (in air only its outward face draws), so a fluid's sides are two programs. The patch throws if a material that says so reads its side.

Returns​

boolean


kind​

• get kind(): ChunkMaterialKind

Returns​

ChunkMaterialKind


type​

• get type(): string

Returns​

string

Overrides​

NodeMaterial.type


variantKey​

• get variantKey(): string

The program this material compiles to: same key, same program.

Returns​

string

Methods​

copy​

▸ copy(source): this

Parameters​

NameType
sourceChunkMaterial

Returns​

this

Overrides​

NodeMaterial.copy


customProgramCacheKey​

▸ customProgramCacheKey(): string

Returns​

string

Overrides​

NodeMaterial.customProgramCacheKey


fork​

▸ fork(): ChunkMaterial

A fork with this material's program and inputs and its own copies of the per-material values (forkChunkMaterial).

Returns​

ChunkMaterial


setVariant​

▸ setVariant(options): void

Rebuild this material's program for another kind, sway or hooks (a game customizing a block). Meshes keep the material; the next draw picks up the new program.

Parameters​

NameType
optionsPartial<ChunkMaterialOptions>

Returns​

void


setupDiffuseColor​

▸ setupDiffuseColor(builder): void

Parameters​

NameType
builderdefault

Returns​

void

Overrides​

NodeMaterial.setupDiffuseColor


setupLighting​

▸ setupLighting(): Vec3Node

Returns​

Vec3Node

Overrides​

NodeMaterial.setupLighting


setupObserver​

▸ setupObserver(builder): NodeMaterialObserver

three refreshes a node material's per-object bindings on every draw; a chunk mesh's are refreshed only when what they read changed (see narrowRefresh), the largest share of a chunk draw's CPU cost.

Parameters​

NameType
builderdefault

Returns​

NodeMaterialObserver

Overrides​

NodeMaterial.setupObserver


setupOutput​

▸ setupOutput(builder, outputNode): Node

Parameters​

NameType
builderdefault
outputNodeVec4Node

Returns​

Node

Overrides​

NodeMaterial.setupOutput


setupPosition​

▸ setupPosition(builder): AttributeNode<"vec3">

Parameters​

NameType
builderdefault

Returns​

AttributeNode<"vec3">

Overrides​

NodeMaterial.setupPosition