Back to the referenceMaterials
Surfaces, custom shaders, and the file format shaders are written in.
57 symbols
#anodizedfunctionnacatamalon
anodized(options: TMaterialRecipeOptions) => TMaterialRecipe
Anodized metal: chrome in a colour, the blue, red or violet aluminium of a bike part, a phone, a
futuristic interface. Give it any tint.
A metal reflects in its own colour (reflection.metal: 1) and shines in it too (specular its
own colour): shininess: 120, reflection front: 0.8, edge: 1, metal: 1.
Parameters
optionsTMaterialRecipeOptionsIts colour (a blue by default) and the surroundings it reflects.
Example
declare const studio: TTexture;
createMaterial(anodized({ tint: '#a02ad8', environment: studio }));
View source · materials/recipes.ts:413#brassfunctionnacatamalon
brass(options: TMaterialRecipeOptions) => TMaterialRecipe
Brass: a pale yellow metal, softer than gold. Instruments, door handles, the fittings of a ship.
A metal reflects in its own colour (reflection.metal: 1) and shines in it too (specular its
own colour): shininess: 60, reflection front: 0.7, edge: 1, metal: 1.
Parameters
optionsTMaterialRecipeOptionsIts colour (brass by default) and the surroundings it reflects.
Example
declare const studio: TTexture;
createMaterial(brass({ environment: studio }));
View source · materials/recipes.ts:389#carPaintfunctionnacatamalon
carPaint(options: TMaterialRecipeOptions) => TMaterialRecipe
Car paint, or any deep lacquer: its colour under a clear coat, a very tight shine and the
surroundings strong towards the edge, more than plastic. The sports car of every demo reel.
Options of a model's material, like plastic: shininess: 200, reflection front: 0.08,
edge: 1.
Parameters
optionsTMaterialRecipeOptionsIts colour (a deep red by default) and the surroundings it reflects.
Example
declare const studio: TTexture;
createMaterial(carPaint({ tint: '#1a3fb0', environment: studio }));
View source · materials/recipes.ts:203#ceramicfunctionnacatamalon
ceramic(options: TMaterialRecipeOptions) => TMaterialRecipe
Glazed ceramic: a pale colour, a very tight shine and a little more of the surroundings than
plastic, softer at the edge. A teapot, a tile, a figurine.
Options of a model's material, like plastic: reflection front: 0.06, edge: 0.7.
Parameters
optionsTMaterialRecipeOptionsIts colour (an off-white by default) and the surroundings it reflects.
Example
declare const studio: TTexture;
createMaterial(ceramic({ environment: studio }));
View source · materials/recipes.ts:130#chromefunctionnacatamalon
chrome(options: TMaterialRecipeOptions) => TMaterialRecipe
Chrome: nearly all of it is what it reflects, everywhere, with the lamp's spot on top. The logos,
the robots and the spaceships of the era's computer graphics. Without environment it has
nothing to reflect and reads as grey metal.
Options of a model's material, like plastic: reflection front: 0.9, edge: 1.
Parameters
optionsTMaterialRecipeOptionsIts colour (a cool grey by default, which shows where the reflection is thin) and
the surroundings it reflects.
Example
declare const studio: TTexture;
createMaterial(chrome({ environment: studio }));
View source · materials/recipes.ts:155#copperfunctionnacatamalon
copper(options: TMaterialRecipeOptions) => TMaterialRecipe
Copper: a warm, reddish metal, a little less of a mirror than gold. Pipes, pans, wires, robots.
A metal reflects in its own colour (reflection.metal: 1) and shines in it too (specular its
own colour): shininess: 70, reflection front: 0.75, edge: 1, metal: 1.
Parameters
optionsTMaterialRecipeOptionsIts colour (copper by default) and the surroundings it reflects.
Example
declare const studio: TTexture;
createMaterial(copper({ environment: studio }));
View source · materials/recipes.ts:366#feltfunctionnacatamalon
felt(options: TMaterialRecipeOptions) => TMaterialRecipe
Felt, or any cloth with a nap: no shine and almost nothing of the surroundings, only a soft sheen
of its own colour, lighter, where it turns away, as the fibres catch the light at the edge. The top
of a card table, a pool table, a hat, a stuffed toy.
Options of a model's material: a near-black specular with shininess: 6, reflection
front: 0, edge: 0.08, and a soft rim step in its own colour made lighter. The sheen does not
follow the lamp: the side away from it keeps a sheen at its edge too, as the era's renders gave it.
Parameters
optionsTMaterialRecipeOptionsIts colour (a card table's green by default) and the surroundings it reflects.
Example
declare const studio: TTexture;
createMaterial(felt({ tint: '#7a1626', environment: studio }));
View source · materials/recipes.ts:496#glassfunctionnacatamalon
glass(options: TMaterialRecipeOptions) => TMaterialRecipe
Glass: see-through, a tight shine, and the surroundings little in front and nearly all at the edge,
where what it reflects also makes it less see-through, so its outline shows. Without the bending
of what is behind it, as the era's renders mostly drew it.
Options of a model's material: alpha: 0.2 and transparent, shininess: 220, reflection
front: 0.1, edge: 1. A glass with nothing to reflect is a faint tint.
Parameters
optionsTMaterialRecipeOptionsIts colour (a pale blue by default) and the surroundings it reflects.
Example
declare const studio: TTexture;
createMaterial(glass({ environment: studio }));
View source · materials/recipes.ts:228#goldfunctionnacatamalon
gold(options: TMaterialRecipeOptions) => TMaterialRecipe
Gold: nearly all of it is what it reflects, tinted gold, with a gold shine. The trophy, the coin,
the idol of every adventure.
A metal reflects in its own colour (reflection.metal: 1) and shines in it too (specular its
own colour): shininess: 90, reflection front: 0.85, edge: 1, metal: 1.
Without environment it has nothing to reflect and reads as dull ochre.
Parameters
optionsTMaterialRecipeOptionsIts colour (gold by default) and the surroundings it reflects.
Example
declare const studio: TTexture;
createMaterial(gold({ environment: studio }));
View source · materials/recipes.ts:343#hologramfunctionnacatamalon
hologram(options: TMaterialRecipeOptions) => TMaterialRecipe
A hologram: see-through light, added to what is behind it rather than covering it, with a bright
rim where it turns away, the blue projection of every science-fiction film of the nineties. It
reflects nothing: it is light.
Options of a model's material: alpha: 0.5, transparent, blend: 'additive', a dim shine
and a strong rim step, which is where its light is. environment is not used.
Parameters
optionsTMaterialRecipeOptionsIts colour (a cyan by default) and the surroundings it reflects.
Example
declare const studio: TTexture;
createMaterial(hologram());
View source · materials/recipes.ts:309#icefunctionnacatamalon
ice(options: TMaterialRecipeOptions) => TMaterialRecipe
Ice: a block of it, pale and half see-through, a tight shine, the surroundings strong at the edge
and a cold glow along its outline, where light runs through it. An ice level, a frozen lake, a
crystal. Glass is a window; this is solid.
Options of a model's material: alpha: 0.7 and transparent, shininess: 160, reflection
front: 0.08, edge: 0.9, and a strong rim step in a pale cyan.
Parameters
optionsTMaterialRecipeOptionsIts colour (a pale blue by default) and the surroundings it reflects.
Example
declare const studio: TTexture;
createMaterial(ice({ environment: studio }));
View source · materials/recipes.ts:463#leatherfunctionnacatamalon
leather(options: TMaterialRecipeOptions) => TMaterialRecipe
Leather: a dark colour with a soft, low shine, wider than plastic's and grey rather than white, and
a little of the surroundings at the edge. A chair, a jacket, a book's cover, a ball.
Options of a model's material, like plastic: shininess: 24, a grey specular, reflection
front: 0.02, edge: 0.35.
Parameters
optionsTMaterialRecipeOptionsIts colour (a dark brown by default) and the surroundings it reflects.
Example
declare const studio: TTexture;
createMaterial(leather({ tint: '#1c1c20', environment: studio }));
View source · materials/recipes.ts:557#matcapfunctionnacatamalon
matcap(texture: TTexture, options: TMatcapOptions) => TMaterialRecipe
A matcap: a picture of a ball already lit (its colour, its shadow and its shine) that colours the
whole model by which way each part of it faces the camera. No lamp is needed, nor read: the light
is the painted one, so it always comes from the same side of the screen as the model turns, and a
scene of them is as cheap as it gets. The soft, toy-like look of a clay model or a product shot.
The picture is the ball seen from in front, round in its square, as a 3D program renders one or
paintMatcap paints one; any such picture loaded with useLoadTexture works.
Nothing but options of a model's material: lighting: unlitLighting() and a reflection of the
picture at full, front: 1, edge: 1, metal: 1, so the tint and the model's own picture
multiply it, and its alpha fades it as any surface's. A scene document keeps it when the picture
is a file. Steps go on top: groundBounce() for the floor's colour coming up, rim() for a lit
edge.
Parameters
textureTTextureThe matcap.
optionsTMatcapOptionsA colour to multiply it by.
Example
import { createMaterial, createMesh, matcap, useSphereGeometry } from 'nacatamalon';
import { createPixelTexture, paintMatcap } from 'nacatamalon/pixels';
import { groundBounce } from 'nacatamalon/shader';
const clay = createPixelTexture(paintMatcap({ base: '#e2414b' }));
createMesh({ geometry: useSphereGeometry(), material: createMaterial(matcap(clay)) });
createMaterial({ ...matcap(clay), steps: [groundBounce({ color: '#ff7a33' })] });
View source · materials/recipes.ts:635#neonfunctionnacatamalon
neon(options: TMaterialRecipeOptions) => TMaterialRecipe
A lit neon tube: it glows its own colour, whatever lights it, with a little of the surroundings
at the edge, the glass of the tube. In the CGI style (RENDER.STYLES.cgi) the bloom makes it glow
round itself.
Options of a model's material: emissive its own colour, shininess: 60, reflection
front: 0.02, edge: 0.3.
Parameters
optionsTMaterialRecipeOptionsIts colour (a hot pink by default) and the surroundings it reflects.
Example
declare const studio: TTexture;
createMaterial(neon({ tint: '#3cf0ff' }));
View source · materials/recipes.ts:253#paperfunctionnacatamalon
paper(options: TMaterialRecipeOptions) => TMaterialRecipe
Paper, or card: matte, a faint wide shine and almost nothing of the surroundings. A playing card, a
page, a box, a sign. What is printed on it is a picture given with a spread (texture), which the
tint multiplies: give a white tint for the picture's own colours.
Options of a model's material, like plastic: shininess: 6, a dark grey specular,
reflection front: 0, edge: 0.12.
Parameters
optionsTMaterialRecipeOptionsIts colour (an off-white by default) and the surroundings it reflects.
Example
declare const studio: TTexture;
declare const aceOfSpades: TTexture;
createMaterial({ ...paper({ tint: '#ffffff', environment: studio }), texture: aceOfSpades });
View source · materials/recipes.ts:583#pearlfunctionnacatamalon
pearl(options: TMaterialRecipeOptions) => TMaterialRecipe
Pearl, or satin: a soft pale surface whose rim turns another colour as it turns away, the shimmer
of mother-of-pearl, a bathroom of the era, a trophy.
Options of a model's material: shininess: 40, a rim step in a cool blue, reflection
front: 0.05, edge: 0.6. The rim is its own colour: change it with a spread and a rim() of
your own in steps.
Parameters
optionsTMaterialRecipeOptionsIts colour (an ivory by default) and the surroundings it reflects.
Example
declare const studio: TTexture;
createMaterial(pearl({ environment: studio }));
View source · materials/recipes.ts:278#plasticfunctionnacatamalon
plastic(options: TMaterialRecipeOptions) => TMaterialRecipe
Glossy plastic, the toy and the product shot of the era's computer graphics: its own colour, a
tight white shine, and the surroundings only towards its edge.
Nothing but options of a model's material (perPixel, specular, shininess and a reflection
that reflects little in front, 0.04, and much at the edge, 0.9), so what it does is what they
do, and any of it can be changed with a spread.
Parameters
optionsTMaterialRecipeOptionsIts colour (red by default) and the surroundings it reflects.
Example
import { createMaterial, createMesh, plastic, useSphereGeometry } from 'nacatamalon';
import { createPixelTexture, studioEnvironment } from 'nacatamalon/pixels';
const studio = createPixelTexture(studioEnvironment());
createMesh({ geometry: useSphereGeometry(), material: createMaterial(plastic({ tint: '#2a7bd8', environment: studio })) });
createMaterial({ ...plastic({ environment: studio }), shininess: 30 });
View source · materials/recipes.ts:107#rubberfunctionnacatamalon
rubber(options: TMaterialRecipeOptions) => TMaterialRecipe
Matte rubber: a wide, grey shine and almost nothing of the surroundings, a faint sheen at the edge.
Tyres, handles, the soft parts of a toy.
Options of a model's material, like plastic: shininess: 8, a grey specular, reflection
front: 0.01, edge: 0.25.
Parameters
optionsTMaterialRecipeOptionsIts colour (a near-black grey by default) and the surroundings it reflects.
Example
declare const studio: TTexture;
createMaterial(rubber({ tint: '#2a2a2e', environment: studio }));
View source · materials/recipes.ts:179#steelfunctionnacatamalon
steel(options: TMaterialRecipeOptions) => TMaterialRecipe
Steel, or iron: a grey metal that is not polished, a wide shine in its own colour and only some of
the surroundings, so it reads as metal without being a mirror. Machines, tools, weapons, robots,
the plates of a ship.
A metal reflects in its own colour (reflection.metal: 1) and shines in it too (specular its
own colour): shininess: 30, reflection front: 0.35, edge: 0.8, metal: 1.
Parameters
optionsTMaterialRecipeOptionsIts colour (a mid steel grey by default) and the surroundings it reflects.
Example
declare const studio: TTexture;
createMaterial(steel({ environment: studio }));
View source · materials/recipes.ts:438#useEnvironmentfunctionhooknacatamalon
useEnvironment(options: TEnvironmentOptions) => TEnvironment
The surroundings of a place, captured: the scene drawn round it as the six faces of a cube, for a
model of chrome to reflect the room it is really in, the columns and the torches and the floor,
rather than a picture of somewhere else. Give it to a material's reflection or to a recipe's
environment: createMaterial(chrome({ environment: useEnvironment({ around: hero }) })).
Seen from around (the model that reflects, which is left out of its own surroundings, so it does
not see the inside of itself), and followed as it moves. Captured once when the scene has loaded,
the way the games of the era baked their reflections, or every frame with live: true, so a torch
that flickers or someone walking past is in the reflection too. Live, it draws the scene six more
times a frame, with its shadows: one or two in a scene, not one per coin.
In the world's own axes, so one capture is right from wherever the camera looks. Its pictures are
drawn by code, so a scene document does not keep them.
Parameters
optionsTEnvironmentOptionsWhere it is seen from, how often, and how sharp.
Example
import { chrome, createMaterial, createModel, useEnvironment, useLoadModel } from 'nacatamalon';
const hero = createModel({ model: useLoadModel({ src: '/models/hero.glb' }) });
const room = useEnvironment({ around: hero, height: 1, live: true });
for (const part of hero.parts) part.material = createMaterial(chrome({ environment: room }));
View source · hooks/mirror/use_environment.ts:155#useMirrorfunctionhooknacatamalon
useMirror(options: TMirrorOptions) => TMirror
A mirror: the world reflected in a flat surface, a polished floor, a mirror on a wall, a lake.
Give what it returns to the surface as its reflection, and the surface shows the world as a mirror
lying on it would, moving with the camera, and more of it where it is seen low, as a real floor does.
Any flat model: a usePlaneGeometry, turned and placed as it should be, a floor as it is or a wall
stood up. Its plane is read from where it ends up each frame, so it can move. What is behind it is
never in it.
It draws the scene a second time, from the camera reflected across the plane, into a picture the
size of the game's screen (scale makes it smaller, for less). One mirror is one more drawing of
the scene, its lights and its shadows, every frame, on screen or not: a few in a scene are fine, one
per tile is not. A surface that shows its picture is never drawn in it, so it does not reflect
itself; two mirrors facing each other show each other once, not for ever.
It is the reflection seen through the scene's own 3D camera, on the screen. Anything else that sees
the surface (a view of a split screen, a picture, useEnvironment's faces) shows that same picture
at its own places on it, which is not its reflection. Not with a camera that follows the 2D one
(follow2d).
Its picture is drawn by code each frame, so a scene document does not keep it: the surface is saved
without its mirror. Best with perPixel: true on the surface, so its own light is round too.
Parameters
optionsTMirrorOptionsHow much it shows in front and at the edge, how much of its colour, how soft, and
how big its picture is.
Example
import { createMesh, useMirror, usePlaneGeometry } from 'nacatamalon';
// A polished floor, softened a little.
createMesh({
geometry: usePlaneGeometry({ width: 20, depth: 20 }),
tint: '#2a2622',
perPixel: true,
reflection: useMirror({ front: 0.25, blur: 2 }),
});
// A mirror on a wall: the plane stood up, facing the room.
createMesh({
geometry: usePlaneGeometry({ width: 2, depth: 3 }),
transform: { z: -5, y: 1.5, rotationX: Math.PI / 2 },
reflection: useMirror({ front: 0.9 }),
});
View source · hooks/mirror/use_mirror.ts:159#woodfunctionnacatamalon
wood(options: TMaterialRecipeOptions) => TMaterialRecipe
Varnished wood: its colour under a thin clear coat, a tight white shine and a little of the
surroundings, more towards the edge. A table's rail, a guitar, a cabinet.
Options of a model's material, like plastic: shininess: 80, reflection front: 0.04,
edge: 0.6. The grain is a picture of it given with a spread (texture), which the tint
multiplies: give a white tint for the picture's own colours.
Parameters
optionsTMaterialRecipeOptionsIts colour (a warm brown by default) and the surroundings it reflects.
Example
declare const studio: TTexture;
declare const grain: TTexture;
createMaterial(wood({ environment: studio }));
createMaterial({ ...wood({ tint: '#ffffff', environment: studio }), texture: grain });
View source · materials/recipes.ts:533#TCreateMaterialtypenacatamalon
TCreateMaterial: (options: TMaterialShaderOptions & { shader, texture, key, tint, emissive, emissiveTexture, occlusion, specular, shininess, alpha, transparent, blend, smooth, wrap, maps, vertexSnap, affine, perPixel, reflection, normalMap, uvTransform, cull, alphaCutoff, lighting, steps } & { uniforms }) => TShaderHalf & { shader, texture, tint, emissive, emissiveTexture, occlusion, specular, shininess, alpha, transparent, blend, smooth, wrap, maps, vertexSnap, affine, perPixel, reflection, normalMap, uvTransform, cull, alphaCutoff, lighting, steps } & { uniforms }
The ways to call createMaterial: which kind of material comes back follows from shader, so a
model's material can only be handed to a model and a sprite's only to a sprite.
Given uniforms (which compileShader always gives), the material's uniforms is typed as
there, so a parameter is animated with material.uniforms.glow = 1 and no ?? {}.
Plain overloads and no type parameter, so it is called from inside a function of your own that
takes its options as a type parameter, or with options typed as any kind of material, as readily
as with the options written in place; an option it does not have is still refused there. Options
that could be either kind give a material that could be either, to narrow by its shader.
View source · gameobjects/material/create_material.ts:76#TEnvironmenttypenacatamalon
What useEnvironment gives back: the surroundings for a material's reflection (or a recipe's
environment), and a way to draw them again.
Properties
textureTTextureThe six faces of a cube of the surroundings, three across and two down.
read'cube'How a reflection reads them: as a cube.
capturearoundindexedAccessWhere they are seen from, as around in the options: changed at any time, for a model made after
them, whose material needed them to be made.
View source · hooks/mirror/use_environment.ts:60#TEnvironmentOptionstypenacatamalon
What useEnvironment is asked for. Everything is optional.
Properties
aroundoptionalTMesh | TModel | TAroundDrawing | { x, y, z }Where the surroundings are seen from: the model that reflects them (a mesh, a model from a
file, or a plugin's drawing in depth), followed as it moves and left out of its own
surroundings, or a fixed point. Default the origin.
heightoptionalnumberHow far above around to see them from, so a character reflects the room from its chest and not
its feet. Default 0.
liveoptionalbooleanDrawn again every frame (true), so what moves round it is in its reflection, at the cost of
drawing the scene six more times a frame; or once, when the scene has finished loading, and
kept (false, the default), for a room that stays as it is. capture() draws it again.
sizeoptionalnumberHow many pixels across each of the six faces is. Default 128; 256 for a big, sharp mirror.
View source · hooks/mirror/use_environment.ts:28#TMatcapOptionstypenacatamalon
What matcap is asked for besides its picture.
Properties
tintoptionalTColorOptionA colour the matcap is multiplied by, so one white matcap colours many things. Left out, the
matcap's own colours.
View source · materials/recipes.ts:593#TMaterialtypenacatamalon
TMaterial: TSpriteMaterial | TMeshMaterial
A surface, a shader, or both, that one or many things can be drawn with.
Two shapes and not one with half its fields unused, because a field that means nothing half the
time is a field that lies. Which one you have is written on shader, so asking narrows it.
A material is an atomic value: nothing caches it and nothing looks it up by name. Two things
share one by being handed the same one.
View source · materials/types/t_material.ts:485#TMaterialMaptypenacatamalon
One extra picture a material carries for its shader to read, besides the picture it is drawn
with: a reflection, a mask, a fine detail, a ripple.
The shader reads it by name, sampleMap_<name>(uv), with the same wrap and filtering choices the
main picture has. A picture with mipmaps is read by a model's colour hook from the copy its size
on the screen asks for; sampleMapScaled_<name>(uv, scale) reads it at a place that runs scale
times as fast as the model's picture coordinate (see TMaterialOptions.maps).
Properties
textureTTextureThe picture. One still loading reads as white until it lands; what wears it is drawn meanwhile.
wrapoptionalTTextureWrap | { u, v }What the picture does past its edge. Default 'repeat'.
smoothoptionalbooleanHow it is read between pixels. Omitted, the material's own smooth decides.
View source · materials/types/t_material.ts:125#TMaterialNormalMaptypenacatamalon
A normal map: a picture whose colours are the directions a surface faces at each of its pixels, so a
flat wall catches the light as if it were carved, stone, brick, wood grain, rivets.
Properties
textureTTextureThe map: each pixel's colour a direction in the surface's own frame, red across the picture,
green up it, blue out of the surface (the usual lilac ones; normalsFromHeight makes one from a
picture of heights).
strengthoptionalnumberHow far it bends the surface: 0 flat, 1 as the map says, more to deepen it. Default 1. A
uniform, normalStrength, so it changes while the game runs.
View source · materials/types/t_material.ts:241#TMaterialOcclusiontypenacatamalon
How much of the light from all around reaches each part of a model's surface: a crease, an
armpit, the gap between two pieces, where little of the room can see in.
Its picture's red is how open a place is, white wide open and black shut in. It darkens only the
light from all around (the scene's ambient), never a lamp's or the sun's: a crease turned to the
sun is lit, and the same crease in the shade is darker than the open surface beside it. It is what
a model file calls its occlusion, the shading its author saw in the modelling program, and one
picture with the roughness and metalness in its other channels serves as it is.
Properties
textureTTextureThe picture, read in its red. One still loading reads as white, wide open, until it lands.
strengthoptionalnumberHow much of it is applied, 0 none to 1 all. Default 1.
uvoptional'uv' | 'uv2'Which picture coordinate it is laid out by: 'uv', the one the colour picture uses, or
'uv2', a second one the model file brings or createGeometry is given (shapes with none read
their first again).
Default 'uv'.
wrapoptionalTTextureWrap | { u, v }What the picture does past its edge, one word for both ways or one each: 'repeat',
'clamp' or 'mirror'. Omitted, what the colour picture does (the material's wrap). It is
read with the material's filtering.
View source · materials/types/t_material.ts:154#TMaterialOptionstypenacatamalon
TMaterialOptions: TSpriteMaterialOptions | TMeshMaterialOptions
What createMaterial is asked for. shader decides which of the two you are making.
View source · materials/types/t_material_options.ts:382#TMaterialRecipetypenacatamalon
TMaterialRecipe: TMeshMaterialOptions & { shader }
The options a recipe gives back: those of a model's material, ready for createMaterial or to be
opened with a spread and changed.
Properties
shader'mesh3d'Which of the engine's shaders it is built on, its family: 'mesh3d', the one that lights
models. Not your code: that is effect (or fragment), and its file says the same family on
its // @shader mesh3d line.
textureoptionalTTextureA picture for the surface, from useLoadTexture. One loaded with mipmaps: true is read far
away from a smaller copy of itself, so a floor running into the distance does not shimmer.
keyoptionalstringThe name a picture was loaded under, for a material built where the picture is not at hand.
tintoptionalTColorOptionMultiplies the picture, and is the whole colour without one. Default white.
emissiveoptionalTColorOptionLight it gives off by itself. Default none.
emissiveTextureoptionalTTextureA picture the glow comes through, multiplied by emissive: white where it glows, black where
it does not, the lit windows of a building or the screen of an arcade cabinet. Read with the
same edges and corners as texture. Default none, the glow the same all over.
occlusionoptionalTTexture | TMaterialOcclusionWhere the light from all around is kept out of its creases, the shading a modelling program
calls occlusion: a picture whose red is white where the surface is open and black where it is
shut in. It darkens only the scene's ambient, never a lamp or the sun. The picture alone, or
{ texture, strength, uv, wrap } to apply less of it, lay it out by a second picture coordinate
or give it edges of its own (see TMaterialOcclusion). Default none.
specularoptionalTColorOptionThe colour of its shine. Default none, which is matt.
shininessoptionalnumberHow tight that shine is. Default 32.
alphaoptionalnumberHow solid it is, 0 to 1. Default 1.
transparentoptionalbooleanDrawn as see-through even at full alpha: for a shader that works out its own alpha, or a
picture with see-through parts. Omitted, it is see-through when alpha or its tint's own is
below 1. A see-through model is drawn after the solid ones, furthest first, and hides nothing.
blendoptional'alpha' | 'additive'How it lands on what is behind it. 'alpha' (the default) covers it as far as its alpha says.
'additive' adds its colour instead, so it can only brighten: a flash, a hologram, a shield,
a beam of light, a magic circle. Its alpha says how much of it is added. An additive model is
always drawn as see-through (after the solid ones, hiding nothing, whatever transparent
says), casts no shadow, since light added blocks none, and fades into the fog by adding less
rather than by turning the fog's colour.
smoothoptionalbooleanOverrides the game's smooth for anything drawn with this.
wrapoptionalTTextureWrap | { u, v }What the picture does past its edge: 'repeat' (the default for a model) tiles it, 'mirror' tiles it
flipped every other time, and 'clamp' stretches its last row and column. A pair sets each
way on its own (u across, v down), which is how a fence repeats sideways and not upwards.
mapsoptionalRecord<string, TTexture | TMaterialMap>Extra pictures for the shader to read by name, up to four, each a texture or a texture with its
own wrap and smooth. In the shader, sampleMap_<name>(uv) reads the one under that name,
in the fragment hook and in the vertex hook alike (see vertex).
A picture made with mipmaps (useLoadTexture({ mipmaps: true })) is read in the fragment hook
from the copy its size on the screen asks for, judged by how the model's own ctx.uv runs
across the screen, inside a branch too. Read at a place that runs faster, say how much faster
with sampleMapScaled_<name>(uv, scale): sampleMapScaled_detail(ctx.uv * 8.0, vec2(8.0)).
Otherwise a picture repeated eight times is read eight times too sharp far away and shimmers.
A scale of vec2(0.0) reads the picture itself, for a place that does not follow the surface
(envUv(ctx)). sampleTexture and sampleTextureScaled do the same for texture. The vertex
hook always reads the picture itself.
vertexSnapoptionalboolean | numberIts corners land on a coarse grid of the screen, the way the PlayStation drew them: a model
shivers as it moves and its edges crawl as the camera turns. A number is how many rows the grid
has (120 is the classic look, smaller is wilder); true uses the game's own rows, which is
subtle. Left out, the scene's render style decides (useRenderStyle), and with none it is off;
false, or 0, says no to that style.
affineoptionalbooleanIts picture is stretched straight across the screen without correcting for depth, the way the
PlayStation drew it: big flat surfaces bend and swim as the camera comes close. Left out, the
scene's render style decides (useRenderStyle), and with none it is off; false says no to it.
perPixeloptionalbooleanIts light is worked out at every pixel rather than at its corners. The engine's own light is
worked out at the corners and smeared across each triangle, the way the consoles of the era
did it; a shine that falls between corners is lost, or comes out shaped like the triangles.
Worked out at every pixel, a shine is a round, clean spot that slides across the surface
however few triangles the model has: the look of the computer graphics of the time, glossy
plastic and chrome. It costs more per pixel, and a shader of your own receives that light in
ctx.light and ctx.shine without changing. It can be changed while the game runs. Left out,
the scene's render style decides (useRenderStyle), and with none it is off; false says no
to that style.
reflectionoptionalTTexture | TMaterialReflectionWhat its surface reflects: a round picture of its surroundings, and how much it reflects in
front and at the edge (see TMaterialReflection). The picture alone is a glossy plastic
(front: 0.04, edge: 1); front: 0.9 is chrome. It goes over the light, under the shine and
the glow, and with lighting and steps too. It makes part of the colour, so it is not given
with fragment or effect: a shader of your own reads a map at envUv(ctx) instead. The
picture takes the map reflection, one of the four, and the two numbers are the uniforms
reflectionFront and reflectionEdge. Default none.
normalMapoptionalTTexture | TMaterialNormalMapA normal map that bends its surface at every pixel, so a flat wall catches the light as carved
stone or brick would: the picture alone, or { texture, strength } (0 flat, 1 as the map
says, the default). It needs the model's tangents, which every built-in shape and model file has.
The material is lit at every pixel unless it says perPixel: false. The picture takes the map
normalMap, one of the four, and the strength is the uniform normalStrength. Not with an
effect from a file. Default none.
uvTransformoptionalTMaterialUvTransformIts picture laid moved from where its shape puts it: repeated (scale), turned (rotation)
and slid (offset), in that order, as a model file's own are. It moves everything laid by the
first picture coordinate: the picture, its glow (emissiveTexture), its normal map (laid the
new way round, so its relief leans right), an occlusion laid by it, and what a hook of your own
reads at ctx.uv. What is laid by the second (occlusion: { uv: 'uv2' }, ctx.uv2) stays.
Read every frame from material.uvTransform, so a game changes it while it runs: growing
offset.x scrolls a river. The material is drawn with the engine's own ending as its colour
hook, as one with a normal map is, and the two numbers it is drawn with are the uniforms
uvTransformMatrix and uvTransformOffset, written by the engine. Not with an effect from a file. Default none.
culloptionalTCullModeWhich side of its triangles is thrown away. 'back' (the default) is a shape seen from
outside; 'front' one seen from inside, such as a dome of sky; 'none' draws both sides, each
lit as the side it is, for a leaf, a sheet or the top of a liquid. A colour hook tells the two
sides apart with ctx.frontFacing.
alphaCutoffoptionalnumberCuts its picture out instead of blending it: a pixel whose alpha is below this number is not
drawn, every other one is drawn solid. For a fence, a leaf, grass or a paper figure, which then
hides what is behind it and casts the shadow of its shape. 0.5 is the usual; from 0 to 1.
Omitted, nothing is cut.
lightingoptionalTLightingLookHow the surface is lit, in place of the engine's light: toonLighting() (flat bands) or unlitLighting() (no
light at all). One only. Its numbers become uniforms of the material (toonShadow...), so they can
be turned while the game runs. It makes the colour, so it is not given with fragment or
effect; a vertex hook may go with it.
stepsoptionaltypeOperatorWhat is done to the surface once it is lit, in order: mangaDots() (ink in the shadow),
rim() (a lit edge), groundBounce() (the ground's colour coming up). On lighting when
there is one, on the engine's light when not. Their numbers become uniforms too
(mangaDotsSize, rimColor; a second of one kind is rim2Color).
nameoptionalstringA name, which is what a warning about this material will call it.
fragmentoptionalstringThe fragment hook, in WGSL.
For a model, fn effect(surface: vec4<f32>, ctx: FragContext) -> vec4<f32>, where ctx has:
uv; normal, worldPos and viewDir in the world; cameraPos, where the camera stands
in the world, so distance(ctx.cameraPos, ctx.worldPos) is how far away this is; light, shine and emissive, the
light reaching it already worked out; color, the colour painted on the corners; screen,
where it is on the screen in the game's pixels, (0, 0) at the top left; tangent and
bitangent, the way across and down the surface the picture runs, in the world; uv2, a
second picture coordinate (the file's own or createGeometry's uv2, or uv again; stretched
as uv is when affine);
frontFacing; carry, what the corner hook carried here (see vertex); and occlusion, how
open the place is to the light from all around, 1 to 0 (see occlusion, already in light).
The corner hook's VertContext has normal, uv, color, tangent, bitangent and uv2,
before anything is moved, and, on a model drawn as many (createMeshInstances), instance,
the four numbers of the instance the corner belongs to, and origin, where that instance
stands; both are zeros on a single model.
fragmentGlsloptionalstringThe same hook in GLSL, without which the effect is WebGPU only: on WebGL2 the material draws
with the built-in shader and says so once. To write it once for both cards, build it with the
shader composer (compileShader), which gives fragment and fragmentGlsl together.
vertexoptionalstringThe vertex hook, in WGSL: fn vertex(pos: vec3<f32>, ctx: VertContext) -> vec3<f32>, where the
corner ends up. 3D only: a sprite is a flat square and has nothing to move.
On a model drawn as many (createMeshInstances) it runs after the instance has placed the
corner: pos, ctx.normal and ctx.tangent are in the space the whole group stands in, so a
wind crossing a meadow is one direction for every blade, and pos.y - ctx.origin.y is how far
up its own instance a corner is.
It can also hand four numbers on to the fragment hook by writing them into carry
(carry = vec4<f32>(lift, 0.0, 0.0, 0.0);, carry = vec4(lift, 0.0, 0.0, 0.0); in GLSL),
which reads them as ctx.carry, smeared across the triangle: how high a wave lifted a corner, for foam on its
crests; a light of its own worked out at the corners, the look of the era; pos itself, where
the corner is in the model's own space, for bands or a fill line that stay on the model as it
moves and turns.
Nothing written is zeros.
It can also say which way the surface faces at the corner, for the light, by writing it into
surfaceNormal (surfaceNormal = vec3<f32>(0.0, 1.0, 0.0);), in the space pos is in: a blade
of grass lit as if it faced up rather than sideways, a flat card lit as if it were round. It is
brought back to length one. Nothing written, the surface is measured where the hook moved it
(below). The composer's compileShader({ normal }) writes it.
It reads the material's uniforms (mu) and its maps (sampleMap_<name>(uv)), so a picture can
move the corners: a height map, footprints pressed into snow, ripples drawn into a texture. The
surface is measured again where the hook moved it, by calling it at two places beside each
corner with the same ctx, and lit by that. So read a map at a place worked out from pos,
not at ctx.uv: read at ctx.uv, the places beside it rise just as much, and the moved surface
is lit as if it were still flat. On a plane width by depth,
pos.xz / vec2<f32>(width, depth) + 0.5 is its uv. Give a height map smooth: true in
maps: read pixel by pixel (the game's default), each pixel is a flat step, and the surface
comes out in terraces lit flat, with walls where one step meets the next.
vertexGlsloptionalstringThe same, in GLSL, without which the corners are not moved on WebGL2. compileShader gives
both from one graph, as for fragmentGlsl.
uniformsoptionalTUniformValuesThe uniforms, with the values they start at. Their kinds are read off these, and fixed from then
on, because how they are packed for the card depends on them.
Kept as given, not copied: the object you pass in is the one the renderer reads, so writing a
number into it is read by the next frame. That is how a shader is driven by the game, and it
is the same rule a text's style follows.
effectoptionalTShader | stringA file from useLoadShader, or the name one was loaded under.
View source · materials/recipes.ts:36#TMaterialRecipeOptionstypenacatamalon
What a material recipe is asked for: its colour, and the surroundings it reflects. Both optional.
Properties
tintoptionalTColorOptionIts colour. Each recipe has its own when this is left out.
environmentoptionalTTexture | { texture, read }The surroundings it reflects: a round picture of them (studioEnvironment paints one, useStudio
gives one), or the scene around it captured with useEnvironment. Left out, it shines but
reflects nothing.
View source · materials/recipes.ts:15#TMaterialReflectiontypenacatamalon
What a model's surface reflects, and how much: a picture of its surroundings laid on it by which
way it faces from the camera, the chrome of the era's consoles and the glossy plastic of its
computer graphics.
The picture is round, the surroundings as a ball of chrome would show them seen from in front: the
middle is what is behind the camera, and the rim what is behind the model. The reflection follows
the camera, as it did then.
How much is reflected changes with the angle: front where the surface faces the camera, edge
where it turns away, and in between the way light does (more and more towards the edge, and fast
near it). Glossy plastic or paint reflects little in front and much at the edge (front: 0.04,
edge: 1); chrome reflects nearly everything everywhere (front: 0.9).
Properties
textureTTextureThe surroundings, as one round picture. One still loading reads as white until it lands.
frontoptionalnumberHow much is reflected where the surface faces the camera, 0 to 1. Default 0.04, a glossy
plastic.
edgeoptionalnumberHow much is reflected where the surface turns away from the camera, 0 to 1. Default 1.
metaloptionalnumberHow much what is reflected takes the surface's own colour, 0 to 1, as a metal's does: gold
reflects a white sky gold. Default 0, the plain mirror of plastic, glass and chrome. What a
metal reflects is the surface's own colour, so it leaves a see-through surface as see-through
as it is, where a plain mirror's makes it more solid.
readoptional'round' | 'cube' | 'screen'How its picture is read: 'round' (the default), a round picture of the surroundings, read at
where the reflection lands on it; 'cube', the six faces of a cube of them, three across and
two down, as useEnvironment draws them; 'screen', a picture of the world seen in a mirror,
read at the pixel's own place on the screen, as useMirror draws it. The last two are drawn by
code, so a scene document does not keep them: a scene saved while the game runs comes back with
the surface plain, and the code that gave it them gives them again.
bluroptionalnumberHow soft a mirror's picture is, in pixels (read: 'screen' only): 0, the default, sharp; a
few for polished stone or a wet floor. A uniform, reflectionBlur, so it changes while it runs.
View source · materials/types/t_material.ts:196#TMaterialReflectionRecordtypenacatamalon
TMaterialReflectionRecord: Required<Omit<TMaterialReflection, 'read' | 'blur'>> & Pick<TMaterialReflection, 'read' | 'blur'>
A material's reflection as it keeps it: every number filled in, and how it is read and softened
only when it is a mirror's.
View source · materials/types/t_material.ts:306#TMaterialShadertypenacatamalon
TMaterialShader: 'sprite2d' | 'mesh3d' | 'post'
Which family of built-in shader a material plugs into, and so what its hooks are handed.
'sprite2d' is handed a colour already sampled and already tinted, and the flat square's place on
it. 'mesh3d' is handed a surface and everything the light knew about it, and may also move the
corner before any of that happens. 'post' is handed the finished frame.
A screen-wide effect takes the same hooks as a sprite, on purpose: a CRT over one sprite and a
CRT over the whole picture are the same arithmetic, so they should be the same file.
View source · materials/types/t_uniforms.ts:17#TMaterialShaderOptionstypenacatamalon
The shader half of what a material can be asked for, which both kinds share.
Writing the source here is the quick way in, for an effect that lives with the scene that uses it.
effect is the other way: a file, which several scenes can share and which an editor can open.
Giving both is a contradiction, and the file wins.
Properties
nameoptionalstringA name, which is what a warning about this material will call it.
fragmentoptionalstringThe fragment hook, in WGSL.
For a model, fn effect(surface: vec4<f32>, ctx: FragContext) -> vec4<f32>, where ctx has:
uv; normal, worldPos and viewDir in the world; cameraPos, where the camera stands
in the world, so distance(ctx.cameraPos, ctx.worldPos) is how far away this is; light, shine and emissive, the
light reaching it already worked out; color, the colour painted on the corners; screen,
where it is on the screen in the game's pixels, (0, 0) at the top left; tangent and
bitangent, the way across and down the surface the picture runs, in the world; uv2, a
second picture coordinate (the file's own or createGeometry's uv2, or uv again; stretched
as uv is when affine);
frontFacing; carry, what the corner hook carried here (see vertex); and occlusion, how
open the place is to the light from all around, 1 to 0 (see occlusion, already in light).
The corner hook's VertContext has normal, uv, color, tangent, bitangent and uv2,
before anything is moved, and, on a model drawn as many (createMeshInstances), instance,
the four numbers of the instance the corner belongs to, and origin, where that instance
stands; both are zeros on a single model.
fragmentGlsloptionalstringThe same hook in GLSL, without which the effect is WebGPU only: on WebGL2 the material draws
with the built-in shader and says so once. To write it once for both cards, build it with the
shader composer (compileShader), which gives fragment and fragmentGlsl together.
vertexoptionalstringThe vertex hook, in WGSL: fn vertex(pos: vec3<f32>, ctx: VertContext) -> vec3<f32>, where the
corner ends up. 3D only: a sprite is a flat square and has nothing to move.
On a model drawn as many (createMeshInstances) it runs after the instance has placed the
corner: pos, ctx.normal and ctx.tangent are in the space the whole group stands in, so a
wind crossing a meadow is one direction for every blade, and pos.y - ctx.origin.y is how far
up its own instance a corner is.
It can also hand four numbers on to the fragment hook by writing them into carry
(carry = vec4<f32>(lift, 0.0, 0.0, 0.0);, carry = vec4(lift, 0.0, 0.0, 0.0); in GLSL),
which reads them as ctx.carry, smeared across the triangle: how high a wave lifted a corner, for foam on its
crests; a light of its own worked out at the corners, the look of the era; pos itself, where
the corner is in the model's own space, for bands or a fill line that stay on the model as it
moves and turns.
Nothing written is zeros.
It can also say which way the surface faces at the corner, for the light, by writing it into
surfaceNormal (surfaceNormal = vec3<f32>(0.0, 1.0, 0.0);), in the space pos is in: a blade
of grass lit as if it faced up rather than sideways, a flat card lit as if it were round. It is
brought back to length one. Nothing written, the surface is measured where the hook moved it
(below). The composer's compileShader({ normal }) writes it.
It reads the material's uniforms (mu) and its maps (sampleMap_<name>(uv)), so a picture can
move the corners: a height map, footprints pressed into snow, ripples drawn into a texture. The
surface is measured again where the hook moved it, by calling it at two places beside each
corner with the same ctx, and lit by that. So read a map at a place worked out from pos,
not at ctx.uv: read at ctx.uv, the places beside it rise just as much, and the moved surface
is lit as if it were still flat. On a plane width by depth,
pos.xz / vec2<f32>(width, depth) + 0.5 is its uv. Give a height map smooth: true in
maps: read pixel by pixel (the game's default), each pixel is a flat step, and the surface
comes out in terraces lit flat, with walls where one step meets the next.
vertexGlsloptionalstringThe same, in GLSL, without which the corners are not moved on WebGL2. compileShader gives
both from one graph, as for fragmentGlsl.
uniformsoptionalTUniformValuesThe uniforms, with the values they start at. Their kinds are read off these, and fixed from then
on, because how they are packed for the card depends on them.
Kept as given, not copied: the object you pass in is the one the renderer reads, so writing a
number into it is read by the next frame. That is how a shader is driven by the game, and it
is the same rule a text's style follows.
effectoptionalTShader | stringA file from useLoadShader, or the name one was loaded under.
View source · materials/types/t_material_options.ts:19#TMaterialUvTransformtypenacatamalon
How a model's picture is laid on it, moved from where its shape puts it: repeated, turned and slid.
The three are done in that order, as a model file's own (glTF's KHR_texture_transform) are, so
one read from a file is laid exactly as its author saw it.
Properties
scaleoptionalnumber | { x, y }How many times the picture is laid across (x) and down (y) the place it had: 4 is four
times each way, a floor of tiles from a picture of one; { x: 4, y: 1 } only across; a
negative one lays it mirrored. Not 0. Default 1.
rotationoptionalnumberHow far it is turned, in radians, about the picture's top-left corner, its (0, 0): clockwise as
it is seen, as a model file turns it. Default 0.
offsetoptional{ x, y }How far it is slid, in pictures (1 is a whole picture): the place read is moved by this, so
{ x: 0.25, y: 0 } shows the picture a quarter of the way on, moved to the left. Growing it
every frame scrolls the picture: a river, a conveyor belt, clouds. Default none.
View source · materials/types/t_material.ts:264#TMaterialUvTransformRecordtypenacatamalon
A material's uvTransform as it keeps it: every part filled in, plain numbers a game changes while
it runs (material.uvTransform.offset.x += delta * 0.5), read afresh every frame.
Properties
scale{ x, y }rotationnumberoffset{ x, y }
View source · materials/types/t_material.ts:292#TMeshMaterialtypenacatamalon
TMeshMaterial: TShaderHalf & { shader, texture, tint, emissive, emissiveTexture, occlusion, specular, shininess, alpha, transparent, blend, smooth, wrap, maps, vertexSnap, affine, perPixel, reflection, normalMap, uvTransform, cull, alphaCutoff, lighting, steps }
A material for models: a surface, and optionally a shader over it.
Here the surface is the material's, because that is what a hundred crates want to share. They
are one shape and one surface and a hundred placements, and a colour per crate would be a
parameter nobody asked for.
That is the other half of the split: in three dimensions the material owns the look, in two the
object does.
Properties
shader'mesh3d'textureTTexture | nullThe picture on it, or null for a plain surface of its tint.
tintTColorMultiplies the picture. White leaves it alone, and is the whole colour without one.
emissiveTColorLight it gives off by itself, which no lamp has to reach. Black is none.
emissiveTextureoptionalTTexture | nullA picture the glow comes through, multiplied by emissive: white where it glows, black where
it does not, the lit windows of a building or the screen of an arcade cabinet. Read with the
same edges and corners as texture. Omitted, the glow is the same all over.
occlusionoptionalTMaterialOcclusion | nullWhere the light from all around is kept out of its creases. See TMaterialOcclusion.
Always the long form here, { texture, strength, uv, wrap }, whichever was given to make it: to
change it later, write that. Omitted, nothing is.
specularTColorThe colour of its shine. Black is a surface that does not shine at all.
shininessnumberHow tight the shine is: higher is a smaller, harder highlight.
alphanumberHow solid it is, 0 to 1. Multiplies the tint's own.
transparentoptionalbooleanDrawn as see-through even at full alpha: for a shader that works out its own alpha, or a
picture with see-through parts. Omitted, it is see-through when alpha or its tint's own is
below 1. A see-through model is drawn after the solid ones, furthest first, and hides nothing.
blendoptional'alpha' | 'additive'How it lands on what is behind it: 'alpha' covers, 'additive' adds its colour, and is always
drawn see-through and casts no shadow. Omitted, 'alpha'. Can be changed any frame.
smoothoptionalbooleanHow the picture is read between pixels. Omitted, the game decides.
wrapoptionalTTextureWrap | { u, v }What the picture does past its edge: 'repeat' (the default) tiles it, 'mirror' tiles it
flipped every other time, and 'clamp' stretches its last row and column. A pair sets each
way on its own (u across, v down), which is how a fence repeats sideways and not upwards.
mapsoptionalRecord<string, TMaterialMap>Extra pictures for its shader to read, by name, up to four: sampleMap_<name>(uv) in the
shader reads the one under that name, in the fragment hook or the vertex hook. Read every
frame, so swapping one shows at once.
vertexSnapoptionalboolean | numberIts corners land on a coarse grid of the screen, the way the PlayStation drew them: a model
shivers as it moves and its edges crawl as the camera turns.
A number is how many rows that grid has, and the columns follow the view's shape so its cells
stay square: 120 is the classic shiver at any resolution, smaller is wilder. true uses the
game's own rows, which is honest but subtle, because the picture is already drawn on that grid
and a corner moves less than half a pixel. The real console shivered more than that: its maths
ran on low-precision numbers, which is why a coarser grid is what reads as "PlayStation".
Left out, the scene's render style decides (useRenderStyle), and with none there is no
snapping; false, or 0, says no to that style.
affineoptionalbooleanIts picture is stretched straight across the screen, without correcting for depth, the way the
PlayStation drew it: a floor or a wall bends and swims as the camera comes close.
The warp grows with the size of a triangle on screen, so a big flat plane shows it most and a
finely cut one hides it, which is what the games of the time did to keep it down. Left out,
the scene's render style decides (useRenderStyle), and with none the picture is held true to
the surface; false says no to that style.
perPixeloptionalbooleanIts light is worked out at every pixel rather than at its corners: a shine is a round, clean
spot that slides across the surface however few triangles the model has, where the engine's
own light, worked out at the corners and smeared across each triangle, loses it between them.
The look of the computer graphics of the era (glossy plastic, chrome) rather than of its
consoles.
Drawn the way a material with a shader of its own is, whether it has one or not: that way
already carries which way the surface faces and where it is to every pixel, which the light
needs. A shader of your own receives it in ctx.light and ctx.shine without changing; one
written in WGSL only is drawn the built-in way on WebGL2, as always, and there the light is
worked out at the corners. Read every frame, so it can change while the game runs. Left out,
the scene's render style decides (useRenderStyle), and with none it is off; false says no
to that style.
reflectionoptionalTMaterialReflectionRecordWhat its surface reflects, and how much in front and at the edge, as it was asked for (see
TMaterialReflection). Kept so it can be written down and made again, like lighting:
the picture is the material's map reflection, and the two numbers are its uniforms
reflectionFront and reflectionEdge, which are what change while the game runs. Left out
when it has none.
normalMapoptionalRequired<TMaterialNormalMap>The normal map that bends its surface, as it was made with, its strength filled in. Kept so it
can be written down and made again. Left out when it has none.
uvTransformoptionalTMaterialUvTransformRecordHow its picture is laid, moved from where its shape puts it (see TMaterialUvTransform):
plain numbers, read every frame, so a game changes them while it runs. Left out when it has none,
and then setting one later does nothing: the material is drawn by a shader that moves the
picture only when it was made with one (uvTransform: {} for a picture that starts still).
culloptionalTCullModeWhich side of its triangles is thrown away: 'back', 'front' or 'none' (see
TCullMode). Omitted, 'back'. Read every frame, so it can change while the game runs.
alphaCutoffoptionalnumberCuts its picture out instead of blending it: a pixel whose alpha is below this number is not
drawn at all, and every other one is drawn solid. A fence, a leaf, grass, hair or a paper
figure, with the shape of its picture and none of its square. Solid, so it hides what is behind
it, needs no sorting, and casts the shadow of its shape. The edge is as hard as the picture is
read: pixel steps without smooth, rounded with it. The alpha is the picture's times the tint,
the corners' colour and alpha, or what a colour hook returns. 0.5 is the usual. Omitted, nothing is
cut. Read every frame, so it can change while the game runs.
lightingoptionalTLightingLookThe lighting look it was made with, kept so it can be written down and made again. Left out
when it has none.
stepsoptionaltypeOperatorThe steps it was made with, for the same reason. Left out when it has none.
idstringtype'material'namestring | nullA name for reading in a warning. Never looked up by: a material is a value, not a resource.
fragmentstring | nullThe fragment hook in WGSL, which is what WebGPU compiles.
fragmentGlslstring | nullThe same hook written again in GLSL, which is what WebGL2 compiles.
vertexstring | nullThe vertex hook in WGSL. Only a 3D material has one: a sprite is a flat square.
vertexGlslstring | nullThe same, in GLSL.
uniformsTUniformValues | nullThe uniforms, or null when there is no shader of your own to turn.
uniformSigTUniformSignature | nullWhat kind each uniform is. Fixed once, because the compiled shader was built against it.
effectTShader | nullThe file this came from, or null when the source was written inline.
View source · materials/types/t_material.ts:322#TMeshMaterialOptionstypenacatamalon
TMeshMaterialOptions: TMaterialShaderOptions & { shader, texture, key, tint, emissive, emissiveTexture, occlusion, specular, shininess, alpha, transparent, blend, smooth, wrap, maps, vertexSnap, affine, perPixel, reflection, normalMap, uvTransform, cull, alphaCutoff, lighting, steps }
What createMaterial is asked for when the material is for models.
Everything about the surface is optional and defaults to a plain matt white one, so a material
that only carries an effect says only that.
Properties
shader'mesh3d'Which of the engine's shaders it is built on, its family: 'mesh3d', the one that lights
models. Not your code: that is effect (or fragment), and its file says the same family on
its // @shader mesh3d line.
textureoptionalTTextureA picture for the surface, from useLoadTexture. One loaded with mipmaps: true is read far
away from a smaller copy of itself, so a floor running into the distance does not shimmer.
keyoptionalstringThe name a picture was loaded under, for a material built where the picture is not at hand.
tintoptionalTColorOptionMultiplies the picture, and is the whole colour without one. Default white.
emissiveoptionalTColorOptionLight it gives off by itself. Default none.
emissiveTextureoptionalTTextureA picture the glow comes through, multiplied by emissive: white where it glows, black where
it does not, the lit windows of a building or the screen of an arcade cabinet. Read with the
same edges and corners as texture. Default none, the glow the same all over.
occlusionoptionalTTexture | TMaterialOcclusionWhere the light from all around is kept out of its creases, the shading a modelling program
calls occlusion: a picture whose red is white where the surface is open and black where it is
shut in. It darkens only the scene's ambient, never a lamp or the sun. The picture alone, or
{ texture, strength, uv, wrap } to apply less of it, lay it out by a second picture coordinate
or give it edges of its own (see TMaterialOcclusion). Default none.
specularoptionalTColorOptionThe colour of its shine. Default none, which is matt.
shininessoptionalnumberHow tight that shine is. Default 32.
alphaoptionalnumberHow solid it is, 0 to 1. Default 1.
transparentoptionalbooleanDrawn as see-through even at full alpha: for a shader that works out its own alpha, or a
picture with see-through parts. Omitted, it is see-through when alpha or its tint's own is
below 1. A see-through model is drawn after the solid ones, furthest first, and hides nothing.
blendoptional'alpha' | 'additive'How it lands on what is behind it. 'alpha' (the default) covers it as far as its alpha says.
'additive' adds its colour instead, so it can only brighten: a flash, a hologram, a shield,
a beam of light, a magic circle. Its alpha says how much of it is added. An additive model is
always drawn as see-through (after the solid ones, hiding nothing, whatever transparent
says), casts no shadow, since light added blocks none, and fades into the fog by adding less
rather than by turning the fog's colour.
smoothoptionalbooleanOverrides the game's smooth for anything drawn with this.
wrapoptionalTTextureWrap | { u, v }What the picture does past its edge: 'repeat' (the default for a model) tiles it, 'mirror' tiles it
flipped every other time, and 'clamp' stretches its last row and column. A pair sets each
way on its own (u across, v down), which is how a fence repeats sideways and not upwards.
mapsoptionalRecord<string, TTexture | TMaterialMap>Extra pictures for the shader to read by name, up to four, each a texture or a texture with its
own wrap and smooth. In the shader, sampleMap_<name>(uv) reads the one under that name,
in the fragment hook and in the vertex hook alike (see vertex).
A picture made with mipmaps (useLoadTexture({ mipmaps: true })) is read in the fragment hook
from the copy its size on the screen asks for, judged by how the model's own ctx.uv runs
across the screen, inside a branch too. Read at a place that runs faster, say how much faster
with sampleMapScaled_<name>(uv, scale): sampleMapScaled_detail(ctx.uv * 8.0, vec2(8.0)).
Otherwise a picture repeated eight times is read eight times too sharp far away and shimmers.
A scale of vec2(0.0) reads the picture itself, for a place that does not follow the surface
(envUv(ctx)). sampleTexture and sampleTextureScaled do the same for texture. The vertex
hook always reads the picture itself.
vertexSnapoptionalboolean | numberIts corners land on a coarse grid of the screen, the way the PlayStation drew them: a model
shivers as it moves and its edges crawl as the camera turns. A number is how many rows the grid
has (120 is the classic look, smaller is wilder); true uses the game's own rows, which is
subtle. Left out, the scene's render style decides (useRenderStyle), and with none it is off;
false, or 0, says no to that style.
affineoptionalbooleanIts picture is stretched straight across the screen without correcting for depth, the way the
PlayStation drew it: big flat surfaces bend and swim as the camera comes close. Left out, the
scene's render style decides (useRenderStyle), and with none it is off; false says no to it.
perPixeloptionalbooleanIts light is worked out at every pixel rather than at its corners. The engine's own light is
worked out at the corners and smeared across each triangle, the way the consoles of the era
did it; a shine that falls between corners is lost, or comes out shaped like the triangles.
Worked out at every pixel, a shine is a round, clean spot that slides across the surface
however few triangles the model has: the look of the computer graphics of the time, glossy
plastic and chrome. It costs more per pixel, and a shader of your own receives that light in
ctx.light and ctx.shine without changing. It can be changed while the game runs. Left out,
the scene's render style decides (useRenderStyle), and with none it is off; false says no
to that style.
reflectionoptionalTTexture | TMaterialReflectionWhat its surface reflects: a round picture of its surroundings, and how much it reflects in
front and at the edge (see TMaterialReflection). The picture alone is a glossy plastic
(front: 0.04, edge: 1); front: 0.9 is chrome. It goes over the light, under the shine and
the glow, and with lighting and steps too. It makes part of the colour, so it is not given
with fragment or effect: a shader of your own reads a map at envUv(ctx) instead. The
picture takes the map reflection, one of the four, and the two numbers are the uniforms
reflectionFront and reflectionEdge. Default none.
normalMapoptionalTTexture | TMaterialNormalMapA normal map that bends its surface at every pixel, so a flat wall catches the light as carved
stone or brick would: the picture alone, or { texture, strength } (0 flat, 1 as the map
says, the default). It needs the model's tangents, which every built-in shape and model file has.
The material is lit at every pixel unless it says perPixel: false. The picture takes the map
normalMap, one of the four, and the strength is the uniform normalStrength. Not with an
effect from a file. Default none.
uvTransformoptionalTMaterialUvTransformIts picture laid moved from where its shape puts it: repeated (scale), turned (rotation)
and slid (offset), in that order, as a model file's own are. It moves everything laid by the
first picture coordinate: the picture, its glow (emissiveTexture), its normal map (laid the
new way round, so its relief leans right), an occlusion laid by it, and what a hook of your own
reads at ctx.uv. What is laid by the second (occlusion: { uv: 'uv2' }, ctx.uv2) stays.
Read every frame from material.uvTransform, so a game changes it while it runs: growing
offset.x scrolls a river. The material is drawn with the engine's own ending as its colour
hook, as one with a normal map is, and the two numbers it is drawn with are the uniforms
uvTransformMatrix and uvTransformOffset, written by the engine. Not with an effect from a file. Default none.
culloptionalTCullModeWhich side of its triangles is thrown away. 'back' (the default) is a shape seen from
outside; 'front' one seen from inside, such as a dome of sky; 'none' draws both sides, each
lit as the side it is, for a leaf, a sheet or the top of a liquid. A colour hook tells the two
sides apart with ctx.frontFacing.
alphaCutoffoptionalnumberCuts its picture out instead of blending it: a pixel whose alpha is below this number is not
drawn, every other one is drawn solid. For a fence, a leaf, grass or a paper figure, which then
hides what is behind it and casts the shadow of its shape. 0.5 is the usual; from 0 to 1.
Omitted, nothing is cut.
lightingoptionalTLightingLookHow the surface is lit, in place of the engine's light: toonLighting() (flat bands) or unlitLighting() (no
light at all). One only. Its numbers become uniforms of the material (toonShadow...), so they can
be turned while the game runs. It makes the colour, so it is not given with fragment or
effect; a vertex hook may go with it.
stepsoptionaltypeOperatorWhat is done to the surface once it is lit, in order: mangaDots() (ink in the shadow),
rim() (a lit edge), groundBounce() (the ground's colour coming up). On lighting when
there is one, on the engine's light when not. Their numbers become uniforms too
(mangaDotsSize, rimColor; a second of one kind is rim2Color).
nameoptionalstringA name, which is what a warning about this material will call it.
fragmentoptionalstringThe fragment hook, in WGSL.
For a model, fn effect(surface: vec4<f32>, ctx: FragContext) -> vec4<f32>, where ctx has:
uv; normal, worldPos and viewDir in the world; cameraPos, where the camera stands
in the world, so distance(ctx.cameraPos, ctx.worldPos) is how far away this is; light, shine and emissive, the
light reaching it already worked out; color, the colour painted on the corners; screen,
where it is on the screen in the game's pixels, (0, 0) at the top left; tangent and
bitangent, the way across and down the surface the picture runs, in the world; uv2, a
second picture coordinate (the file's own or createGeometry's uv2, or uv again; stretched
as uv is when affine);
frontFacing; carry, what the corner hook carried here (see vertex); and occlusion, how
open the place is to the light from all around, 1 to 0 (see occlusion, already in light).
The corner hook's VertContext has normal, uv, color, tangent, bitangent and uv2,
before anything is moved, and, on a model drawn as many (createMeshInstances), instance,
the four numbers of the instance the corner belongs to, and origin, where that instance
stands; both are zeros on a single model.
fragmentGlsloptionalstringThe same hook in GLSL, without which the effect is WebGPU only: on WebGL2 the material draws
with the built-in shader and says so once. To write it once for both cards, build it with the
shader composer (compileShader), which gives fragment and fragmentGlsl together.
vertexoptionalstringThe vertex hook, in WGSL: fn vertex(pos: vec3<f32>, ctx: VertContext) -> vec3<f32>, where the
corner ends up. 3D only: a sprite is a flat square and has nothing to move.
On a model drawn as many (createMeshInstances) it runs after the instance has placed the
corner: pos, ctx.normal and ctx.tangent are in the space the whole group stands in, so a
wind crossing a meadow is one direction for every blade, and pos.y - ctx.origin.y is how far
up its own instance a corner is.
It can also hand four numbers on to the fragment hook by writing them into carry
(carry = vec4<f32>(lift, 0.0, 0.0, 0.0);, carry = vec4(lift, 0.0, 0.0, 0.0); in GLSL),
which reads them as ctx.carry, smeared across the triangle: how high a wave lifted a corner, for foam on its
crests; a light of its own worked out at the corners, the look of the era; pos itself, where
the corner is in the model's own space, for bands or a fill line that stay on the model as it
moves and turns.
Nothing written is zeros.
It can also say which way the surface faces at the corner, for the light, by writing it into
surfaceNormal (surfaceNormal = vec3<f32>(0.0, 1.0, 0.0);), in the space pos is in: a blade
of grass lit as if it faced up rather than sideways, a flat card lit as if it were round. It is
brought back to length one. Nothing written, the surface is measured where the hook moved it
(below). The composer's compileShader({ normal }) writes it.
It reads the material's uniforms (mu) and its maps (sampleMap_<name>(uv)), so a picture can
move the corners: a height map, footprints pressed into snow, ripples drawn into a texture. The
surface is measured again where the hook moved it, by calling it at two places beside each
corner with the same ctx, and lit by that. So read a map at a place worked out from pos,
not at ctx.uv: read at ctx.uv, the places beside it rise just as much, and the moved surface
is lit as if it were still flat. On a plane width by depth,
pos.xz / vec2<f32>(width, depth) + 0.5 is its uv. Give a height map smooth: true in
maps: read pixel by pixel (the game's default), each pixel is a flat step, and the surface
comes out in terraces lit flat, with walls where one step meets the next.
vertexGlsloptionalstringThe same, in GLSL, without which the corners are not moved on WebGL2. compileShader gives
both from one graph, as for fragmentGlsl.
uniformsoptionalTUniformValuesThe uniforms, with the values they start at. Their kinds are read off these, and fixed from then
on, because how they are packed for the card depends on them.
Kept as given, not copied: the object you pass in is the one the renderer reads, so writing a
number into it is read by the next frame. That is how a shader is driven by the game, and it
is the same rule a text's style follows.
effectoptionalTShader | stringA file from useLoadShader, or the name one was loaded under.
View source · materials/types/t_material_options.ts:113#TMirrortypenacatamalon
TMirror: TMaterialReflection & { texture, read }
What useMirror gives back: a material's reflection, ready to give to the surface that mirrors.
Its texture is the picture of the world it draws every frame.
Properties
textureTTextureThe surroundings, as one round picture. One still loading reads as white until it lands.
frontoptionalnumberHow much is reflected where the surface faces the camera, 0 to 1. Default 0.04, a glossy
plastic.
edgeoptionalnumberHow much is reflected where the surface turns away from the camera, 0 to 1. Default 1.
metaloptionalnumberHow much what is reflected takes the surface's own colour, 0 to 1, as a metal's does: gold
reflects a white sky gold. Default 0, the plain mirror of plastic, glass and chrome. What a
metal reflects is the surface's own colour, so it leaves a see-through surface as see-through
as it is, where a plain mirror's makes it more solid.
readoptional'round' | 'cube' | 'screen'How its picture is read: 'round' (the default), a round picture of the surroundings, read at
where the reflection lands on it; 'cube', the six faces of a cube of them, three across and
two down, as useEnvironment draws them; 'screen', a picture of the world seen in a mirror,
read at the pixel's own place on the screen, as useMirror draws it. The last two are drawn by
code, so a scene document does not keep them: a scene saved while the game runs comes back with
the surface plain, and the code that gave it them gives them again.
bluroptionalnumberHow soft a mirror's picture is, in pixels (read: 'screen' only): 0, the default, sharp; a
few for polished stone or a wet floor. A uniform, reflectionBlur, so it changes while it runs.
View source · hooks/mirror/use_mirror.ts:56#TMirrorOptionstypenacatamalon
What useMirror is asked for. Everything is optional.
Properties
frontoptionalnumberHow much of the world it shows where it faces the camera, 0 to 1. Default 0.3, a polished
floor; 0.9 is a mirror on a wall.
edgeoptionalnumberHow much it shows where it turns away from the camera, 0 to 1. Default 1: a floor seen low
is nearly all reflection, as a real one is.
metaloptionalnumberHow much what it shows takes its own colour, 0 to 1. Default 0.
bluroptionalnumberHow soft what it shows is, in the picture's pixels. Default 0, sharp; 2 to 4 is polished
stone, a wet street.
scaleoptionalnumberHow big its picture is against the game's screen, 0.1 to 1. Default 1. Half (0.5) costs a
quarter and, with a little blur, looks the same on a floor.
View source · hooks/mirror/use_mirror.ts:21#TShaderHalftypenacatamalon
What both kinds of material have: a shader of your own, and the uniforms on it.
All four sources are null on a material that only describes a surface, which is every material
a game has until it asks for an effect.
Properties
idstringtype'material'namestring | nullA name for reading in a warning. Never looked up by: a material is a value, not a resource.
fragmentstring | nullThe fragment hook in WGSL, which is what WebGPU compiles.
fragmentGlslstring | nullThe same hook written again in GLSL, which is what WebGL2 compiles.
vertexstring | nullThe vertex hook in WGSL. Only a 3D material has one: a sprite is a flat square.
vertexGlslstring | nullThe same, in GLSL.
uniformsTUniformValues | nullThe uniforms, or null when there is no shader of your own to turn.
uniformSigTUniformSignature | nullWhat kind each uniform is. Fixed once, because the compiled shader was built against it.
effectTShader | nullThe file this came from, or null when the source was written inline.
View source · materials/types/t_material.ts:17#TSpriteMaterialtypenacatamalon
TSpriteMaterial: TShaderHalf & { shader, maps }
A material for flat things: a shader and nothing else.
The picture and the colour are not here, and that is the design. A sprite carries its own, and
carries them per sprite: they travel in the instance buffer next to its place and its size, so a
thousand sprites in one draw can be a thousand different colours. Putting the colour on something
shared would mean one of these per sprite to vary it, which is the opposite of what a material is
for. A sprite keeps its own texture and its own tint, and its material is only the effect over
the top.
Properties
shader'sprite2d'mapsoptionalRecord<string, TMaterialMap>Extra pictures for its shader to read, by name, up to four: sampleMap_<name>(uv) reads the
one under that name, usually at localUv(), across what is drawn. Read every frame, so
swapping one shows at once.
idstringtype'material'namestring | nullA name for reading in a warning. Never looked up by: a material is a value, not a resource.
fragmentstring | nullThe fragment hook in WGSL, which is what WebGPU compiles.
fragmentGlslstring | nullThe same hook written again in GLSL, which is what WebGL2 compiles.
vertexstring | nullThe vertex hook in WGSL. Only a 3D material has one: a sprite is a flat square.
vertexGlslstring | nullThe same, in GLSL.
uniformsTUniformValues | nullThe uniforms, or null when there is no shader of your own to turn.
uniformSigTUniformSignature | nullWhat kind each uniform is. Fixed once, because the compiled shader was built against it.
effectTShader | nullThe file this came from, or null when the source was written inline.
View source · materials/types/t_material.ts:68#TSpriteMaterialOptionstypenacatamalon
TSpriteMaterialOptions: TMaterialShaderOptions & { shader, maps }
What createMaterial is asked for when the material is for flat things.
There is nothing here about a picture or a colour, because those belong to the sprite. This is the
effect and its uniforms, and nothing else.
Properties
shaderoptional'sprite2d'Which of the engine's shaders it is built on, its family: 'sprite2d', the one that draws
sprites and texts. Left out, it is this one, the commoner of the two by a long way. Not your
code: that is effect (or fragment).
mapsoptionalRecord<string, TTexture | TMaterialMap>Extra pictures for the shader to read by name, up to four, each a texture or a texture with its
own wrap and smooth. In the shader, sampleMap_<name>(uv) reads the one under that name,
and localUv() is where this pixel is across what is drawn, 0 to 1: the whole sprite, one tile
of a map (layerUv() is across the whole layer), one letter of a text, one piece of a
nine-slice. A mask that stays put while the sprite animates is read there, and not at the uv
of the sheet.
nameoptionalstringA name, which is what a warning about this material will call it.
fragmentoptionalstringThe fragment hook, in WGSL.
For a model, fn effect(surface: vec4<f32>, ctx: FragContext) -> vec4<f32>, where ctx has:
uv; normal, worldPos and viewDir in the world; cameraPos, where the camera stands
in the world, so distance(ctx.cameraPos, ctx.worldPos) is how far away this is; light, shine and emissive, the
light reaching it already worked out; color, the colour painted on the corners; screen,
where it is on the screen in the game's pixels, (0, 0) at the top left; tangent and
bitangent, the way across and down the surface the picture runs, in the world; uv2, a
second picture coordinate (the file's own or createGeometry's uv2, or uv again; stretched
as uv is when affine);
frontFacing; carry, what the corner hook carried here (see vertex); and occlusion, how
open the place is to the light from all around, 1 to 0 (see occlusion, already in light).
The corner hook's VertContext has normal, uv, color, tangent, bitangent and uv2,
before anything is moved, and, on a model drawn as many (createMeshInstances), instance,
the four numbers of the instance the corner belongs to, and origin, where that instance
stands; both are zeros on a single model.
fragmentGlsloptionalstringThe same hook in GLSL, without which the effect is WebGPU only: on WebGL2 the material draws
with the built-in shader and says so once. To write it once for both cards, build it with the
shader composer (compileShader), which gives fragment and fragmentGlsl together.
vertexoptionalstringThe vertex hook, in WGSL: fn vertex(pos: vec3<f32>, ctx: VertContext) -> vec3<f32>, where the
corner ends up. 3D only: a sprite is a flat square and has nothing to move.
On a model drawn as many (createMeshInstances) it runs after the instance has placed the
corner: pos, ctx.normal and ctx.tangent are in the space the whole group stands in, so a
wind crossing a meadow is one direction for every blade, and pos.y - ctx.origin.y is how far
up its own instance a corner is.
It can also hand four numbers on to the fragment hook by writing them into carry
(carry = vec4<f32>(lift, 0.0, 0.0, 0.0);, carry = vec4(lift, 0.0, 0.0, 0.0); in GLSL),
which reads them as ctx.carry, smeared across the triangle: how high a wave lifted a corner, for foam on its
crests; a light of its own worked out at the corners, the look of the era; pos itself, where
the corner is in the model's own space, for bands or a fill line that stay on the model as it
moves and turns.
Nothing written is zeros.
It can also say which way the surface faces at the corner, for the light, by writing it into
surfaceNormal (surfaceNormal = vec3<f32>(0.0, 1.0, 0.0);), in the space pos is in: a blade
of grass lit as if it faced up rather than sideways, a flat card lit as if it were round. It is
brought back to length one. Nothing written, the surface is measured where the hook moved it
(below). The composer's compileShader({ normal }) writes it.
It reads the material's uniforms (mu) and its maps (sampleMap_<name>(uv)), so a picture can
move the corners: a height map, footprints pressed into snow, ripples drawn into a texture. The
surface is measured again where the hook moved it, by calling it at two places beside each
corner with the same ctx, and lit by that. So read a map at a place worked out from pos,
not at ctx.uv: read at ctx.uv, the places beside it rise just as much, and the moved surface
is lit as if it were still flat. On a plane width by depth,
pos.xz / vec2<f32>(width, depth) + 0.5 is its uv. Give a height map smooth: true in
maps: read pixel by pixel (the game's default), each pixel is a flat step, and the surface
comes out in terraces lit flat, with walls where one step meets the next.
vertexGlsloptionalstringThe same, in GLSL, without which the corners are not moved on WebGL2. compileShader gives
both from one graph, as for fragmentGlsl.
uniformsoptionalTUniformValuesThe uniforms, with the values they start at. Their kinds are read off these, and fixed from then
on, because how they are packed for the card depends on them.
Kept as given, not copied: the object you pass in is the one the renderer reads, so writing a
number into it is read by the next frame. That is how a shader is driven by the game, and it
is the same rule a text's style follows.
effectoptionalTShader | stringA file from useLoadShader, or the name one was loaded under.
View source · materials/types/t_material_options.ts:344#TTextureWraptypenacatamalon
TTextureWrap: 'repeat' | 'clamp' | 'mirror'
What a model's picture does past its edge.
A model's corners may ask for any part of the plane, not only the picture's own square: a ladder
of UVs from 0 to 20 across a field is how one small patch of grass covers a whole hillside, and it
is how nearly every level of the era was textured. 'repeat' tiles the picture, 'mirror' tiles
it flipped every other time so its seams meet themselves, and 'clamp' stretches its last row and
column outwards.
Repeating is the default for a model, as it is in glTF. A sprite and a
map never repeat: they read one frame of a sheet, and the next frame over is not theirs to show.
View source · materials/types/t_material.ts:94#TUniformColorValuetypenacatamalon
TUniformColorValue: number[] | string | TColor
A uniform that is a colour: as text ('#ffcc00'), { r, g, b, a }, or the card's [r, g, b].
View source · materials/types/t_uniforms.ts:85#TUniformNumberstypenacatamalon
TUniformNumbers: Record<string, number | number[]>
Uniforms as a file keeps them: each a number or a list, the card's own form, whatever form the
game gave them in.
View source · materials/types/t_uniforms.ts:95#TUniformPointtypenacatamalon
A point given to a uniform as the rest of the engine takes one: { x, y }, with z and w for a
uniform of three or four numbers.
Properties
xnumberynumberzoptionalnumberwoptionalnumber
View source · materials/types/t_uniforms.ts:41#TUniformPointValuetypenacatamalon
TUniformPointValue: number[] | TUniformPoint
A uniform that is a place or a direction: { x, y } or the card's [x, y].
View source · materials/types/t_uniforms.ts:76#TUniformSignaturetypenacatamalon
TUniformSignature: Record<string, TUniformType>
What kind each of those parameters is.
Worked out once from the shape of the first values it was given, and fixed from then on: how
the numbers are laid out in memory depends on it, and the shader has already been compiled
against that layout.
View source · materials/types/t_uniforms.ts:108#TUniformTypetypenacatamalon
TUniformType: 'f32' | 'vec2<f32>' | 'vec3<f32>' | 'vec4<f32>'
What kind a material's own parameter may be: one number, or two, three or four of them.
A small set on purpose. It covers what an effect is actually tuned with (a strength, a count, a
colour, an offset) and leaves out matrices and lists, which bring alignment rules that are all
cost and no use here. The one matrix a drawing needs is the one that puts it on screen, and that
already travels with the drawing rather than with its surface.
View source · materials/types/t_uniforms.ts:31#TUniformValuetypenacatamalon
TUniformValue: number | number[] | TUniformPoint | string | TColor
One uniform's value, in any of the forms the engine takes elsewhere for the same thing: a number;
a list of two to four numbers, as the card reads it; a point, { x, y }; or a colour, as text
('#ffcc00', 'orange') or { r, g, b, a }. A point or a colour becomes the card's list when the
uniform is sent, as many of its numbers as the uniform has (a colour to a three-number uniform
gives its r, g, b).
View source · materials/types/t_uniforms.ts:54#TUniformValuestypenacatamalon
TUniformValues: Record<string, TUniformValue>
A material's own parameters, by name: its uniforms. Each is a number, a list of two to four, a
point or a colour (see TUniformValue).
Change one and the next frame shows it: the card is handed these again every draw, so animating a
strength is an assignment and nothing else.
View source · materials/types/t_uniforms.ts:67nacatamalon/shader
#parseShaderFilefunctionnacatamalon/shader
parseShaderFile(source: string, src: string) => TParsedShader
Reads a shader file: comments that say what it is, and plain shader code that says what it does.
The header is read from the whole file, deliberately outside the language halves. What the
file is for and what uniforms it has are one fact about the file, and a fact written twice is two
facts that can drift apart.
A file stays valid code in its own language, so an editor colours it and a card could compile it
with the engine's own preamble in front. That is the point of a comment-based header: nothing here
invents a format that only this engine can open.
Parameters
sourcestringThe text of the file.
srcstringWhere it came from, used only so an error can name it.
View source · loaders/shader/parse_shader_file.ts:159#parseShaderSourcefunctionnacatamalon/shader
parseShaderSource(source: string, src: string) => TParsedShader
Reads a shader file with the reader its extension asks for: a .shader is a graph of nodes, as
JSON, and anything else is WGSL with a header. Both give the same shape, so nothing after this
knows which it was.
It is the loader's own reader, open to tools: an editor that lets a material pick a shader needs
the uniforms it declares, whichever of the two ways it was written.
Parameters
sourcestringThe file's text.
srcstringIts path: the extension decides how it is read, and warnings name it.
View source · loaders/shader/parse_shader_source.ts:21