Skip to content

Materials

Updated

A material decides how a mesh’s surface looks: its colour, how it reacts to light, whether it is see-through, shiny, glowing or reflective. In MIRA each kind of material is a component, and an entity holds one of them. This page explains how materials work, lists every kind with its props, and shows how scripts change them safely and cheaply.

  • Meshes. A material is drawn on a mesh: a primitive or a loaded model. See Models and meshes.
  • Lights. Most materials are lit: they look the way the scene’s lights make them look. With no lights, a lit material is black. See Lighting.
  • Props and setProps. Every component’s settings are its props. Scripts read component.props and change them with component.setProps({ … }). See Components.
  • One per entity. Every material kind shares one slot on the entity. Adding another kind replaces the one there. getComponent(MaterialComponent) returns whichever kind the entity has.
  • Required on primitives. A Primitive Mesh and a Floor always have a material. It cannot be removed, only replaced; a new one starts with a Standard material. Disabling it hides the mesh until it is enabled again.
  • Optional on models. On a loaded model a material is an override, drawn on every mesh of the model instead of the materials stored in the file. Without one, the model keeps its own materials. See Models and meshes.
  • Built on change. The GPU material is rebuilt only when the component or its props change, never per frame on its own. Each setProps call costs one rebuild.
  • Networked. Each kind can be replicated to other players as a network trait, such as NetworkTraitType.StandardMaterial. See Multiplayer.
Material Script global Type Use it for
Basic BasicMaterialComponent comp-basic-material Unlit flat colour, ignoring every light; the cheapest. Signs, UI-like props, stylized scenes.
Lambert LambertMaterialComponent comp-lambert-material Cheap matte lit surfaces, good on phones and headsets.
Phong PhongMaterialComponent comp-phong-material Shiny highlights, cheaper than Standard.
Standard StandardMaterialComponent comp-standard-material Physically based metal and roughness: the default for most surfaces.
Physical PhysicalMaterialComponent comp-physical-material Standard plus clearcoat, transmission, sheen and iridescence: car paint, fabric, soap bubbles.
Normal NormalMaterialComponent comp-normal-material Colour by the direction a surface faces, no lights: debugging and sci-fi looks.
Glass GlassMaterialComponent comp-glass-material Ready-made see-through glass.
Shader ShaderMaterialComponent comp-shader-material A shader: a preset (hologram, toon, fire aura, frozen, …) or your own code. See Shaders.
Reflector ReflectorMaterialComponent comp-reflector-material Floors and mirrors with a live reflection of the scene.
Matte Shadow MatteShadowMaterialComponent comp-matte-shadow-material An invisible surface that shows only shadows: AR floors.

A good rule of thumb: start with Standard. Drop to Lambert or Basic for many objects on phones and headsets, and reach for Physical, Glass or Reflector only where the extra look matters.

Every kind except Glass has these props:

Prop Type Default Description
color string | number '#ffffff' Base colour, a hex string such as '#ff8800' or a number such as 0xff8800.
opacity number 1 0 to 1. Below 1 the material is drawn transparent.
wireframe boolean false Draw the triangle edges only.
side 'front' | 'back' | 'double' 'front' Which faces render. 'double' shows both sides of flat shapes.

Unlit: it shows its colour as it is, whatever the lights. It has the shared props only.

Matte, lit per vertex.

Prop Type Default Description
emissive string | number '#ffffff' Colour the surface gives off, unaffected by light.
emissiveIntensity number 0 Strength of emissive, 0 to 1000. Values above 1 are valid and glow under bloom.
flatShading boolean false Shade each face flat instead of smoothly.

Emission is off until emissiveIntensity rises above 0. Changing emissive alone never switches it on. The same holds for Phong, Standard, Physical and Reflector.

Classic shiny highlights. Lambert’s props, plus:

Prop Type Default Description
specular string | number '#111111' Colour of the highlight.
shininess number 30 0 to 1000: how tight and sharp the highlight is.

