Shader composer
Volver a la referencia

Shader composer

Writing a shader as typed values, and the node graph a .shader file holds.

107 símbolos

nacatamalon/shader

compileShaderfunctionnacatamalon/shader

compileShader(asked: TShaderGraph<S>) => TCompiledShader<S>

Turns a composed graph into the fields a material takes, in both languages.

The result spreads straight into createMaterial, and whichever backend draws it takes the half it speaks. Nothing at the call site names a backend, and that is the point: the values are typed, so the second language is a second walk over the graph rather than a translation, and the two halves cannot drift apart because nobody wrote either.

On the way it works out anything used twice only once, reads each leaf the way its stage offers it (and refuses one read where it does not exist), gathers every parameter into uniforms, and writes each noise function once.

The family comes back in the type, so the result spreads into a material for sprites or for models and the material knows which it is.

A sprite shader needs color and has no vertex stage. A model shader takes color, position or both, and a stage left out keeps the engine's own. color may be a vec3 (alpha 1) or a vec4; position is a vec3.

Parámetros

askedTShaderGraph<S>

Ejemplo

const Level = () => {
    const glow = compileShader({
        shader: 'mesh3d',
        color: composerMix(composerSurface(), composerVec4(0.3, 0.7, 1, 1), composerFresnel(3)),
        position: composerAdd(composerVertexPosition(), composerMul(composerVertexNormal(), composerUniform('swell', 0.1))),
    });
    const material = createMaterial({ tint: '#e08a3a', ...glow });

    createMesh({ geometry: useIcoSphereGeometry(), material });

    return createScene();
};
Ver el código · shader_composer/compile_shader.ts:197

compileShaderGraphfunctionnacatamalon/shader

compileShaderGraph(doc: TShaderGraphDoc, src: string) => TParsedShader

Compiles a .shader file into what a material needs: its hooks in both languages, its parameters and their types. The same shape reading a .wgsl gives, so nothing that uses a shader file can tell the two apart.

It writes no shader code of its own. It turns the file into the same values the composer functions build and hands them to compileShader, so a graph drawn on a canvas and the same graph written in code cannot drift, and every check the composer functions make applies to a wired graph too.

Only what reaches an output is built: a node nothing is wired to adds nothing, so a canvas with a few loose nodes on it still compiles. A loop is caught and named. An output left unwired keeps the engine's own for that stage, so a new file is valid and its material draws with the engine's shader until something is connected.

Parámetros

docTShaderGraphDoc

The graph, from parseShaderGraph.

srcstring

Where it came from, for the error messages.

Ejemplo

const src = '/shaders/glow.shader';
const parsed = compileShaderGraph(parseShaderGraph(await (await fetch(src)).text(), src), src);
Ver el código · shader_composer/compile_shader_graph.ts:42

composerAtan2functionnacatamalon/shader

composerAtan2(y: TComposerInput, x: TComposerInput) => TComposerNode

The angle of the point (x, y) around the origin, in radians from -π to π, lane by lane: 0 pointing along +x, growing towards +y. y comes first, as in every language that has it.

It is what turns a place into "how far round": a swirl, rays from a sun, a ring that fills like a clock, a pattern wrapped around a centre. Taken around the middle of a sprite, composerAtan2(uv.y - 0.5, uv.x - 0.5); around a model's axis, from the corner's own position. Divide by 2π and add 0.5 for a turn from 0 to 1. At the origin itself, where there is no angle, 0, on every card.

Parámetros

yTComposerInput

The second coordinate. A number spreads over a vector given as x.

xTComposerInput

The first coordinate.

Ejemplo

// eight rays turning around the middle of a sprite
const centred = composerSub(composerUv(), 0.5);
const angle = composerAtan2(composerY(centred), composerX(centred));
const rays = composerStep(0.5, composerFract(composerAdd(composerMul(angle, 8 / (Math.PI * 2)), composerTime())));
const shader = compileShader({ shader: 'sprite2d', color: composerVec4(rays, rays, rays, 1) });
Ver el código · shader_composer/math.ts:494

composerCameraPosfunctionnacatamalon/shader

composerCameraPos() => TComposerNode

Where the camera stands, in the world (vec3): the place the fog measures from. How far away a point is, composerDistance(composerCameraPos(), composerWorldPos()), is what bands, a fade or detail by distance are worked out from. With an orthographic camera it is only where the camera was put, since its rays leave from no one point. Models only, colour stage.

Ejemplo

