Skip to content

Material

const Material: object

Defined in: material.ts:302

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

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): Promise<ImageData | null>

Render a material to an offscreen

number

number

number

Promise<ImageData | null>

w×@p h target and resolve with its pixels (a “material ball” thumbnail). Reuses the real viewport render path — a unit quad lit by one directional light — so the preview matches how the material looks in-scene. The readback rides the engine’s async seam: immediate on GL, resolved when the staging-buffer map lands on WebGPU — one awaited call either way. 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

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