Physically based: you describe what the surface is (rough or smooth, metal or not), and the lighting follows. Lambert’s props, plus:

Prop Type Default Description
roughness number 0.8 0 mirror-smooth to 1 fully rough.
metalness number 0 0 non-metal to 1 metal. Real materials are almost always 0 or 1.

Standard’s props, plus layers for special surfaces:

Prop Type Default Description
clearcoat number 0 0 to 1: a clear lacquer layer on top, as on car paint.
clearcoatRoughness number 0 0 to 1: roughness of the clearcoat.
transmission number 0 0 to 1: how much light passes through, with refraction. Use with opacity 1.
thickness number 0 Thickness of the volume under the surface, for transmission, 0 to 10000 metres; 0 is thin-walled.
ior number 1.5 Index of refraction, 1 to 2.333. Water is about 1.33, glass 1.5.
sheen number 0 0 to 1: soft fabric sheen, as on velvet.
sheenColor string | number '#ffffff' Colour of the sheen.
sheenRoughness number 1 0 to 1: roughness of the sheen.
iridescence number 0 0 to 1: thin-film rainbow, as on soap bubbles.
specularIntensity number 1 0 to 1: strength of the non-metal specular reflection.
specularColor string | number '#ffffff' Tint of the non-metal specular reflection.

Colours each surface by the direction it faces, with no lights. color does not apply.

Prop Type Default Description
flatShading boolean false Shade each face flat.

Ready-made glass: a tint and an opacity, with everything else set for glass. What is behind it shows through, filtered by its tint, under a sharp clear coat that reflects the environment; at grazing angles the reflection takes over. It is smooth, front faces only and never wireframe. Glass has only these two props; any other prop is dropped.

Prop Type Default Description
color string | number '#ffffff' The tint: how much of each colour it lets through.
opacity number 0.9 0 to 1. How strongly the glass tints what is behind it and shows its reflection.

Glass draws each mesh three times, over its own pixels only, and never redraws the scene behind it, so it costs the same in a mirror, under water and in each eye of a headset. Nothing seen through it bends: for real refraction use a Physical material with transmission, which costs one more draw of the opaque scene for every view that sees it.

The Standard material with a live mirror-like reflection of what stands over it. A plane with strength 1, roughness 0 and blur 0 is a perfect mirror. Standard’s props (with roughness defaulting to 0.2), plus:

Prop Type Default Description
strength number 0.5 0 to 1: how much it reflects. At 1 it shows only the reflection, tinted by color.
blur number 1 0 to 1: softness of the reflection. 0 keeps it sharp and skips the blur passes.
fade number 0 Metres, 0 to 10000: objects higher above the surface fade out over this distance, so only what is near the surface shows. 0 is no fade.
quality 'low' | 'medium' | 'high' 'medium' Reflection texture size: 256, 512 or 1024 pixels square.
  • The reflecting face is the mesh’s flattest side, on its positive side: a floor box’s top, a plane’s front. Other faces show the plain lit material.
  • Free when unseen. Nothing is drawn when the surface is off screen, hidden, disabled, or the camera is behind it.
  • Cost while seen. One more draw of the scene at its quality, at most once a frame per surface, plus two small blur passes when blur is above 0. In a headset it draws once, shared by both eyes.
  • No recursion. A reflector seen in another reflector shows its plain surface, so facing mirrors never reflect each other. Outlines are not reflected.
  • A Reflector is never batched by a Cache Mesh.

An invisible shadow catcher: it shows only the shadows other objects cast on it. Put it on a floor so an object placed in AR, or over a photo, video or sky, is grounded by a real shadow. color and opacity are the shadow’s, and default to '#000000' at 0.5.

It always receives and never casts shadows, but its entity still needs an enabled Shadow component, and some light must cast shadows. See Lighting.