// Darker bands the further away: three steps across twenty units.
const far = composerDistance(composerCameraPos(), composerWorldPos());
const band = composerFloor(composerMul(composerClamp(composerDiv(far, 20), 0, 1), 3));
compileShader({ shader: 'mesh3d', color: composerMul(composerSurface(), composerSub(1, composerMul(band, 0.25))) });
Ver el código · shader_composer/inputs.ts:114

composerCarryfunctionnacatamalon/shader

composerCarry() => TComposerNode

What the vertex stage carried to this pixel (vec4): the graph's carry, worked out at each corner and smeared across the triangle. How high a wave lifted the water here, for foam on its crests; a light of the graph's own worked out at the corners, the look of the era; where the point was in the model's own space, for bands or a fill line that stay on the model as it moves. A carry smaller than four numbers is filled out with zeros, and none at all reads as zeros. Models only, colour stage.

Ejemplo

const lift = composerMul(composerSin(composerAdd(composerX(composerVertexPosition()), composerTime())), 0.2);
const sea = compileShader({
    shader: 'mesh3d',
    position: composerAdd(composerVertexPosition(), composerMul(composerVertexNormal(), lift)),
    carry: lift,
    color: composerMix(composerSurface(), composerVec4(1, 1, 1, 1), composerSmoothstep(0.12, 0.2, composerX(composerCarry()))),
});
Ver el código · shader_composer/inputs.ts:403

composerCubeUvfunctionnacatamalon/shader

composerCubeUv() => TComposerNode

Where the surface reflects the world on a picture of its surroundings drawn as the six faces of a cube, three across and two down, as useEnvironment draws them: in the world's own axes, so the same from wherever it is seen. Feed it to a map sample of that picture.

Ejemplo

import { composerCubeUv, composerMapSample } from 'nacatamalon/shader';

const around = composerMapSample('room', composerCubeUv(), { scale: 0 });
Ver el código · shader_composer/inputs.ts:226

composerEnvUvfunctionnacatamalon/shader

composerEnvUv() => TComposerNode

Where the surface's reflection of the world lands on a round picture of its surroundings (vec2): read a map there and the model looks like chrome, the reflection the consoles of the era made with a second texture. Use it as the coordinate of composerMapSample. Models only, colour stage.

Ejemplo

const chrome = composerMapSample('env', composerEnvUv());
Ver el código · shader_composer/inputs.ts:206

composerFbmfunctionnacatamalon/shader

composerFbm(pos: TComposerNode, octaves: number) => TComposerNode

Layers of noise, each twice as fine and half as strong as the one before (f32): the detailed, natural kind, for terrain, smoke or lava. octaves is written into the shader, so it is a small fixed number (4 unless you say). Takes a vec2 or a vec3.

Parámetros

posTComposerNode

Where to read it: a vec2 or a vec3.

octavesnumber

How many layers. Default 4.

Ver el código · shader_composer/noise.ts:140

composerFloatfunctionnacatamalon/shader

composerFloat(value: number) => TComposerNode

A constant number. The only kind of constant: vectors are made with composerVec2, composerVec3 and composerVec4, which wrap their plain numbers in this on their own.

Parámetros

valuenumber

The number.

Ver el código · shader_composer/constructors.ts:34

composerFresnelfunctionnacatamalon/shader

composerFresnel(power: TComposerInput) => TComposerNode

The rim term, from 0 where the surface faces the camera to 1 where it turns away (f32): the start of a rim light, a hologram or a force field. A higher power pulls the rim in to the silhouette.

It reads which way the surface faces and where the camera is, so it only exists in a model's colour stage, and the compiler says so anywhere else.

Parámetros

powerTComposerInput

How tightly the rim hugs the silhouette. Default 3.

Ver el código · shader_composer/effects.ts:26

composerFrontFacingfunctionnacatamalon/shader

composerFrontFacing() => TComposerNode

Which side of the triangle is being drawn (f32): 1 the side facing the camera, 0 the other. Only ever 0 on a material that keeps the other side (cull: 'front' or 'none'): mixed by it, a liquid seen from below takes another colour, or a leaf is lighter underneath. Models only, colour stage.

Ver el código · shader_composer/inputs.ts:377

composerInstanceDatafunctionnacatamalon/shader

composerInstanceData() => TComposerNode

The four numbers of the instance a corner belongs to (vec4), for a model drawn as many (createMeshInstances): what set was given as data, a seed, a height, how far along it is. Zeros on a single model. Models only, vertex stage: hand what the colour stage needs of them on with carry.

