Skip to main content

Language Reference

Besides the syntactic sugar afforded by shape blocks and other high‑level constructs, Shape‑Z provides a powerful GLSL‑style math system.

Variables

let pos = vec3(0.0, 0.0, 0.0);
let pos = 0; // promotes to vec3(0.0, 0.0, 0.0)
let pos = vec2(0.5); // promotes to vec3(0.5, 0.5, 0.5)

All three statements create a variable named pos, but they demonstrate different ways of supplying the value. Shape‑Z internally stores every value as a vec3, so scalars and 2‑component vectors are automatically promoted.

Vector components can be accessed or modified individually via the .x, .y, and .z suffixes:

let p = vec3(1.0, 2.0, 3.0);
let h = p.y; // h == 2.0

p.z = 0.0; // p is now vec3(1.0, 2.0, 0.0)

You can define variables anywhere in the code and at any block level. However Shape-Z does not support variables per block, every variable is stored in a flat array internally in the VM for performance reasons. If you redefine a variable Shape-Z will re-use the pre-existing variable slot and overwrite the previous value.

Inbuilt Math Functions

The table below lists functions that are available in every expression. Most mirror standard GLSL behaviour, while a few domain‑specific helpers—such as value_noise—extend the set.

FunctionArgsDescription
abs(x)1Absolute value, component‑wise
atan(x)1Arctangent of x (radians)
atan2(y, x)2Arctangent of y/x preserving quadrants (radians)
ceil(x)1Smallest integer ≥ x
clamp(x, min, max)3Clamps x to the range [min, max]
cos(x)1Cosine of x (radians)
cross(a, b)23‑D cross product
degrees(x)1Converts radians to degrees
dot(a, b)2Dot (scalar) product
floor(x)1Largest integer ≤ x
fract(x)1Fractional part of x
length(v)1Euclidean length of vector v
log(x)1Natural logarithm of x
max(a, b)2Component‑wise maximum
min(a, b)2Component‑wise minimum
mix(a, b, t)3Linear interpolation: a(1‑t) + b t
mod(x, y)2Component‑wise remainder of x / y
normalize(v)1Returns v scaled to unit length
point_at(p)1Converts a normalized (u,v,d) into world space along the current segment
pow(x, y)2Component‑wise power x^y
radians(x)1Converts degrees to radians
sin(x)1Sine of x (radians)
smoothstep(edge0, edge1, x)3Smooth Hermite interpolation between edge0 and edge1
smooth_union(d1, d2, k)3Softly blends two signed‑distance fields with blend radius k
sqrt(x)1Square root of x
step(edge, x)2Returns 0 if x < edge else 1
tan(x)1Tangent of x (radians)
value_noise(octaves, scale)2Fractal value‑noise sample; octaves (float) sets the number of layers, scale (vec3) controls the frequency
white_noise()0Pseudo‑random value in [0, 1] tied to the current voxel