Skip to content

Materials ​

A model is drawn with the materials the client makes of its file's: lit as the client's own shapes (standard) or as its maker made them (pbr, ModelDef.materials), with the fog of war, the mist, the lamps, the level fades, the see-through and the glow put on each. A look can change those materials by name: a colour, a picture, what shines, metal and roughness, both sides. Every copy of the model takes it: a unit up close and far off, a building's copies, the scenery.

Change materials through the look (or client.renderer.kit.setMaterial for one unit): the renderer (@v12-engine/render) draws batches of the client's own materials, and has no scene of meshes to set a material on by hand.

Quick start ​

ts
const view: GameView = {
	units: {
		looks: {
			knight: {
				height: 2,
				shapes: [],
				model: {
					src: 'characters/knight.glb',
					scale: 0.7,
					material: {
						// by the material's name in the file
						armor: { color: [0.9, 0.75, 0.3], metallic: 1, roughness: 0.35 },
						// '*' is every material of the file: a name's own is laid over it
						'*': { emissive: [0.05, 0.05, 0.1] }
					}
				}
			}
		}
	}
}

The names are the file's materials: the editor's Material panel lists them with the meshes drawn with each, and modelAnatomy(bytes).materials does in code.

Common tasks ​

Give one unit a material of its own ​

ts
const { kit } = client.renderer
kit.setMaterial(hero.id, 'armor', { color: [1, 0.8, 0.2], emissive: [0.3, 0.2, 0] }) // gold armour
kit.setMaterial(hero.id, 'armor', null) // as its look says again

The unit is drawn again at once with its model's materials and these over them, its clip going on from its pose. It is undone as the unit is dressed anew: another model, another owner, its look changed.

Use a picture of your own ​

ts
material: { armor: { texture: 'armor/gold.png', normalTexture: 'armor/gold-normal.png' } }

Paths are under textures/ (or an address). A picture of your own is not painted in the owner's colour: the cells of ModelDef.team are painted on the file's picture. A normal map uses the model's tangents where it has them, and turns by the screen's derivatives where it has none.

A shader of your own ​

A material in code of the game's (a plugin into the client's shaders, a node graph) is not taken by the looks: the renderer's materials are WGSL of its own kinds (MaterialKind, @v12-engine/render). What a game can draw with a shader of its own is a pass over the whole picture (Lighting › Passes of your own); a shape of its own in a colour is the render kit's (kit.draw, Drawing your own).

Editor ​

The Material panel (right rail, Look panel) picks a unit type with a model, lists its file's materials with the meshes drawn with each, and sets what the look says of one: colour, shine, highlights, pictures, opacity, metal, roughness. Each change is a step of the history (Ctrl+Z), drawn in the scene at once and written to looks.json with the map (Ctrl+S).

Reference ​

MaterialDef ​

FieldTypeWhat it does
color[r, g, b] 0..1Diffuse (standard) or albedo (PBR) colour, times the picture
emissive[r, g, b] 0..1What it shines of itself; glows as ModelDef.glow says
texturepath in textures/Its picture in place of the file's
emissiveTexturepath in textures/A picture of what shines
normalTexturepath in textures/A normal map
alpha0..1How opaque; under 1 is blended
specular[r, g, b] 0..1Highlights, a standard material's
metallic, roughness0..1A PBR material's
backFacesbooleanBoth sides drawn and lit

API ​

NameWhat it does
ModelDef.materialThe look's materials, by the file's names, '*' for every one
client.renderer.kit.setMaterial(id, name, def | null)One unit's own, over its model's
materialDefOf(model, name)What a model's look says of a material, '*' under the name's own
EVERY_MATERIAL'*'