Material

View source

Defines the base asset type for render material values.

Extend this class when defining a concrete material asset for a renderer. The base value supplies neutral defaults and an empty serialized form, so a subclass can add the state and behavior its renderer needs.

Examples

class CustomMaterial extends Material {
  vertex() { return 'vertex shader source' }
  fragment() { return 'fragment shader source' }
}

const material = new CustomMaterial()

Constructor


constructor()

Methods


vertex(): string

View source

Returns the vertex-stage shader source for this material.

The base implementation returns an empty string. Concrete material classes can override this method with their vertex source.

Returns

Empty source from the base implementation.

fragment(): string

View source

Returns the fragment-stage shader source for this material.

The base implementation returns an empty string. Concrete material classes can override this method with their fragment source.

Returns

Empty source from the base implementation.

staticdefault(): Material

View source

Creates the base material’s default asset value.

The base implementation returns a new Material. Concrete material classes should override this method when their default asset needs subtype-specific state.

Returns

A new base material.

staticserialize(_value: Material): object

View source

Converts a material to the base class’s serialized representation.

The base implementation ignores _value and returns a new empty object; it does not mutate the material. Concrete material classes can override this method with fields for their own asset data.

Parameters

NameDescriptionDefault
_value

Material value to serialize.

—

Returns

An empty serialized representation.

staticdeserialize(_value: unknown, out?: Material): Material

View source

Restores a material from the base class’s serialized representation.

The base implementation ignores _value. When out is provided, it returns that same object without changing it; otherwise it returns a new Material. Concrete material classes can override this method to populate their own fields.

Parameters

NameDescriptionDefault
_value

Serialized material value, ignored by the base implementation.

—
out?

Existing material to return unchanged.

...

Returns

out, or a new base material when out is omitted.