Ver el código · shader_composer/inputs.ts:482

composerInstanceOriginfunctionnacatamalon/shader

composerInstanceOrigin() => TComposerNode

Where the instance a corner belongs to stands (vec3), in the space the vertex position is in, for a model drawn as many (createMeshInstances): the foot of a blade of grass, whatever corner of it this is. Zeros on a single model. Models only, vertex stage.

Ver el código · shader_composer/inputs.ts:494

composerLayerUvfunctionnacatamalon/shader

composerLayerUv() => TComposerNode

Where this pixel is across the whole of a map's layer, from 0 to 1 (vec2): a shine that crosses the map rather than each tile on its own. On a sprite, the same as composerLocalUv(), so one material does for both. Sprites and map layers only.

Ver el código · shader_composer/inputs.ts:256

composerLightfunctionnacatamalon/shader

composerLight() => TComposerNode

How much light reaches this point, and of what colour (vec3).

It is handed over on its own so a graph can light things its own way, in hard bands or with a rim. The engine's own look is the surface times this, plus composerEmissive. The light is worked out at the corners and blended in between, as the consoles of the era did, or at every pixel on a material with perPixel. Models only, colour stage.

Ver el código · shader_composer/inputs.ts:129

composerLocalUvfunctionnacatamalon/shader

composerLocalUv() => TComposerNode

Where this pixel is across what is drawn, from 0 to 1 (vec2): the whole sprite however its frames change, one tile of a map, one letter of a text or one piece of a nine-slice. Where a mask is read so a sprite crumbles in its own shape and not the sheet's. It turns over with the picture when the sprite or the tile is flipped. Sprites and map layers only.

Ejemplo

const grain = composerMapSample('grain', composerLocalUv());
Ver el código · shader_composer/inputs.ts:244

composerMapSamplefunctionnacatamalon/shader

composerMapSample(name: string, coord: TComposerNode, options?: TComposerSampleOptions) => TComposerNode

Reads one of the material's extra maps by name, at any coordinate (vec4): a reflection, a mask, a detail, a ripple. The material carries the picture under the same name in its maps; one it does not carry reads white. On a model it reads in the colour graph and in the vertex graph too, to move the corners by a picture (a height map, footprints in snow); read it there at a place worked out from composerVertexPosition() rather than composerUv(), so the surface is lit by the shape the map gives it (see TMaterialOptions.vertex). On a sprite or a map's layer, colour graph only: read it at composerLocalUv() for a mask that stays put while the frames change.

A map with mipmaps (useLoadTexture({ mipmaps: true })) is read in a model's colour graph from the copy its size on the screen asks for, judged by how the model's own picture coordinate runs: read it at one that runs faster, say so with scale.

Parámetros

namestring

The map's name, as the material's maps gives it: lowercase first, letters and digits.

coordTComposerNode

Where to read it, in 0-1.

optionsopcionalTComposerSampleOptions

scale, for a place that runs faster than the model's picture coordinate.

Ejemplo

const detail = composerMapSample('detail', composerMul(composerUv(), 8), { scale: 8 });
Ver el código · shader_composer/inputs.ts:308

composerModvariablenacatamalon/shader

composerMod: TComposerBinaryOp

The remainder the way shader authors expect it, x - y * floor(x / y), which always takes the sign of y. Built from the pieces above, because WGSL's own % keeps the sign of x instead and the two backends would disagree on negative numbers. A number as y spreads over x.

Ver el código · shader_composer/math.ts:426

composerOcclusionfunctionnacatamalon/shader

composerOcclusion() => TComposerNode

How open this place is to the light from all around (f32): 1 wide open, 0 shut in a crease, from the material's occlusion, and 1 with none. It is already in composerLight(); this is it on its own, to dim a shine inside the creases or gather dirt in them. Models only, colour stage.

Ejemplo

// The shine kept out of the creases too, as the light from all around already is.
const lit = composerAdd(
    composerMul(composerSwizzle(composerSurface(), 'rgb'), composerLight()),
    composerMul(composerShine(), composerOcclusion()),
);
Ver el código · shader_composer/inputs.ts:424

composerPipefunctionnacatamalon/shader

composerPipe(seed: TComposerInput, steps: TComposerStep[]) => TComposerNode

Passes a value through a list of steps, left to right, so a long expression reads in the order it happens instead of from the inside out.

