Authoring guide

Rendered from AUTHORING.md at commit d894fc0. The package is imported here by its 0.1.0 name, typeshade.

Authoring shaders with typeshade

This is the developer guide for writing a shader in typeshade. The DSL is a TSL-style (three.js Shading Language) graph: you author typed value expressions and imperative statements in TypeScript, and one IR emits both WGSL (GPU) and a CPU oracle (parity checks) from the same source.

The goal of the recent work was to remove ceremony. You no longer hand-write WGSL var names, return-type tokens, callFn('name', …) strings, .field('name', type) accessors, or f32() wrappers around literals. This guide documents the surface that landed.

Import paths. Author from the package’s public barrel — it re-exports the whole core/** authoring + emit surface (the IR, the SoT layout declarators, the WGSL/GLSL backends, the lint passes, the CPU oracle, and reflect()):

import { fn, module, vec4, If, Switch, when, emitModule, reflect, … } from 'typeshade'
import { ioStruct, uniformStruct, structDecl, builtin, location, storageBuffer, resource } from 'typeshade'

Application shader graphs live in the consuming project and author through this same barrel like any other consumer — this package ships the authoring surface, never a project’s shaders. Inside the package, the barrel re-exports the IR via the core/ir barrel and the layout helpers via core/sot — never import a deep file directly.

Reflection. reflect(module) recovers the pipeline metadata (bind groups, std140/std430 struct byte layouts, vertex attributes, entry signatures) as a target-neutral object; the std140/std430 offset engine is also exposed standalone as wgslLayout(struct, kind). Both are read-only over the IR and never run on the emit path. See core/reflect.ts.

Edit this page