Skip to main content

Material

Description

This component creates a standard PBR material on an entity with geometry.

Properties

PropertyTypeDefaultDescription
rnumber0Red channel value of the material. A value between 0 and 255.
gnumber0Green channel value of the material. A value between 0 and 255.
bnumber0Blue channel value of the material. A value between 0 and 255.
textureSrcstring''The color map source, modulated by color (if set)
roughnessnumber0.5How rough the material appears. A value between 0 and 1.
roughnessMapstring''This texture map resource, affects how rough the material appears
metalnessnumber0.5How metallic the material appears. A value between 0 and 1.
metalnessMapstring''This texture resource affects how metal the material appears
normalScalenumber1How much the normal map (if set) affects the material. A value between 0 and 1.
normalMapstring''Normal map source of the texture
opacitynumber1Overall alpha/transparency of the material. A value between 0 and 1.
opacityMapstring''Alpha/transparency mapped via a texture resource
emissiveIntensitynumber0Overall intensity of the emissive map. A value between 0 and 1.
emissiveMapstring''Emissive strength mapped as a texture resource. Modulated by emissive color and intensity.
emissiveRnumber0Red channel emissive color of the material. A value between 0 and 255.
emissiveGnumber0Green channel emissive color of the material. A value between 0 and 255.
emissiveBnumber0Blue channel emissive color of the material. A value between 0 and 255.
sidestring'front'Which sides of faces will be rendered. Allowed values: 'front', 'back', 'double'.
blendingstring'normal'Blending to use when displaying objects with this material. Allowed values: 'no', 'normal', 'additive', 'subtractive', 'multiply'.
repeatXnumber1How many times a texture is repeated across a material on the X axis
repeatYnumber1How many times a texture is repeated across a material on the Y axis
offsetXnumber0How much a texture is offset across a material on the X axis
offsetYnumber0How much a texture is offset across a material on the Y axis
depthTestbooleantrueWhether to test depth when rendering this material
depthWritebooleantrueWhether rendering this material impacts the depth buffer
wireframebooleanfalseRender geometry as wireframe
forceTransparentbooleanfalseWhether to force the alpha channel to render as transparent
mipmapsbooleantrueWhether to generate mipmaps for textures
textureFilteringstring'smooth'Texture filtering mode. Allowed values: 'smooth' or 'sharp'.
wrapstring'repeat'Wrapping mode for textures. Allowed values: 'clamp', 'repeat', 'mirroredRepeat'.

Functions

Get

Returns a read-only reference.

Example

ecs.Material.get(world, component.eid)

Set

Ensures the component exists on the entity, then assigns the (optional) data to the component.

Example

ecs.Material.set(world, component.eid, {
r: 255,
g: 0,
b: 0
})

Mutate

Perform an update to the component within a callback function. Return true to indicate no changes made.

Example

ecs.Material.mutate(world, component.eid, (cursor) => {
cursor.roughness = 0.8;
cursor.wireframe = true;
return false;
})

Remove

Removes the component from the entity.

Example

ecs.Material.remove(world, component.eid)

Has

Returns true if the component is present on the entity.

Example

ecs.Material.has(world, component.eid)

Reset

Adds, or resets the component to its default state.

Example

ecs.Material.reset(world, component.eid)

Advanced Functions

Cursor

Returns a mutable reference. Cursors are reused so only one cursor for each component can exist at a time.

Example
ecs.Material.cursor(world, component.eid)

Acquire

Same behavior as cursor, but commit must be called after the cursor is done being used.

Example
ecs.Material.acquire(world, component.eid)

Commit

Called after acquire. An optional third argument determines whether the cursor was mutated or not.

Example
ecs.Material.commit(world, component.eid)
ecs.Material.commit(world, component.eid, false)

Dirty

Mark the entity as having been mutated. Only needed in a specific case where systems are mutating data.

Example
ecs.Material.dirty(world, component.eid)