composerPipe(x, composerMul(2), composerAdd(1), composerSin) reads "take x, double it, add one, then the sine", and is exactly composerSin(composerAdd(composerMul(x, 2), 1)). Any one-operand function is a step as it is, and the two-operand ones that put the value on the left (composerAdd, composerMul, composerPow...) become one when given a single operand. For anything else, a small function (n) => ... is a step too.

Parámetros

seedTComposerInput

The value to start with.

stepsTComposerStep[]

What to do to it, in order.

Ejemplo

// 0.5 + 0.5 * sin(uv.y * lineCount + time * speed)
const bands = composerPipe(
    composerY(composerUv()),
    composerMul(composerUniform('lineCount', 120)),
    composerAdd(composerMul(composerTime(), composerUniform('speed', 6))),
    composerSin,
    composerMul(0.5),
    composerAdd(0.5),
);
Ver el código · shader_composer/pipe.ts:34

composerPolarfunctionnacatamalon/shader

composerPolar(coord: TComposerNode, center: TComposerInput) => TComposerNode

A place read round a centre (vec2): x how far from it, 0 there and 1 at the middle of the picture's edge (the circle that fits in it), and y how far round, a turn from 0 to 1. Read a picture at it and a strip becomes a ring: a dial, a radar, a target, rays from a sun, a ring that fills like a clock (composerStep(turn, fill)), and with composerTime() added to either, one that spins or flows outwards.

Round as composerAtan2 goes: y starts at 0 on the left (-x), is 0.5 on the right, and grows towards +y of the place given, down a sprite's picture. To lay a strip of pictures round it, swap the two (composerSwizzle(polar, 'yx')); to repeat it, multiply: composerMul(polar, composerVec2(1, 12)) is twelve times round. Where the turn starts again, on the left, a picture meets itself: draw it so its two ends join.

Parámetros

coordTComposerNode

The place, composerUv() when left out.

centerTComposerInput

The centre, in the same units. Default the middle of the picture, (0.5, 0.5).

Ejemplo

// A ring of numbers round a dial: the picture is the strip, laid once round.
const polar = composerPolar();
const strip = composerTextureSample(composerSwizzle(polar, 'yx'));
const material = createMaterial({ ...compileShader({ shader: 'sprite2d', color: strip }) });
Ver el código · shader_composer/effects.ts:71

composerScreenPosfunctionnacatamalon/shader

composerScreenPos() => TComposerNode

Where on the screen the surface is, in the game's pixels (vec2): (0, 0) at the top left, the game's width and height at the bottom right, whatever the size of the window. A dot screen, a hatch or a dither laid over a model lines up with the screen through this rather than sliding with the model. Models only, colour stage.

Ver el código · shader_composer/inputs.ts:351

composerShinefunctionnacatamalon/shader

composerShine() => TComposerNode

The highlight the lamps put on the surface (vec3), already shadowed: the shine a material's specular and shininess ask for. The built-in look adds it on top of the lit colour. Models only, colour stage.

Ver el código · shader_composer/inputs.ts:189

composerSimplexNoisefunctionnacatamalon/shader

composerSimplexNoise(pos: TComposerNode) => TComposerNode

Smooth noise at a position (f32, 0 to 1): the usual source of anything organic, like clouds, flowing water or a dissolve mask. Takes a vec2 or a vec3. Scale the position to change how busy it is, and add composerTime() to move it.

Parámetros

posTComposerNode

Where to read it: a vec2 or a vec3.

Ver el código · shader_composer/noise.ts:125

composerSurfacefunctionnacatamalon/shader

composerSurface() => TComposerNode