ComponentTypeWhat it does
Basic Materialcomp-basic-materialUnlit flat color that ignores lights.
Lambert Materialcomp-lambert-materialCheap matte lit material for non-shiny surfaces.
Phong Materialcomp-phong-materialClassic shiny highlights, cheaper than Standard.
Standard Materialcomp-standard-materialPhysically based metal/roughness material; the default for most surfaces.
Physical Materialcomp-physical-materialStandard plus clearcoat, transmission, sheen and iridescence.
Normal Materialcomp-normal-materialColors surfaces by the way they face; for debugging or sci-fi looks.
Glass Materialcomp-glass-materialReady-made see-through glass.
Reflector Materialcomp-reflector-materialA surface with a live mirror reflection of the scene.
Matte Shadow Materialcomp-matte-shadow-materialAn invisible surface that only shows the shadows cast on it, a shadow catcher.
Shader Materialcomp-shader-materialDraws its mesh with a shader: a preset, or code written with pragmas and hooks.
  • Read the current values from material.props, such as material.props.color.
  • Change them with material.setProps({ color: '#ff8800' }). Each call rebuilds the material once, so group several changes into one call.
  • Replace the kind with entity.addComponent(new GlassMaterialComponent({ … })). The new kind takes the shared slot and the old one is removed.
  • Find it with entity.getComponent(MaterialComponent) when you do not know the kind, or with the specific class when you need its own props.

The live example shows a box whose material colour changes on click.

The entity Crate has a Selectable and a Signal Emitter with the signal crate/clicked. Place the Behavior entity under the crate.

Recolor.jx
#pragma lifecycle(startup)
const PALETTE = ['#ef4444', '#f59e0b', '#22c55e', '#3b82f6', '#a855f7'];
let next = 0;
function startup() {
const material = self.parent.getComponent(MaterialComponent);
on('crate/clicked', (event) => {
if (event.eventType !== EventType.Selectable.Select) return;
findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again
material.setProps({ color: PALETTE[next] });
next = (next + 1) % PALETTE.length;
});
}
  • getComponent(MaterialComponent) finds the material whatever its kind, so this script works on Basic, Standard, Physical and the rest.
  • The click arrives as a Selectable event on the crate’s signal. The script ignores the other events by checking eventType.
  • One setProps per click means one material rebuild per click: no cost between clicks.

A beacon that flashes its emissive glow on and off twice a second. Discrete changes like this are the cheap way to animate a material.

Beacon.jx
#pragma slot(ref=interval, type=Number, min=50, max=5000, default=500)
#pragma lifecycle(startup, disable, enable)
let material;
let glowing = false;
let cancel = null;
function blink() {
glowing = !glowing;
material.setProps({ emissiveIntensity: glowing ? 4 : 0 });
cancel = delay(blink, interval);
}
function startup() {
material = self.parent.getComponent(StandardMaterialComponent);
material.setProps({ emissive: '#ff3b30' });
blink();
}
function disable() {
if (cancel) cancel();
material.setProps({ emissiveIntensity: 0 });
}
function enable() {
blink();
}
  • #pragma slot adds an interval field (in milliseconds) to the editor, so designers can tune the speed without editing code.
  • getComponent(StandardMaterialComponent) asks for the Standard kind specifically, because the script uses its emissive props. It returns undefined if the entity has another kind.
  • emissive sets the glow colour once. Emission stays off until emissiveIntensity rises above 0; values above 1 make it bright enough to bloom.
  • delay(blink, interval) schedules the next flash and returns a function that cancels it. The disable hook cancels it and switches the glow off while the script is paused; enable starts again.
  • Avoid naming a variable on: it would hide the on global that listens to signals.

A common game effect: when something is hit, it flashes red for a moment. A loaded model has no material component of its own, so the script adds a temporary override and removes it again, which restores the model’s own materials. The model has a Signal Emitter with the signal enemy/hit, and some other script emits that signal when it is struck.

