Skip to content

Material

const Material: object

Defined in: render/material.ts:366

applyState(material, state, textureLeases?): void

Replace the complete local parameter/render-state snapshot and flush once. Missing fields restore base defaults or remove an instance override, so future parent edits keep propagating. Shader and parent ownership stay with the asset loader; this operation never re-acquires a different generation. When supplied, textureLeases transfers ownership of the complete edited texture set. Receipts remain held until replacement, Reset or material release.

number

Omit<MaterialOptions, "shader">

ReadonlyMap<string, TextureLease>

void

compileShader(esshaderSource, features?): number

Compiles a .esshader material shader through the engine’s ShaderParser, which generates the std140 MaterialConstants block from its #pragma param declarations and registers the param layout. Use this (not createShader) for materials whose parameters should reach the GPU. Returns a shader handle, or 0 on failure.

string

string[] = []

number

create(options): number

Creates a material with a shader and optional settings.

MaterialOptions

Material creation options

number

Material handle

createFromAsset(data, shaderHandle, parentHandle?): number

Creates a material from asset data. When

MaterialAssetData

number

number

number

parentHandle is given (the asset’s instanceOf resolved to a loaded parent), builds a Material Instance carrying only the asset’s overrides — properties and any present render-state fields. Otherwise builds a base material on

shaderHandle.

createInstance(source): number

Creates a material instance (UE MaterialInstanceConstant): it inherits

number

Parent material (a base material or another instance)

number

New instance handle

source’s shader, render state and parameters, and stores only the diffs you later set on it. Editing the parent propagates to every non-overriding instance. Use this for cheap variants (“the same material, but red”) instead of duplicating the whole material.

createShader(vertexSrc, fragmentSrc): number

Creates a shader from vertex and fragment source code.

string

GLSL vertex shader source

string

GLSL fragment shader source

number

Shader handle, or 0 on failure

get(material): MaterialData | undefined

Gets material data by handle.

number

Material handle

MaterialData | undefined

Material data or undefined

getBlendMode(material): BlendMode

Gets the blend mode of a material.

number

Material handle

BlendMode

Blend mode

getRenderState(material): Omit<ResolvedMaterial, "uniforms"> | null

Effective shader/render state without allocating or cloning uniform maps.

number

Omit<ResolvedMaterial, "uniforms"> | null

getShader(material): number

Gets the shader handle for a material.

number

Material handle

number

Shader handle

getSwitch(material, name): boolean

Gets an enabled static switch (false when unset).

number

string

boolean

getUniform(material, name): UniformValue | undefined

Gets a uniform value from a material.

number

Material handle

string

Uniform name

UniformValue | undefined

Uniform value or undefined

getUniforms(material): Map<string, UniformValue>

Gets all uniforms from a material.

number

Material handle

Map<string, UniformValue>

Map of uniform names to values

isValid(material): boolean

Checks if a material exists.

number

Material handle

boolean

True if material exists

release(material): void

Releases a material (does not release the shader).

number

Material handle

void

releaseAll(): void

void

releaseShader(shader): void

Releases a shader.

number

Shader handle to release

void

renderPreview(material, w, h, shape?): Promise<ImageData | null>

Render a material offscreen at

number

number

number

number

number

Promise<ImageData | null>

w×@p h and resolve with its pixels, through the real viewport path, lit by one directional light. shape.mesh (a loaded mesh handle) draws it on that geometry, seen off-axis and framed; without, a sprite shader samples shape.texture on a flat quad. Null if the engine isn’t ready or the readback fails.

setBlendMode(material, mode): void

Sets the blend mode for a material.

number

Material handle

BlendMode

Blend mode

void

setCull(material, cull): void

Sets the triangle culling mode.

number

CullMode

void

setDepthBias(material, units): void

How far toward the eye this surface is pushed, in depth-buffer units — what makes a decal win against the wall it is laid on. Negative is toward the eye; 0 leaves the surface where its geometry puts it.

number

number

void

setDepthTest(material, enabled): void

Sets depth test enabled for a material.

number

Material handle

boolean

Whether depth test is enabled

void

setDepthWrite(material, enabled): void

Enables/disables depth writes (default on, matching the engine’s 2D state).

number

boolean

void

setSwitch(material, name, on): void

Sets a static switch on the record. The shader permutation is chosen at compile time, so a change takes effect when the material’s shader is next (re)compiled — callers that need it live recompile the shader with the new switch set.

number

string

boolean

void

setUniform(material, name, value): void

Sets a uniform value on a material.

number

Material handle

string

Uniform name

UniformValue

Uniform value

void

tex(textureId, slot?): TextureRef

number

number

TextureRef

toAssetData(material, shaderPath, parentPath?): MaterialAssetData | null

Exports material to serializable asset data.

number

Material handle

string

Shader file path for asset reference

string

MaterialAssetData | null

Material asset data