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.
Before you start
Section titled “Before you start”- 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 itsprops. Scripts readcomponent.propsand change them withcomponent.setProps({ … }). See Components.
How materials work
Section titled “How materials work”- 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
setPropscall costs one rebuild. - Networked. Each kind can be replicated to other players as a network trait, such as
NetworkTraitType.StandardMaterial. See Multiplayer.
Choosing a material
Section titled “Choosing a material”| Material | Script global | Type | Use it for |
|---|---|---|---|
| Basic | Basic |
comp- |
Unlit flat colour, ignoring every light; the cheapest. Signs, UI-like props, stylized scenes. |
| Lambert | Lambert |
comp- |
Cheap matte lit surfaces, good on phones and headsets. |
| Phong | Phong |
comp- |
Shiny highlights, cheaper than Standard. |
| Standard | Standard |
comp- |
Physically based metal and roughness: the default for most surfaces. |
| Physical | Physical |
comp- |
Standard plus clearcoat, transmission, sheen and iridescence: car paint, fabric, soap bubbles. |
| Normal | Normal |
comp- |
Colour by the direction a surface faces, no lights: debugging and sci-fi looks. |
| Glass | Glass |
comp- |
Ready-made see-through glass. |
| Shader | Shader |
comp- |
A shader: a preset (hologram, toon, fire aura, frozen, …) or your own code. See Shaders. |
| Reflector | Reflector |
comp- |
Floors and mirrors with a live reflection of the scene. |
| Matte Shadow | Matte |
comp- |
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.
Shared props
Section titled “Shared props”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. |
Material kinds
Section titled “Material kinds”Unlit: it shows its colour as it is, whatever the lights. It has the shared props only.
The lights dim and come back every few seconds: the Standard sphere darkens with them, while the Basic material sphere keeps its full colour, because a Basic material is never lit.
Watch the left sphere darken with the lights while the Basic sphere on the right stays bright. Drag to orbit the camera, scroll to zoom.
Lambert
Section titled “Lambert”Matte, lit per vertex.
| Prop | Type | Default | Description |
|---|---|---|---|
emissive |
string | number |
'#ffffff' |
Colour the surface gives off, unaffected by light. |
emissive |
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.
A lantern made with Lambert materials, the cheap matte kind for phones and headsets: clicking it switches its emissive glow and a point light inside it on and off.
Click the lantern to light it, click again to put it out. Drag to orbit the camera, scroll to zoom.
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. |
Three Phong spheres, from dull to polished, and a ring that steps through the same shininess values every two seconds: the highlight tightens as `shininess` rises.
Watch the highlight on the ring sharpen and spread as it steps through the shininess values. Drag to orbit the camera, scroll to zoom.
Standard
Section titled “Standard”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. |
Physical
Section titled “Physical”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. |
clearcoat |
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. |
sheen |
number |
1 |
0 to 1: roughness of the sheen. |
iridescence |
number |
0 |
0 to 1: thin-film rainbow, as on soap bubbles. |
specular |
number |
1 |
0 to 1: strength of the non-metal specular reflection. |
specularColor |
string | number |
'#ffffff' |
Tint of the non-metal specular reflection. |
Normal
Section titled “Normal”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. |
Shapes coloured by the direction each surface faces, with a Normal material that needs no light; every three seconds the script switches them between smooth and flat shading.
Watch the colours follow each face as the shapes turn, and the switch between smooth and faceted shading. Drag to orbit the camera, scroll to zoom.
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.
A glass cube and a glass ring from the runtime's Glass Lake demo, under an outdoor sky: what stands behind shows through their tint, and the cube steps through clear, sea and amber tints.
Orbit around the glass to see the objects behind it through the tint and the sky reflected at grazing angles. Drag to orbit the camera, scroll to zoom.
Reflector
Section titled “Reflector”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 whenbluris 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.
The floor of the runtime's Dynamic Bones demo: a Reflector material that mirrors the shapes bobbing over it, fading their reflection with height. The script raises and lowers the reflection strength.
Watch the shapes bob over their reflections, and the floor turn from satin to mirror and back. Drag to orbit the camera, scroll to zoom.
Matte Shadow
Section titled “Matte Shadow”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.
| Component | Type | What it does |
|---|---|---|
| Basic Material | comp-basic-material | Unlit flat color that ignores lights. |
| Lambert Material | comp-lambert-material | Cheap matte lit material for non-shiny surfaces. |
| Phong Material | comp-phong-material | Classic shiny highlights, cheaper than Standard. |
| Standard Material | comp-standard-material | Physically based metal/roughness material; the default for most surfaces. |
| Physical Material | comp-physical-material | Standard plus clearcoat, transmission, sheen and iridescence. |
| Normal Material | comp-normal-material | Colors surfaces by the way they face; for debugging or sci-fi looks. |
| Glass Material | comp-glass-material | Ready-made see-through glass. |
| Reflector Material | comp-reflector-material | A surface with a live mirror reflection of the scene. |
| Matte Shadow Material | comp-matte-shadow-material | An invisible surface that only shows the shadows cast on it, a shadow catcher. |
| Shader Material | comp-shader-material | Draws its mesh with a shader: a preset, or code written with pragmas and hooks. |
A balloon floats over a day sky with no visible floor: a Matte Shadow material catches only its shadow, so it still reads as standing on the ground. The script bobs it so the shadow grows and shrinks.
Watch the shadow on the invisible ground follow the balloon. Drag to orbit the camera, scroll to zoom.
Scripting materials
Section titled “Scripting materials”- Read the current values from
material.props, such asmaterial.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.
Examples
Section titled “Examples”The live example shows a box whose material colour changes on click.
A box that spins every frame and takes a new colour when you click it: a Behavior script, a Selectable and a Signal Emitter.
Click the box. Drag to orbit the camera, scroll to zoom.
1. Recolour an object on click
Section titled “1. Recolour an object on click”The entity Crate has a Selectable and a Signal Emitter with the signal crate/clicked. Place the Behavior entity under the crate.
#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; });}Each click on the crate writes the next colour of a palette into its material's color prop.
Click the crate to change its colour. Drag to orbit the camera, scroll to zoom.
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
setPropsper click means one material rebuild per click: no cost between clicks.
2. A blinking warning light
Section titled “2. A blinking warning light”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.
#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();}A beacon that flashes its emissive glow on and off twice a second: a Behavior script changing a Standard Material from a timer.
Watch the beacon flash. Drag to orbit the camera, scroll to zoom.
#pragma slotadds anintervalfield (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 itsemissiveprops. It returnsundefinedif the entity has another kind.emissivesets the glow colour once. Emission stays off untilemissiveIntensityrises 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. Thedisablehook cancels it and switches the glow off while the script is paused;enablestarts again.- Avoid naming a variable
on: it would hide theonglobal that listens to signals.
3. Hit flash on a model
Section titled “3. Hit flash on a model”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.
#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); });}On enemy/hit, a script adds a red Basic Material to a loaded model for 120 ms, then removes it, which restores the model's own materials.
Press Hit to make the knight flash red. Drag to orbit the camera, scroll to zoom.
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
flashingflag 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
colorinstead 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.
#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));}A toy car under an outdoor sky changes its paint between gloss, metallic, matte and pearl: four Physical material looks, each applied with one setProps, from buttons that send the paint/finish signal.
Press Gloss, Metallic, Matte or Pearl and watch the clear coat, metal and iridescence change under the sky. Drag to orbit the camera, scroll to zoom.
- The
Dropdownslot shows the four finishes in the editor; the chosen item is infinish. - 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.
clearcoatadds the lacquer layer of car paint;iridescencegives the pearl finish its colour shift.applyignores 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').
Common mistakes
Section titled “Common mistakes”- Animating a material every frame. Each
setPropsrebuilds the material. A tween that callssetPropsevery 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 })thensetProps({ roughness })rebuilds twice. Pass both in one object. - Writing to
propsdirectly.material.props.color = 'red'changes nothing on screen. UsesetProps. - Expecting glow without intensity. Setting
emissivealone does nothing:emissiveIntensitystarts 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)returnsundefinedon an entity with a Lambert material. UseMaterialComponentwhen any kind will do. - Transmission with low opacity. A Physical material’s
transmissionis meant foropacity1; 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
qualityat'low'on phones and headsets, and setblurto 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.