Build · Scripting API
wired:shading
Node-based shader graphs attached to prims in place of a standard material.
Graphs are directed acyclic lists of fixed-arity nodes with no loops,
branches, or raw shader source, keeping GPU cost bounded.
Limits: 128 nodes per network, 16 public inputs, 4 texture samples.
Interface graph
Uses vec2, vec3, color, prim-id, error, document, layer.
graph-value
variant
Value type for public shader inputs and per-prim overrides.
value-kind
enum
port
variant
Input operand to a shader node.
const(graph-value) | |
input(u16) | Index into public-inputs. |
node(u16) | Index of an earlier node in the same network (strictly less than the referencing node's index to prevent cycles; cannot cross between surface and displacement networks). |
binary-op
record
lerp-op
record
pow-op
record
atan2-op
record
select-op
record
clamp-op
record
step-op
record
smoothstep-op
record
texture-sample-op
record
uv: port | |
slot: u8 | Texture slot index (0..=3). |
record
combine2-op
record
combine3-op
record
combine4-op
record
convert-op
record
remap-op
record
polar-coords-op
record
rotate-uv-op
record
dither-op
record
node
variant
Single operation in a shading network.
Stage availability for zero-arity inputs:
- Surface only:
uv, world-normal, world-position, vertex-color,
view-direction, screen-uv, screen-dots.
- Displacement only:
local-position, local-normal.
- Both stages:
time, instance-random, object-position,
object-scale.
lit-output
record
Physically based lit output; unset ports fall back to renderer defaults.
base-color: option<port> | |
emissive: option<port> | |
metallic: option<port> | |
roughness: option<port> | |
normal: option<port> | |
alpha: option<port> | |
alpha-clip-threshold: option<port> | Fragments with alpha below this threshold are discarded. |
specular-transmission: option<port> | Specular transmission (0..1), tinted by base-color. Values above 0 render in the transmissive pass using thickness and ior. |
diffuse-transmission: option<port> | Diffuse (Lambertian) transmission from rear lighting. |
thickness: option<port> | Refracted ray travel thickness in meters. |
ior: option<port> | Index of refraction (1.0 air, 1.33 water, 1.5 glass). |
unlit-output
record
Direct unlit color output bypassing lighting.
color: port | |
alpha-clip-threshold: option<port> | |
surface-output
variant
blend-mode
enum
Alpha/color compositing mode.
opaque | |
blend | |
add | |
multiply | |
cull-mode
enum
surface-graph
record
Fragment-stage network.
displacement-graph
record
Vertex-stage network. position-offset applies in prim-local space;
world-position-offset applies after the prim transform.
nodes: list<node> | |
position-offset: option<port> | |
normal-override: option<port> | |
world-position-offset: option<port> | |
shader-graph
record
Complete shader graph with default public-inputs, a fragment network,
and an optional vertex displacement network.
set-graph
Attaches graph to prim in place of its material, or clears the graph
(and its overrides) when none. Identical graphs share one compiled
pipeline. Prims can also reference a graph on another prim via the
shader-binding relation.
overrides
Returns active public-input overrides on prim by index.
set-overrides
Replaces all public-input overrides on prim in layer without
recompiling the shared shader pipeline.
Source
package wired:shading;
interface graph {
use wired:core/math.{vec2, vec3, color};
use wired:core/ids.{prim-id};
use wired:core/error.{error};
use wired:scene/document.{document, layer};
variant graph-value {
float(f32),
vec2(vec2),
vec3(vec3),
color(color),
}
enum value-kind {
float,
vec2,
vec3,
color,
}
variant port {
const(graph-value),
input(u16),
node(u16),
}
record binary-op { a: port, b: port }
record lerp-op { a: port, b: port, t: port }
record pow-op { x: port, y: port }
record atan2-op { y: port, x: port }
record select-op { cond: port, a: port, b: port }
record clamp-op { x: port, low: port, high: port }
record step-op { edge: port, x: port }
record smoothstep-op { low: port, high: port, x: port }
record texture-sample-op {
uv: port,
slot: u8,
}
record extract-op { v: port, channel: u8 }
record combine2-op { x: port, y: port }
record combine3-op { x: port, y: port, z: port }
record combine4-op { x: port, y: port, z: port, w: port }
record convert-op { v: port, to: value-kind }
record remap-op {
x: port,
from-low: port,
from-high: port,
to-low: port,
to-high: port,
}
record polar-coords-op { uv: port, center: port }
record rotate-uv-op { uv: port, center: port, radians: port }
record dither-op { coord: port, level: port }
-
-
-
variant node {
uv,
world-normal,
world-position,
vertex-color,
local-position,
local-normal,
time,
instance-random,
object-position,
object-scale,
view-direction,
screen-uv,
add(binary-op),
sub(binary-op),
mul(binary-op),
div(binary-op),
modulo(binary-op),
min(binary-op),
max(binary-op),
dot(binary-op),
cross(binary-op),
distance(binary-op),
pow(pow-op),
atan2(atan2-op),
lerp(lerp-op),
clamp(clamp-op),
step(step-op),
smoothstep(smoothstep-op),
remap(remap-op),
select(select-op),
sin(port),
cos(port),
one-minus(port),
abs(port),
floor(port),
fract(port),
saturate(port),
sqrt(port),
length(port),
normalize(port),
triangle-wave(port),
luminance(port),
fresnel(port),
noise(port),
texture-sample(texture-sample-op),
scene-color(port),
extract(extract-op),
combine2(combine2-op),
combine3(combine3-op),
combine4(combine4-op),
convert(convert-op),
polar-coords(polar-coords-op),
rotate-uv(rotate-uv-op),
screen-dots,
dither(dither-op),
}
record lit-output {
base-color: option<port>,
emissive: option<port>,
metallic: option<port>,
roughness: option<port>,
normal: option<port>,
alpha: option<port>,
alpha-clip-threshold: option<port>,
specular-transmission: option<port>,
diffuse-transmission: option<port>,
thickness: option<port>,
ior: option<port>,
}
record unlit-output {
color: port,
alpha-clip-threshold: option<port>,
}
variant surface-output {
lit(lit-output),
unlit(unlit-output),
}
enum blend-mode {
opaque,
blend,
add,
multiply,
}
enum cull-mode {
back,
front,
none,
}
record surface-graph {
nodes: list<node>,
output: surface-output,
blend: blend-mode,
cull: cull-mode,
cast-shadows: bool,
}
record displacement-graph {
nodes: list<node>,
position-offset: option<port>,
normal-override: option<port>,
world-position-offset: option<port>,
}
record shader-graph {
public-inputs: list<graph-value>,
surface: surface-graph,
displacement: option<displacement-graph>,
}
set-graph: func(
document: borrow<document>,
prim: prim-id,
layer: layer,
graph: option<shader-graph>,
) -> result<_, error>;
overrides: func(document: borrow<document>, prim: prim-id) -> list<tuple<u16, graph-value>>;
set-overrides: func(
document: borrow<document>,
prim: prim-id,
layer: layer,
values: list<tuple<u16, graph-value>>,
) -> result<_, error>;
}