The colour the engine would have drawn here (vec4): the picture, already read and already tinted (and on a model, painted by its corners' colour), before any light. Where most colour effects start. Colour stage only.

Ver el código · shader_composer/inputs.ts:61

composerSwizzlefunctionnacatamalon/shader

composerSwizzle(value: TComposerNode, mask: string) => TComposerNode

Picks components of a vector by their letters ('bgr', 'xy'). The number of letters, one to four, is the size of the result, and a single letter gives a plain number.

The letters come from one set, xyzw or rgba, never both in one mask, and each must exist in the value it reads: both are checked here rather than left to the card.

Parámetros

valueTComposerNode

The vector to read.

maskstring

One to four letters from xyzw or rgba.

Ver el código · shader_composer/constructors.ts:105

composerTextureSamplefunctionnacatamalon/shader

composerTextureSample(coord: TComposerNode, options?: TComposerSampleOptions) => TComposerNode

Reads the material's own picture, tinted, at any coordinate (vec4). What waves, pixelation, a colour split or a blur are made of: composerSurface() is this read at the fragment's own coordinate. Colour stage only.

A picture with mipmaps on a model is read from the copy its size on the screen asks for, judged by how the model's own picture coordinate runs. Read at one that runs faster (uv * 4), say so with scale.

Parámetros

coordTComposerNode

Where to read the picture, in 0-1.

optionsopcionalTComposerSampleOptions

scale, for a place that runs faster than the model's picture coordinate.

Ejemplo

const tiled = composerTextureSample(composerMul(composerUv(), 4), { scale: 4 });
Ver el código · shader_composer/inputs.ts:279

composerUniformfunctionnacatamalon/shader

composerUniform(name: string, value: number | number[]) => TComposerNode

A parameter with a name, which the game can change while it runs.

What value looks like sets its type (a number, or a list of two, three or four) and is what it starts at. compileShader gathers every parameter of the graph into the material's uniforms, so writing material.uniforms.<name> moves it on the next frame. time and resolution are taken: the engine writes those, and they are read with composerTime and composerResolution.

Parámetros

namestring

What the game calls it: material.uniforms.<name>.

valuenumber | number[]

What it starts at. A number, or a list of two, three or four.

Ver el código · shader_composer/inputs.ts:330

composerUv2functionnacatamalon/shader

composerUv2() => TComposerNode

A second picture coordinate (vec2): the model file's own or createGeometry's uv2, or the first again when it has none. For a second picture laid over the first by coordinates of its own: baked light, a decal, a detail. Models only, in either stage.

Ver el código · shader_composer/inputs.ts:364

composerVertexColorfunctionnacatamalon/shader

composerVertexColor() => TComposerNode

The colour painted on the model's corners (vec4), smeared across each triangle. Models only, in either stage.

It is already part of composerSurface. On its own it is for using the paint as something other than colour: how much a corner sways in the wind, or how much of a second picture shows through, which is how the era blended grass into a dirt path without a second texture pass.

Ver el código · shader_composer/inputs.ts:177

composerWorldBitangentfunctionnacatamalon/shader

composerWorldBitangent() => TComposerNode

Which way down the surface the picture runs, in the world (vec3): the normal crossed with the tangent, turned over where the picture is mirrored. Models only, colour stage.

Ver el código · shader_composer/inputs.ts:447

composerWorldTangentfunctionnacatamalon/shader

composerWorldTangent() => TComposerNode

Which way across the surface the picture runs, in the world (vec3, one long, square to the normal). With the bitangent and the normal it is the frame a relief or a ripple moves the picture in. Models only, colour stage.

Ver el código · shader_composer/inputs.ts:436

groundBouncefunctionnacatamalon/shader

groundBounce(options: { color, reach, amount, groundY }) => TGroundBounceLook

The colour of the ground coming up onto what stands on it, as light bounces off a bright floor: the closer a part is to the ground and the more it looks down, the more it goes towards the ground's colour; nothing of it reach above the ground, nor on a face looking up. A lamp's light that bounces, without a lamp, so it goes as well on a matcap as on the engine's light. For a material's steps.

It works from where each pixel is in the world, so a model that jumps loses it on the way up and gets it back as it lands.

Parámetros

options{ color, reach, amount, groundY }

color, the ground's, what getColor takes, a TColor or [r, g, b] (default an orange); reach how high it reaches, in the world's units (default 1); amount how far a face on the ground and looking down goes towards the colour, 0 to 1 (default 0.5); groundY where the ground is (default 0).

Ejemplo

declare const red: TTexture;

createMaterial({ ...matcap(red), steps: [groundBounce({ color: '#ff7a33', reach: 1.4 })] });
Ver el código · shader_composer/surface/looks.ts:140

mangaDotsfunctionnacatamalon/shader

mangaDots(options: { size, fill, ink }) => TMangaDotsLook

Dots of ink in the shadow, the way printed comics shaded: the darker, the bigger. They are laid out on the screen and not on the model, so they stay put as it turns. For a material's steps.

After toonLighting the dots go exactly where its bands went dark; with the engine's light they grow smoothly into the dark.

Parámetros

options{ size, fill, ink }

size how far apart the dots are, in game pixels (default 5); fill how big a dot grows in full shadow, as a part of its cell (default 0.3; past 0.5 they touch); ink its colour, what getColor takes, a TColor or [r, g, b] (default a deep violet).

Ejemplo

declare const tint: TColor;

createMaterial({ shader: 'mesh3d', tint, lighting: toonLighting(), steps: [mangaDots({ size: 4 })] });
Ver el código · shader_composer/surface/looks.ts:86

parseShaderGraphfunctionnacatamalon/shader

parseShaderGraph(source: unknown, src: string) => TShaderGraphDoc

Reads a .shader file and checks its shape.

It takes the text of the file or JSON already parsed, because both callers exist: a game loading it has text in hand, and an editor holds a graph it has just changed and wants checked before it writes it. A broken shape (a node with no id, a place that is not two numbers, an unknown family) is refused here, naming the node. What the graph means (a kind of node nobody knows, a wire into an input that does not exist, a loop) is compileShaderGraph's, which knows the catalogue.

Parámetros

sourceunknown

The file's text, or its JSON.

srcstring

Where it came from, for the error messages.

Ejemplo

const graph = parseShaderGraph(await (await fetch('/shaders/glow.shader')).text(), '/shaders/glow.shader');
Ver el código · shader_composer/document.ts:164

rimfunctionnacatamalon/shader

rim(options: { color, power, amount }) => TRimLook

A light along the edge that turns away from the camera, as if lit from behind. The edge goes towards color and never past it, so it brightens without burning. For a material's steps.

Parámetros

options{ color, power, amount }

color, what getColor takes, a TColor or [r, g, b] (default white); power how tightly it keeps to the silhouette (default 4); amount how far the edge goes towards the colour, 0 to 1 (default 0.7).

Ver el código · shader_composer/surface/looks.ts:106

toonLightingfunctionnacatamalon/shader

toonLighting(options: { bands, shadow, spot }) => TToonLook

The light cut into flat bands, the cartoon look: the surface is lit or it is not, with nothing smeared between, and the shine is one hard spot. For a material's lighting.

It cuts the light every light of the scene gives (the sun, the lamps, the shadows they cast), and only its brightness: each band keeps the colour of the light that made it, so a warm lamp gives warm bands and a white light greys.

It also says which part it put in shadow, so a step after it (mangaDots) inks exactly there.

Parámetros

options{ bands, shadow, spot }

bands how many steps of light (default 2); shadow how bright the darkest one is, 0 to 1 (default 0.45); spot where the shine is cut, 0 to 1 (default 0.75).

Ejemplo

declare const tint: TColor;

createMaterial({ shader: 'mesh3d', tint, lighting: toonLighting({ bands: 3 }) });
Ver el código · shader_composer/surface/looks.ts:36

unlitLightingfunctionnacatamalon/shader

unlitLighting() => TUnlitLook

No light at all: the surface exactly as it is painted (its picture, its tint and what it gives off itself), the same from every side and in every shadow. For a material's lighting: a sky, a screen, a sign that glows, anything that is not lit but is a light.

Ejemplo

declare const tint: TColor;

createMaterial({ shader: 'mesh3d', tint, lighting: unlitLighting() });
Ver el código · shader_composer/surface/looks.ts:61

TCompiledShadertypenacatamalon/shader

What compileShader gives back: exactly the fields createMaterial takes, so it is spread straight in, createMaterial({ ...compiled }).

A stage left at the engine's own is missing, the same as not writing it in createMaterial. uniforms holds every parameter found in the graph, ready to be changed while the game runs.

Propiedades

shaderS
fragmentopcionalstring

The colour hook in WGSL, missing when the graph has no color.

vertexopcionalstring

The vertex hook in WGSL, missing when the graph has no position.

fragmentGlslopcionalstring

The same two hooks in GLSL, always, never on request.

That is what makes a composed shader work on both backends by construction rather than when somebody remembers to ask. The values are typed, so the second language is a second walk over the same graph and not a translation of the first one's text.

vertexGlslopcionalstring
Ver el código · shader_composer/types/t_shader_graph.ts:62

TComposerNodetypenacatamalon/shader

One value in a composed shader: what kind of value it is, and how to build it from the values it depends on.

It is plain data, never a closure. kind picks how it is written out, params carries its literal operands and deps the values it is made from. That is what lets a graph be written to JSON and read back, the same rule every other piece of state in the engine follows.

Never built by hand: the composer* functions fill these fields consistently and check their operands as they go.

Propiedades

kindstring

How it is written out: literal, input, uniform, texture, construct, swizzle, binop or call.

typeTUniformType

What it evaluates to. Every operation checks its operands against this.

depsTComposerNode[]

The values it is made from, in argument order.

paramsopcionalnumber | string[]

Literal operands: a number, an operator, a swizzle mask or the name of the function called.

inputopcionalTInputKind

For a leaf, which value of the running shader it reads.

uniformopcional{ name, value }

For a parameter, the name the shader reads it by and the value it starts at.

helpersopcionalTHelperDef[]

Functions this node needs written at the top of the shader.

Ver el código · shader_composer/types/t_composer_node.ts:80

TComposerSampleOptionstypenacatamalon/shader

How composerTextureSample and composerMapSample read a picture that has mipmaps.

Propiedades

scaleopcionalTComposerInput | typeOperator

How many times as fast the place read runs as the model's own picture coordinate: 8 for uv * 8, [4, 2] for one that runs faster across than down, or a value worked out in the graph (a parameter, say). It picks the mipmap that place asks for; without it a picture repeated eight times is read eight times too sharp far away, and shimmers. 0 reads the picture itself, for a place that does not follow the surface (composerEnvUv()). Only a model's colour graph reads mipmaps; anywhere else it changes nothing. Left out, 1.

Ver el código · shader_composer/types/t_composer_node.ts:128

TGraphCommentDoctypenacatamalon/shader

A note on the canvas: a titled rectangle behind the nodes, for grouping part of a graph and saying what it is for.

It has an array of its own rather than being a kind of node, because it is not one: no wires, no value, no place in the graph. As a node, the compiler, the type check and the previews would each need an exception for the one entry that is not part of the shader.

Propiedades

idstring
textstring

The note. May be empty while it is being written.

pos[number, number]

Top-left corner, in the same space as a node's pos.

size[number, number]

Width and height: a note is resized, a node is not.

coloropcional[number, number, number]

An accent, [r, g, b] from 0 to 1. Left out, the editor picks.

Ver el código · shader_composer/types/t_shader_graph_doc.ts:87

TGraphNodeDoctypenacatamalon/shader

One node in a saved graph: which kind of node it is, where it sits on the canvas, and its literals.

It does not describe itself. Its inputs, outputs and code all come from the catalogue, looked up by type, so a file stays small and a node learns something new when the catalogue changes rather than when every file is rewritten.

pos belongs to the editor and is in the file on purpose, like a box's place in a scene: how a graph is laid out is part of what it says to whoever reads it.

Propiedades

idstring
typestring

Which entry of the catalogue this is.

pos[number, number]

Where it sits on the canvas, [x, y].

paramsopcionalRecord<string, TParamValue>

Its literals. One left out takes the catalogue's value.

Ver el código · shader_composer/types/t_shader_graph_doc.ts:28

TGraphTargettypenacatamalon/shader

TGraphTarget: Exclude<TMaterialShader, 'post'>

The families a graph file can be for: the two that draw things, deliberately not every family a material has.

'post' is missing because no node writes a screen-wide effect, so a graph claiming it would compile to nothing. Spelling it as its own type makes that gap a compile error in the one place that could open it, and the reader refuses the same value, so the two cannot disagree.

Ver el código · shader_composer/types/t_shader_graph_doc.ts:73

TGroundBounceLooktypenacatamalon/shader

The colour of the ground coming up onto what stands on it, as groundBounce() writes it down.

Propiedades

look'groundBounce'
colornumber[]

The ground's colour, [r, g, b] from 0 to 1.

reachnumber

How high above the ground it reaches, in the world's units: none of it from there up.

amountnumber

How far a face right on the ground and looking down goes towards the colour, 0 none to 1 all the way.

groundYnumber

Where the ground is: its height in the world.

Ver el código · shader_composer/surface/types.ts:90

THelperDeftypenacatamalon/shader

A function a node needs written once at the top of the shader (the noise functions, for instance), kept only once however many nodes ask for it.

Both languages ride on the node rather than living in a table per language looked up by name. A helper exists because a node needs it, and keeping the two apart would let a graph ask for a helper one language never defined: a failure that shows up as a shader that does not compile in somebody's browser, rather than as a missing entry while writing it.

Propiedades

namestring
wgslstring
glslstring
Ver el código · shader_composer/types/t_composer_node.ts:59

TInputKindtypenacatamalon/shader

TInputKind: 'uv' | 'time' | 'resolution' | 'surface' | 'worldNormal' | 'worldPos' | 'viewDir' | 'cameraPos' | 'light' | 'emissive' | 'shine' | 'envUv' | 'cubeUv' | 'vertexPosition' | 'vertexNormal' | 'vertexColor' | 'screenPos' | 'uv2' | 'worldTangent' | 'worldBitangent' | 'vertexTangent' | 'vertexBitangent' | 'instanceData' | 'instanceOrigin' | 'frontFacing' | 'carry' | 'occlusion' | 'localUv' | 'layerUv'

A value a leaf reads from the running shader: a function argument (uv, pos), one of the values the engine writes for every material (time), or what the model's colour hook is told about the place it is colouring (worldNormal, light).

Each one is only there in some stages, and the compiler refuses a leaf read where it does not exist (light in a vertex graph, say) instead of emitting code the card then rejects.

Ver el código · shader_composer/types/t_composer_node.ts:15

TMangaDotsLooktypenacatamalon/shader

Dots of ink in the shadow, the way printed comics shaded, as mangaDots() writes it down.

Propiedades

look'mangaDots'
sizenumber

How far apart the dots are, in game pixels.

fillnumber

How big a dot grows in full shadow, as a part of its cell. Past 0.5 they touch.

inknumber[]

The colour of the ink, [r, g, b] from 0 to 1.

Ver el código · shader_composer/surface/types.ts:44

TParamValuetypenacatamalon/shader

TParamValue: number | number[] | string

A literal a node keeps in its own body instead of receiving through a wire: a swizzle mask, a number of octaves, a colour. Only what JSON keeps intact and an inspector can show a control for.

Ver el código · shader_composer/types/t_shader_graph_doc.ts:11

TRimLooktypenacatamalon/shader

A light along the edge that turns away from the camera, as rim() writes it down.

Propiedades

look'rim'
colornumber[]

The colour the edge goes towards, [r, g, b] from 0 to 1.

powernumber

How tightly it keeps to the silhouette: higher is thinner.

amountnumber

How far the edge goes towards the colour, 0 none to 1 all the way.

Ver el código · shader_composer/surface/types.ts:67

TShaderGraphtypenacatamalon/shader

What compileShader is handed: the family the shader is for, and up to three results.

color is what the colour hook returns and position is where the vertex hook moves a corner to (models only), and carry is what the vertex hook hands on to the colour hook. Leave one out and that stage keeps the engine's own.

The family is kept in the type, so what comes out is known to be a sprite's or a model's.

Propiedades

shaderS
coloropcionalTComposerNode
positionopcionalTComposerNode
carryopcionalTComposerNode

Up to four numbers worked out at each corner and handed to the colour stage, which reads them with composerCarry(), smeared across the triangle: how high a wave lifted the water, for foam on its crests; a light of the graph's own worked out at the corners; where the point was in the model's own space (composerVec4(composerVertexPosition(), 0)), for bands or a fill line that stay on the model as it moves. A number, a vec2, a vec3 or a vec4, filled out with zeros. Written with position, so what the two have in common is worked out once. Models only.

normalopcionalTComposerNode

Which way the surface faces at each corner, for the light, in the space position is in (a vec3, brought back to length one): a blade of grass lit as if it faced up, a flat card lit as if it were round. Left out, the surface is measured where position moved it. Written with position, as carry is. Models only.

lightingopcionalTLook

How a model's surface is lit, in place of the engine's light: toonLighting() or unlitLighting(). With steps, it makes the colour, so it is never given with color. Models only.

stepsopcionaltypeOperator

What is done to a model's surface once it is lit, in order: mangaDots(), rim(), groundBounce(). Models only.

Ver el código · shader_composer/types/t_shader_graph.ts:19

TShaderGraphDoctypenacatamalon/shader

A .shader file: a shader drawn as nodes on a canvas.

It sits next to a hand-written .wgsl and next to a graph composed in code, and all three end up as the same thing, so a material cannot tell which one it was given. The file holds no shader source in any language, only nodes and wires as plain JSON.

target means what @shader means at the top of a .wgsl: it picks the hooks, so it is not a preference but part of what gets compiled.

Propiedades

formatnumber
kind'shadergraph'
commentsopcionalTGraphCommentDoc[]

The notes on the canvas. A graph written by hand or by a tool has none, and then the field is not there at all: it is a graph nobody annotated, not a missing field.

Ver el código · shader_composer/types/t_shader_graph_doc.ts:121

TToonLooktypenacatamalon/shader

Light cut into flat bands, the cartoon look, as toonLighting() writes it down.

Propiedades

look'toon'
bandsnumber

How many bands of light, from the darkest to the full.

shadownumber

How bright the darkest band is, 0 black to 1 as lit as the rest.

spotnumber

Where the shine is cut into one hard spot, 0 everywhere it shines to 1 nowhere.

Ver el código · shader_composer/surface/types.ts:10