Shaders

A shader is a small WGSL program that paints a background or fill — a grid, a gradient, a dot field, film grain — with typed inputs you can drive from the UI, from a design, or from the API. Because shaders run on the viewer's GPU, they stay crisp at any size and cost nothing to store.

Shaders are user-authored code, so the platform treats them as untrusted. Nothing reaches the database until it has passed vetting, and nothing renders in a browser without a runtime watchdog watching it.

The convention

You write the body of one function:

fn mainImage(uv: vec2f) -> vec4f {
  // uv is 0..1 across the surface, origin top-left
  return vec4f(uv.x, uv.y, 0.5, 1.0);
}

Available to you:

SymbolTypeMeaning
uvvec2fNormalised coordinates, 0..1, origin top-left
u_timef32Seconds since the shader started
u_resolutionvec2fIn templates, the layer's width and height in document pixels
u_mousevec4fLive pointer: xy = position in 0..1 UV space, zw = position in pixels. On a canvas layer, UV is the layer's own space and zw is the document point. Defaults to the center when no pointer is present (previews without hover, server renders)
u_mousedownf321.0 while a pointer button is held, else 0.0
your inputsper manifestReferenced directly by name

Shaders that read u_mouse are interactive: on the standalone canvas and on a creative-editor layer they re-render live as the pointer moves. Server renders always see the deterministic defaults, so exports stay reproducible.

In templates, uv always spans the whole layer and u_resolution stays at the layer's document size. Preview zoom, display pixel density and export scale change sampling quality without changing borders, pattern spacing or image cropping. Resizing the layer changes its design size. Shader paints expose the same size as u_res.

You may not declare pipeline attributes (@group, @binding, @builtin, @vertex, @fragment), var<uniform> or var<storage> bindings, sampler or texture types, enable directives or override constants, or define main(). The platform generates bindings and samplers from your inputs. You may sample images declared as texture inputs, and read text inputs through their generated helpers, as shown below. WGSL has no ternary (use select(f, t, cond)), no implicit int-to-float conversion (use f32(i)), and uses atan2(y, x); the helpers pmod, pmod2 and pmod3 give a floor-style mod.

Text is rasterised, never source

In the creative editor every manifest input is also bindable: bind shaderUniforms.<name> to an expression (template variables, $time, math) or keyframe it on the timeline, and the shader re-renders as the value changes — same rules as any other layer property.

Image inputs use shaderTextures.<name> for their URL bindings. A single shader layer can draw both the selected image and its frame; an additional image layer is unnecessary. Text inputs use shaderTexts.<name>: bind it to product.name and every render draws that product's name through the shader.

Every value a shader exposes is declared in a manifest and bound at draw time — numbers and colours as uniforms, images and text as textures. Values are never substituted into the source; a string becomes pixels, never code:

{
  "name": "grid-background",
  "inputs": [
    { "name": "background", "type": "color", "label": "Background", "default": "#0d0d0d" },
    { "name": "lineColor",  "type": "color", "label": "Line",       "default": "#2c2c2a" },
    { "name": "cellSize",   "type": "float", "label": "Cell size",  "min": 4, "max": 160, "default": 32 },
    { "name": "lineWidth",  "type": "float", "label": "Line width", "min": 0.5, "max": 6, "default": 1 },
    { "name": "majorEvery", "type": "int",   "label": "Major every","min": 1, "max": 16, "default": 4 }
  ]
}