HitFlash.jx
#pragma lifecycle(startup)
const FLASH_MS = 120;
let flashing = false;
function startup() {
const enemy = self.parent;
on('enemy/hit', () => {
if (flashing) return;
flashing = true;
enemy.addComponent(new BasicMaterialComponent({ color: '#ff2020' }));
delay(() => {
enemy.removeComponent(enemy.getComponent(MaterialComponent));
flashing = false;
}, FLASH_MS);
});
}
  • addComponent(new BasicMaterialComponent({ … })) creates an override. On a model, one material is drawn on every mesh; an unlit Basic red reads clearly in any lighting.
  • removeComponent(…) takes the override away, and the model’s original materials come back untouched: they were only swapped out, never changed.
  • The flashing flag prevents a second flash from stacking on the first.
  • Do not use this on a Primitive Mesh: its material is required and cannot be removed. On a primitive, change color instead and change it back.

4. A paint configurator with Physical materials

Section titled “4. A paint configurator with Physical materials”

A product viewer with finishes the user picks from a dropdown in the editor, applied as one setProps each. The Behavior entity sits under the car body, which has a Physical material.

PaintFinish.jx
#pragma slot(ref=finish, type=Dropdown, items=["gloss", "metallic", "matte", "pearl"], default="gloss")
#pragma lifecycle(startup)
const FINISHES = {
gloss: { color: '#b91c1c', metalness: 0, roughness: 0.35, clearcoat: 1, clearcoatRoughness: 0.05, iridescence: 0 },
metallic: { color: '#1e3a8a', metalness: 1, roughness: 0.3, clearcoat: 1, clearcoatRoughness: 0.1, iridescence: 0 },
matte: { color: '#374151', metalness: 0, roughness: 0.9, clearcoat: 0, clearcoatRoughness: 0, iridescence: 0 },
pearl: { color: '#f5f5f4', metalness: 0, roughness: 0.4, clearcoat: 1, clearcoatRoughness: 0.1, iridescence: 0.6 },
};
function apply(name) {
if (!FINISHES[name]) return;
const body = self.parent;
let paint = body.getComponent(PhysicalMaterialComponent);
if (!paint) {
paint = new PhysicalMaterialComponent({});
body.addComponent(paint);
}
paint.setProps(FINISHES[name]);
log('Finish:', name);
}
function startup() {
apply(finish);
on('paint/finish', (data) => apply(data));
}
  • The Dropdown slot shows the four finishes in the editor; the chosen item is in finish.
  • Each finish is one object of props, so switching costs one material rebuild, however many props change.
  • If the body has another material kind, the script adds a Physical one, which replaces it in the shared slot.
  • clearcoat adds the lacquer layer of car paint; iridescence gives the pearl finish its colour shift.
  • apply ignores names it does not know, so a typo in a signal cannot break the material.
  • Other scripts or UI buttons can switch finishes at run time with emit('paint/finish', 'matte').
  • Animating a material every frame. Each setProps rebuilds the material. A tween that calls setProps every frame rebuilds it sixty times a second. Prefer a few discrete changes, or use a Shader Material whose uniform values update without a rebuild.
  • Splitting one change into many calls. setProps({ color }) then setProps({ roughness }) rebuilds twice. Pass both in one object.
  • Writing to props directly. material.props.color = 'red' changes nothing on screen. Use setProps.
  • Expecting glow without intensity. Setting emissive alone does nothing: emissiveIntensity starts at 0.
  • A black object. Lit materials need light. Add a light, or use a Basic material for unlit looks.
  • Asking for the wrong kind. getComponent(StandardMaterialComponent) returns undefined on an entity with a Lambert material. Use MaterialComponent when any kind will do.
  • Transmission with low opacity. A Physical material’s transmission is meant for opacity 1; lowering opacity as well makes the surface doubly faint.
  • Too many reflectors. Each visible Reflector draws the scene again. Use one mirror floor per view, keep quality at 'low' on phones and headsets, and set blur to 0 when you do not need softness.
  • Removing a primitive’s material. A Primitive Mesh’s material is required. Replace it with another kind instead.