Input types: color (a vec4f, defaulted as #rrggbb), colors (a palette — see below), float, int, vec2, enum (which becomes an i32 index), texture (an image input) and text (a string drawn into a distance field — see below). No value ever enters the shader source: image URLs select textures, and text is rasterised by the platform before the shader sees it.

Palettes (colors)

A colors input is an array of colors with a declared capacity (maxItems, 2–8). It arrives as array<vec4f, maxItems> plus a generated <name>Count (i32, how many entries are actually set — the companion name is reserved for you). Loops are bounded by the literal maxItems, and break at <name>Count, so this is the idiomatic way to paint from a user-sized palette. The same input works through the MCP create_shader / update_shader tools:

{ "name": "palette", "type": "colors", "label": "Palette", "maxItems": 6,
  "default": ["#2D5016", "#556B2F", "#8B4513"] }
var col = palette[0].rgb;
for (var i = 1; i < 6; i++) {
  if (i >= paletteCount) { break; }
  col = mix(col, palette[i].rgb, someMask);
}

Bound to a template, a palette takes a list of colours: Make variable on the input declares an array variable seeded with the current colours. Separate color inputs (colorA, colorB, …) remain the simpler choice when each colour should be its own form field.

In a JSON-schema manifest, declare it as a color list: { "type": "array", "items": { "type": "color" }, "maxItems": 6, "default": [...] }.

Textures (texture)

A texture input is an image picker on the shader itself. The manifest constrains image properties, so any conforming image can be bound per use (per canvas node, per render, per test-form pick). It generates <name>: texture_2d<f32>, <name>Sampler: sampler and <name>Size: vec2f (pixel dimensions; companion names belong to the platform). Declare it through MCP create_shader or update_shader:

{ "name": "photo", "type": "texture", "label": "Photo", "maxDim": 1024, "maxBytes": 5242880 }
fn mainImage(uv: vec2f) -> vec4f {
  return textureSample(photo, photoSampler, uv);
}

Rules and guarantees:

  • textureSample may only sample a declared texture input with its generated sampler. Authors cannot declare additional bindings.
  • Values are URL strings. Same-origin URLs always work. Other hosts must be https and on the hosts Bannx allows. That check happens before any request.
  • maxDim (≤2048) and maxBytes (≤10MB) bound what can be bound: oversized images are downscaled at bind time, over-size files are rejected in the picker.
  • The stored thumbnail shows the shader on a checker. The editor preview uses your image.
  • In a JSON-schema manifest, declare it as an asset field: { "type": "string", "inputType": "library", "libraries": "media", "maxDim": 1024 }.

Text (text)

A text input puts type in a shader: an outlined headline, a long shadow, neon, a 3D extrusion, a glitch. The value is a plain string. Bannx draws it in the declared font, converts the letters to a signed distance field (for every pixel, how far it is from the nearest letter edge) and binds that like an image. The shader never sees the characters, only distances, so a headline cannot change the program, and the same shader works for any text you bind later.

{ "name": "label", "type": "text", "label": "Headline", "maxLength": 60,
  "default": "Big news", "font": "Inter", "weight": 800, "spread": 64 }
PropertyMeaning
maxLengthLongest value accepted, 1–200 (default 80). Longer values are cut; control characters (tabs and newlines included) become spaces and runs of whitespace collapse to one
fontA Google Fonts family name — letters, digits and spaces (default Inter). The font belongs to the shader, not to the value
weight100–900 (default 800)
spreadHow far from the edge distances are measured, in layer pixels, 8–128 (default 64). Raise it for wide glows and long shadows

The text is drawn on one line, centred, as large as fits: about 62% of the layer height, shrunk so the line spans at most 80% of the width. An empty value draws nothing (every pixel reads as outside). On a text layer's Shader effect the field is the layer's own layout instead.

Generated for you (the companion names are reserved):

SymbolTypeMeaning
labelSd(uv)fn(vec2f) -> f32Signed distance to the letter edge at uv, in layer pixels: positive inside the letters, negative outside, 0 on the edge. Saturates at ±spread
labelCov(uv)fn(vec2f) -> f32Plain coverage, 0..1, as a normal text layer would draw it
label, labelSamplertexture + samplerThe field itself (r = the distance encoded 0..1, 0.5 on the edge; g = coverage), if you want to sample it directly
labelSizevec2fThe field's pixel size
labelSpreadf32The field's distance range in field pixels
sdCov(d)fn(f32) -> f32Antialiased fill of a distance: clamp(d + 0.5, 0, 1)
sdRing(d, w)fn(f32, f32) -> f32A band w pixels wide just outside the edge: an outline

sdCov and sdRing are available in every shader that declares a text input.

Outline. A stroke of any width, outside the letters, antialiased:

fn mainImage(uv: vec2f) -> vec4f {
  let d = labelSd(uv);
  var col = vec3f(0.06, 0.06, 0.08);
  col = mix(col, vec3f(1.0, 0.36, 0.22), sdRing(d, 7.0));
  col = mix(col, vec3f(0.98, 0.97, 0.95), sdCov(d));
  return vec4f(col, 1.0);
}

Long shadow. Step the sample point along a direction and keep the strongest coverage:

fn mainImage(uv: vec2f) -> vec4f {
  let d = labelSd(uv);
  let dir = normalize(vec2f(1.0, 1.0));
  var sh = 0.0;
  for (var i = 1; i < 60; i++) {
    let p = uv - dir * f32(i) * 1.6 / u_resolution;
    sh = max(sh, sdCov(labelSd(p)) * (1.0 - f32(i) / 60.0));
  }
  var col = vec3f(0.16, 0.64, 0.56);
  col = mix(col, vec3f(0.09, 0.44, 0.40), sh);
  col = mix(col, vec3f(1.0, 0.96, 0.90), sdCov(d));
  return vec4f(col, 1.0);
}

Neon. Exponential falloff of the outside distance, wide plus tight, on a pulse:

fn mainImage(uv: vec2f) -> vec4f {
  let d = labelSd(uv);
  let o = max(-d, 0.0);
  let pulse = 0.85 + 0.15 * sin(u_time * 3.0) * sin(u_time * 7.3);
  var col = vec3f(0.03, 0.02, 0.06);
  col += vec3f(1.0, 0.18, 0.70) * exp(-o / 26.0) * 0.9 * pulse;
  col += vec3f(1.0, 0.55, 0.9) * exp(-o / 5.0) * pulse;
  col = mix(col, vec3f(1.0, 0.95, 1.0), sdCov(d) * (0.75 + 0.25 * pulse));
  return vec4f(col, 1.0);
}

Rules and guarantees:

  • Each labelSd / labelCov call is a texture read, and the cost model prices it like one. A loop over it must have a literal bound; keep step counts modest (the long shadow above uses 60).
  • Text and texture inputs share two slots per shader: two text inputs, two images, or one of each.
  • The value is drawn by the platform with fonts it loads itself; the field is sized from the layer, never from the string.
  • Vetting renders the shader against generated fields (a dot, a blob, a row of letters, an empty field), and the stored thumbnail shows your default text in a simple block face.
  • The Outlined text preset (list_shader_presets) is a complete example with fill, outline and shadow controls; the whole text pack is listed below.
  • In a JSON-schema manifest, declare it as { "type": "string", "inputType": "shader-text", "maxLength": 60, "font": "Inter", "weight": 800, "spread": 64 }. A plain string field is still rejected.

Text presets

Ten starting points on the Shaders page (New shader → Start from → Text effects) and in list_shader_presets, tagged text. Each has a Text input (up to 60 characters, bindable to a template variable), every colour, width, step count, angle and speed as a ranged input, and a Show background switch: off, the layer is transparent outside the effect so it sits over your other layers.

PresetWhat it draws
Outlined textFill, an outline of any width and a soft drop shadow (offset, softness, opacity)
Sticker textA die-cut sticker: ink line, paper border, ink line, then a two-colour gradient fill
Long shadow textFlat-design shadow stepped along an angle (up to 60 steps), fading with distance
3D extruded textBlock letters with a near-to-far shaded side; the extrusion direction can slowly turn
Chrome textBevelled metal with sky and ground reflections, a tint, gloss and a moving light
Neon textA glowing tube: wide halo, tight core and the tube itself, pulsing with a flicker
Inset textPressed-in letters: an inner shadow (offset, size, depth) plus an inner glow at the edge
Glitch textRows that tear sideways on a clock, an RGB split and scanlines
Reveal textA wipe along an angle that uncovers the letters, with a glowing leading edge; Speed 0 holds it at Progress
Marching ants textA dashed selection outline (dash length, angle, speed) crawling around the letters

Pick one, change the word and the colours in the test form, and save: the preview and the stages run on your values before anything is stored. Every preset also works as a Shader effect on a text layer, where the layer's own letters replace the Text input.

Shader effect on a text layer

A text shader can also style an ordinary text layer. Select the layer, then Effects → + → Shader, and pick a shader that declares a text input (the picker lists those first; shaders without one are shown but cannot be picked). The shader's first text input then reads the layer's own letters: its font, size, weight, line breaks, alignment, letter spacing and styled runs, exactly as the layer lays them out. Edit the text on the canvas and the shader follows; bind the text to a variable and every render draws that value.

  • Pad is the room around the layer box the shader may draw into, in pixels (0–512, default 32). Outlines, glows, long shadows and extrusions land outside the letters, so give them enough pad to show in full.
  • While the effect is on it replaces the layer's fill, stroke, highlights and drop shadows: the shader draws the letters itself. Turn the effect off to get the plain text back.
  • The shader's other inputs appear under the picker, with the same Make variable button as on a shader layer. A second text input stays editable and draws the string you type into it.
  • Renders and exports include the effect. SVG and PDF exports draw the layer as an image (its letters are no longer selectable there).
  • Over MCP: "effects": [{ "type": "shaderText", "shaderId": "…", "pad": 32, "shaderUniforms": { … } }] in a text layer's props. The compiled program comes from the shader record; it is never sent by the caller. A shader that declares no text input is refused with a 400 (Shader "…" has no text input): pick one tagged text.

Declaring inputs as a JSON schema

Inputs can also be declared as a JSON schema. This is what the Shaders page's visual input editor produces, and it powers the live test form under the preview. Send it as schema on create/update instead of manifest:

{
  "root": {
    "type": "object",
    "properties": {
      "background": { "type": "color", "label": "Background", "default": "#0d0d0d" },
      "cellSize":   { "type": "number", "label": "Cell size", "minimum": 4, "maximum": 160, "default": 32 },
      "style":      { "type": "string", "label": "Style", "enum": ["solid", "dashed"] }
    },
    "required": []
  }
}

Only fields a shader can receive are accepted: color, number (multipleOf: 1 or integer for an int), a string with enum, boolean (becomes a 0/1 int), a color list, an image (inputType: "library") and text (inputType: "shader-text"). Groups, other lists, dates and plain free-text strings are rejected by vetting, not dropped — what the form shows is exactly what the shader receives. The typed manifest is derived from the schema during vetting and stored alongside it, and all the classic manifest policy (input cap, reserved names, finite bounded ranges) still applies to the derived inputs.

Inputs are bound as uniforms, not pasted into the source, so a value cannot change the program. The compiled program stays the same when you change an input.

Always give numeric inputs a range

min and max are not just UI bounds. They are the clamp applied on both server and client, and they are what lets the vetter prove your loops terminate:

for (var i = 0; i < steps; i++) { … }   // accepted only because `steps` has a max

Using shaders in the editor

  • Add one: the insert toolbar at the bottom of the canvas → Media → Shader opens your workspace's approved shaders and the published ones; pick one to drop it on the canvas.
  • Swap one: select a shader layer, and the Shader section of the inspector shows its name. Click it to open the shader picker and choose another. Inputs the new shader also declares keep their values; the layer name follows the shader unless you renamed it.
  • Write one: the picker's link opens the Shaders page (Projects → Shaders), where new shaders are vetted.

Shader inputs as template variables

In the editor, every row of a shader layer's Shader section has a { } button: Make variable. It declares a template variable typed after the input — number with the manifest's min/max, colour picker for color, a dropdown of the enum values, a media picker for texture, a text field capped at the input's maxLength for text, an array for vec2 / colors — seeded with the input's current value, and binds the input to it (bindings["shaderUniforms.<name>"], shaderTextures.<name> for images, shaderTexts.<name> for text). The All button at the top of the section does it for every unbound input at once.

From then on the template's form, POST /api/v1/templates/:id/render (variables), the bulk API, MCP and the embed all drive the shader: { "variables": { "tint": "#00ff00" } } renders the layer with that tint, and { "variables": { "label": "Summer sale" } } redraws a text input's letters. A template can be nothing but a shader layer whose inputs are its variables.

The shader itself as a template variable

Beyond per-input variables, the program can be swapped per render. A variable of { "type": "object", "format": "shader" } holds { id, inputs }; a shader layer bound to it through bindings.shaderId takes that shader's program and input values at render. The editor's Variable button at the top of a shader layer's inputs sets this up in one click; the template's page then shows a shader picker. Only the space's approved shaders and published ones resolve — see Shader variables.

Publishing a shader

A shader starts private to the workspace that authored it. The Public switch on its card (or PUT /api/v1/shaders/:id with { "public": true }, or update_shader with public: true over MCP) publishes it:

  • every workspace sees it in the shader picker of a shader variable, in list_shaders, and in GET /api/v1/shaders?public=true;
  • any signed-in user can fetch it with GET /api/v1/shaders/:id — its vetted program, the author's source and the manifest are part of what is published;
  • the author's workspace keeps the only write access: editing, revoking and deleting stay with it.

A shader does not need to be published for a template that uses it to be shared. Whoever may open a template's page (published, share link, embed, or a member) can see the shaders the version they are shown uses (the published version for anyone outside your space) and the ones its shader variables point at, so the picker, inputs form and live preview work for every visitor while the shader stays private. Visitors cannot pick any other private shader of yours there; publishing is what puts a shader in everyone's picker.

Only an approved shader can be published (409 otherwise). Editing a published shader re-vets it and keeps it published; quarantining or revoking it stops it loading everywhere, published or not. Switching it off ({ "public": false }) withdraws it: templates in other workspaces that picked it fall back to the shader they were saved with on their next render.

Vetting

Every create and every edit runs the same pipeline, cheapest stage first, and a rejection at any stage means nothing is stored.

StageWhat it does
Ingest limitsByte cap and encoding, before anything parses the source
Manifest schemaTypes, ranges, reserved names, input count
Static policy scanForbidden constructs and capabilities (samplers, gl_*, main(), …)
Loop normalisationRewrites every loop to a constant bound
Static cost modelWeighted ops per pixel against a budget
Input bindingsInputs are bound around your code, so the program text stays fixed
Sandboxed compileCompiles the program in a sandbox
Sandboxed fuzz renderRenders extreme input values and times it
StoreSaves the vetted program

Two details worth knowing:

Loops are rewritten, not rejected. A loop that cannot be bounded is rewritten so it finishes.

Compilation has a time limit. A shader that takes too long to compile is rejected.

If your shader compiles but is expensive, it is not blocked — it ships with a reduced resolution cap.

Runtime protection

Server-side vetting bounds what a shader can be; it cannot bound what a particular GPU will do with it. So each shader is policed while it renders:

  • Frame times are measured while it renders.
  • If frames run long, resolution steps down: full → ½ → ¼ → frozen → disabled.
  • Enough slow reports from different viewers quarantine the shader for the whole workspace.
  • Offscreen shaders pause, so a gallery of them costs nothing.

You can also revoke a shader yourself from the Shaders page (Projects → Shaders, /spaces/<workspace>/templates/shaders). Status is enforced on every fetch, so revoking stops it loading everywhere at once — there is no cache to wait out.

Editing and versioning

The workspace library shows the total shader count and loads cards in batches with Load more. Cards identify the creator, last modification time, status, performance cost, and any tags.

Tags are optional, normalized to lowercase hyphenated labels, and limited to eight per shader. Tag-only edits do not re-run GPU vetting. Deleting a shader is permanent and immediately prevents designs from loading it, so the library asks for confirmation first.

Shaders are content-addressed by the hash of their generated program:

  • Editing the source or the inputs re-runs the full pipeline and produces a new hash. An approval is never inherited by code that was not vetted.
  • A rejected edit leaves the stored shader exactly as it was.
  • Re-submitting identical source is free — it de-duplicates instead of storing a second copy.
  • A successful re-vet clears any accumulated watchdog trips, since those belonged to the previous program.

Authoring with the assistant

The workspace assistant can write shaders for you — "make me a blueprint-style grid background with navy fill and controls for cell size and line thickness". It reads the built-in presets for the convention, authors the source and manifest, and submits it through the same vetting pipeline. If the result is rejected it sees the failing stage and the compiler log, and fixes it. It cannot store a shader by any other route.

API

MethodPathPurpose
POST/api/v1/shadersVet and create. 422 with a stage report if rejected
GET/api/v1/shadersList the workspace's shaders (the generated program is omitted); ?public=true lists published shaders from every workspace, no auth needed
GET/api/v1/shaders/:idFetch one of the workspace's shaders, or any published one, including the vetted program. 410 if revoked or quarantined
PUT/api/v1/shaders/:idUpdate; source or input changes re-vet. `public: true
DELETE/api/v1/shaders/:idDelete
POST/api/v1/shaders/:id/statusRevoke, quarantine or restore
POST/api/v1/shaders/:id/telemetryReport a client watchdog trip

Webhook events: shader.created, shader.updated, shader.deleted, shader.statusChanged, shader.quarantined — subscribe in Settings → Developers.