---
title: "TypeShade Playground: compile a shader in your browser"
description: "Write a \"use typeshade\" file in the browser, compile it to WGSL and GLSL ES 3.00, run it on WebGPU or WebGL2, and read the diagnostics and the reflection."
url: https://typeshade.dev/playground/
language: en
---

# Playground

Try TypeShade in your browser. Choose an example or write your own shader, then inspect the generated code and rendering results.

[Quick Start](https://typeshade.dev/guide/quick-start/) [Language guide](https://typeshade.dev/guide/language/) [Gallery](https://gallery.typeshade.dev/) [Report a problem](https://github.com/typeshade/typeshade/issues/new)

## Start from an example

Each tile is one of the .shade.ts files in the compiler repository. Open one, change it, add files beside it, and bind your own images to its textures.

[Blank file](https://typeshade.dev/playground/#blank)

A fragment shader that reads `time`, `resolution` and `mouse`.

### Learning path

- [Module and host.ts First colour The smallest program that draws: one fragment entry that returns one colour for every pixel.](https://typeshade.dev/playground/#example=first-color)
- [Module and host.ts UV gradient The `position` builtin and a size uniform turn each pixel into a coordinate from 0 to 1, drawn as a gradient.](https://typeshade.dev/playground/#example=uv-gradient)
- [Module and host.ts Moving wave A `time` uniform field moves a wave, and `animate(canvas)` draws it once a frame.](https://typeshade.dev/playground/#example=moving-wave)
- [Module and host.ts SDF shapes Functions that return the distance to a circle and to a box, with `smoothstep` for a soft edge.](https://typeshade.dev/playground/#example=sdf-shapes)
- [Module and host.ts Tile pattern A `for` loop, an `if` and `fract` draw a pattern that repeats in tiles.](https://typeshade.dev/playground/#example=tile-pattern)
- [Module and host.ts Mandelbrot set A loop and `break` count how long a point stays near the origin, which colours the Mandelbrot set.](https://typeshade.dev/playground/#example=fractal)
- [Module and host.ts Palette A module constant array of four colours, blended with `mix` into one smooth ramp.](https://typeshade.dev/playground/#example=palette)
- [Module and host.ts Bouncing balls A `class Ball` with a method that moves it and one that measures a pixel against it; a function that changes the ball changes the caller's ball.](https://typeshade.dev/playground/#example=bouncing-balls)
- [Module and host.ts Double an array The first compute kernel: a `@compute` entry doubles each number of a storage array.](https://typeshade.dev/playground/#example=double-array)
- [Module and host.ts Image blur A 2D `@compute([8, 8])` entry averages each pixel of an image with its eight neighbours.](https://typeshade.dev/playground/#example=image-blur)
- [Module and host.ts Sum an array A function that takes an array and returns a number is a kernel function: its `for` loop runs on the GPU and the host awaits the sum.](https://typeshade.dev/playground/#example=sum-array)
- [Module and host.ts Parallel sum One workgroup adds up an array, halving its partial sums in `workgroup` memory with `workgroupBarrier()`.](https://typeshade.dev/playground/#example=parallel-sum)
- [Module and host.ts Histogram Many invocations count into shared bins with `atomicAdd`, so no count is lost.](https://typeshade.dev/playground/#example=histogram)
- [Module and host.ts Ray tracer A camera ray for each pixel, a `class Sphere`, a checkered floor and a shadow, built from the pieces of steps 1 to 8.](https://typeshade.dev/playground/#example=ray-tracer)

### Works

- [Class-based Capsule Corp. spaceship on Namek A TypeShade class-based scene of the Capsule Corp. spaceship on Namek.](https://typeshade.dev/playground/#example=capsule-corp-namek-class)
- [Domain warping fbm fed its own output.](https://typeshade.dev/playground/#example=domain-warp-twin)
- [Hillshade Shaded relief.](https://typeshade.dev/playground/#example=hillshade-twin)
- [Julia set Escape-time Julia fractal.](https://typeshade.dev/playground/#example=julia-twin)
- [Kaleidoscope The polar mirror fold.](https://typeshade.dev/playground/#example=kaleidoscope-twin)
- [Mandelbrot set The Mandelbrot set with smooth escape-time colouring.](https://typeshade.dev/playground/#example=mandelbrot-twin)
- [Ocean horizon A seascape from first principles.](https://typeshade.dev/playground/#example=ocean-twin)
- [Path tracer A small path tracer as ordinary TypeScript.](https://typeshade.dev/playground/#example=path-tracer)
- [Plasma The classic sum-of-sines plasma folded through an RGB palette.](https://typeshade.dev/playground/#example=plasma-twin)
- [Class-based 3D SDF ray tracer A 3D signed-distance-field renderer built with an abstract SdfShape base class and concrete Sphere, Box, Torus and Plane subclasses.](https://typeshade.dev/playground/#example=rt-renderer-class)
- [Starfield A textureless night sky.](https://typeshade.dev/playground/#example=starfield-twin)
- [Tunnel The demoscene tunnel.](https://typeshade.dev/playground/#example=tunnel-twin)
- [Voronoi A moving Voronoi pattern written in TypeScript syntax.](https://typeshade.dev/playground/#example=voronoi-twin)

### High precision

- [fp64 Burning Ship The Burning Ship fractal (fold |Re z|, |Im z| before squaring) zoomed onto its needle spike.](https://typeshade.dev/playground/#example=fp64-burning-ship-twin)
- [fp64 catastrophic cancellation The numerics-textbook plot on a GPU.](https://typeshade.dev/playground/#example=fp64-cancellation-twin)
- [fp64 checker plane A 1-unit checkerboard on a world plane.](https://typeshade.dev/playground/#example=fp64-checker-plane-twin)
- [fp64 long-uptime clock The long-uptime animation bug.](https://typeshade.dev/playground/#example=fp64-clock-twin)
- [fp64 deep zoom Emulated double precision (two-f32 df64).](https://typeshade.dev/playground/#example=fp64-deep-zoom-twin)
- [fp64 Julia set The Julia-set face of the double-float technique.](https://typeshade.dev/playground/#example=fp64-julia-twin)
- [Emulated doubles A shader that compares emulated `f64` and `f32` precision at a large world coordinate.](https://typeshade.dev/playground/#example=fp64-lane-stripes)
- [fp64 hyperbolic navigation A LORAN-style chart grid.](https://typeshade.dev/playground/#example=fp64-loran-twin)
- [fp64 distance estimate Mandelbrot boundary rendered by distance estimate (d = ½·|z|·ln|z|/|dz|) with precision split mid-formula.](https://typeshade.dev/playground/#example=fp64-mandelbrot-de-twin)
- [fp64 Newton fractal Newton’s method for z³ = 1, colour = which cube root a pixel falls into.](https://typeshade.dev/playground/#example=fp64-newton-twin)
- [fp64 relative-to-center Why planet-scale engines render relative-to-eye.](https://typeshade.dev/playground/#example=fp64-rtc-twin)
- [fp64 sine sweep sin(x) for x = a large base + a small on-screen sweep.](https://typeshade.dev/playground/#example=fp64-sine-sweep-twin)

### Feature examples

- [Runtime array length A bounds check for a kernel that processes a runtime-sized storage array.](https://typeshade.dev/playground/#example=array-length)
- [Array literals A fullscreen triangle whose corners come from two `array<f32, 3>` lists and whose colour comes from an `array<vec3, 3>` of stops weighted by an `array<i32, 3>`.](https://typeshade.dev/playground/#example=array-literal-ramp)
- [An array's methods Three lights in an `array<Light, 3>`, shaded with the array methods TypeScript developers commonly use.](https://typeshade.dev/playground/#example=array-methods)
- [Atomic histogram Many invocations count into one bin at once with `atomicAdd(bins[bin], 1)`, one indivisible step each; a storage struct field and a bare `storage<atomic<u32>>` binding show the other two shapes of location, and the value an atomic returns is what it held before.](https://typeshade.dev/playground/#example=atomic-histogram)
- [A vertex that returns only the position The smallest render pair.](https://typeshade.dev/playground/#example=bare-position)
- [Builtin breadth `reflect`, `refract` and `faceForward` light a bump, `transpose` and `determinant` read the host matrix, and the bit builtins (`firstLeadingBit`, `reverseBits`, `countOneBits`, `extractBits`, `insertBits`) band the screen, with `fwidthCoarse` marking where a band starts.](https://typeshade.dev/playground/#example=bit-bump)
- [Bitfield bands A fullscreen triangle whose colour is chosen by a `switch` over a band index built with `&=`, `|=`, `<<=`, `>>=` and `^=`, with `let x: f32` declared before it is assigned and the varyings returned as `{ pos, uv }` shorthand.](https://typeshade.dev/playground/#example=bitfield-bands)
- [Block scope Two sequential loops over `i`, a `p` in a loop body beside a `p` in an `if` arm, and an inner `p` that shadows the outer one.](https://typeshade.dev/playground/#example=block-scope)
- [Boolean vectors A comparison of two vectors is a vector of bools.](https://typeshade.dev/playground/#example=bool-select)
- [A builder chain, super on accessors, and statics a subclass inherits Shows how `return this` keeps a builder chain on the same object, while a chain starting with `new` uses a temporary.](https://typeshade.dev/playground/#example=class-builder)
- [Objects inside objects, a const that holds one, a field that holds a function, and an interface as a contract `ring.advance(dt)` calls `step` on its `Mover` field and passes the changed object by reference.](https://typeshade.dev/playground/#example=class-parts)
- [Getters, setters, private names and parameter properties A `class Ring` written the way TypeScript classes are.](https://typeshade.dev/playground/#example=class-syntax)
- [User clip planes Four user clip planes through `builtin<"clip_distances", ...>`, the vertex output the rasterizer reads before it rasterizes.](https://typeshade.dev/playground/#example=clip-planes)
- [Local functions that read and write the variables around them `ring` reads `p` and `width` from the fragment entry and adds to its `glow`, as a TypeScript closure does.](https://typeshade.dev/playground/#example=closures)
- [Compute reduction A @workgroup\_size compute kernel folding a window of an input storage buffer into one output element with reduce().](https://typeshade.dev/playground/#example=compute-reduction-twin)
- [Compare-exchange, uniform load, texture barrier Three workgroup synchronization operations: compare-exchange, uniform load and texture barrier.](https://typeshade.dev/playground/#example=compute-sync)
- [Converting constructors A fullscreen triangle whose corner comes from `vec2(vec2u(...))` and whose colour comes from an `f32`→`u32`→`f32` round trip.](https://typeshade.dev/playground/#example=convert-grid)
- [The WGSL-only textures A colour ramp as a `texture_1d<f32>`, two environment maps as a `texture_cube_array<f32>` picked by layer, a hand-written percentage-closer filter from `textureGatherCompare`, a `textureGather` of one channel from four texels, and a point light’s shadow as a `texture_depth_cube_array`.](https://typeshade.dev/playground/#example=cube-array-gather)
- [Cube and 3D textures, bias and gradients An environment map as a `texture_cube<f32>` looked up by direction, a colour-grading table as a `texture_3d<f32>` the shaded colour indexes, `textureSampleBias` and `textureSampleGrad`, and a point light’s shadow as a `texture_depth_cube` compared by the direction from the light.](https://typeshade.dev/playground/#example=cube-env)
- [Cutout (source language) `discard` in a helper the fragment entry calls, with `fwidth` softening the rim and `saturate`, `exp2` and `**` shaping the falloff.](https://typeshade.dev/playground/#example=cutout)
- [Default parameter values Three helpers with default parameters, each called with a different argument omitted.](https://typeshade.dev/playground/#example=default-args)
- [Feedback trail A dot that leaves a trail.](https://typeshade.dev/playground/#example=feedback-trail)
- [A generic class by monomorphisation A `class Slot<T>` used at f32 and at vec3, so the module carries `Slot_f32` and `Slot_vec3` as separate structs, each with its own constructor and its own copy of every method.](https://typeshade.dev/playground/#example=generic-class)
- [Generics by monomorphisation Three generic helpers, each compiled once per set of argument types the file calls it with.](https://typeshade.dev/playground/#example=generic-helpers)
- [Console from the GPU `console.log("i =", gid.x, p)` inside a compute kernel.](https://typeshade.dev/playground/#example=gpu-console)
- [Gradient pass A two-colour vertical gradient with a biasable blend.](https://typeshade.dev/playground/#example=gradient-twin)
- [Hello triangle The smallest complete TypeShade program.](https://typeshade.dev/playground/#example=hello)
- [No entry point Hello camera uniform A `Camera` class of `mat4` + `vec3` behind `uniform<Camera>`, read by a plain helper function.](https://typeshade.dev/playground/#example=hello-camera)
- [Hello uniform A bare `declare const scale: uniform<f32>` keeps the same numeric host value on both targets.](https://typeshade.dev/playground/#example=hello-uniform)
- [Hello uniform block A `Uniforms` class behind `uniform<T>` groups several values in one std140 block on both targets.](https://typeshade.dev/playground/#example=hello-uniform-struct)
- [Hello vertex attributes Vertex input from a buffer rather than from `vertex_index`.](https://typeshade.dev/playground/#example=hello-vsin)
- [Hello varyings The triangle again, now carrying a `uv` varying from the vertex stage into the fragment stage through a shared `VsOut` interface.](https://typeshade.dev/playground/#example=hello-vsout)
- [Functions that take a function `cover` and `around4` accept a distance-field function and compile a copy for each function passed to them.](https://typeshade.dev/playground/#example=higher-order)
- [An integer varying, and the interpolation it has no choice about Entry IO as WGSL declares it.](https://typeshade.dev/playground/#example=id-pick)
- [Imported noise Clouds drawn with the `fbm` of another shader file.](https://typeshade.dev/playground/#example=imported-noise)
- [Return types the body says Each function omits its return type, which TypeShade infers from the value its body returns.](https://typeshade.dev/playground/#example=inferred-returns)
- [Integer abs and dot Integer `abs` and `dot`, which GLSL ES 3.00 does not provide for these input types.](https://typeshade.dev/playground/#example=integer-math)
- [Module and host.ts An array's methods in a kernel function `sumOfSquares`, `scale` and `firstAbove` use array methods to reduce, write and search kernel data.](https://typeshade.dev/playground/#example=kernel-array-methods)
- [No entry point A kernel that writes an image `invert` reads a `texture_2d<f32>` and writes the result to a `texture_storage_2d` in a kernel loop.](https://typeshade.dev/playground/#example=kernel-image-invert)
- [Module and host.ts A kernel that appends with push `strong` uses `out.push(i)` to append the index of each element above a threshold.](https://typeshade.dev/playground/#example=kernel-push)
- [Module and host.ts A kernel that collects unique labels in a Set `labels` collects nonzero pixel labels in a `Set<u32>`, while `latest` keeps each key's last value in a `Map<u32, f32>`.](https://typeshade.dev/playground/#example=kernel-set-unique)
- [Module and host.ts A loop that runs as a kernel A terrain kernel that processes each element of a runtime-sized output array.](https://typeshade.dev/playground/#example=loop-kernel)
- [No entry point Loops that run on the CPU One loop for each rule of the independence proof (R1 to R6) that the proof refuses.](https://typeshade.dev/playground/#example=loop-on-cpu)
- [Module and host.ts Reductions in a loop A sum, a mean and a variance, and a histogram, each a loop over an array.](https://typeshade.dev/playground/#example=loop-reduction)
- [No entry point A loop over an array of structs The particle step as a loop over `array<Particle>`.](https://typeshade.dev/playground/#example=loop-struct-array)
- [Loops over data The three loops a program over data writes, through Tint and a real WebGL2 context.](https://typeshade.dev/playground/#example=loops-over-data)
- [The mixin pattern A `function Tinted(Base)` whose body is one `return class extends Base { ... }`, applied to two different geometry classes.](https://typeshade.dev/playground/#example=mixin-surface)
- [Module constants A module-scope constant of every scalar type the compiler allows.](https://typeshade.dev/playground/#example=module-const)
- [A multisampled texture, resolved by hand An MSAA render target as a `texture_multisampled_2d<f32>` read one sample at a time with `textureLoad(t, coords, sampleIndex)` and averaged over `textureNumSamples`, and its depth attachment as a `texture_depth_multisampled_2d`.](https://typeshade.dev/playground/#example=msaa-resolve)
- [Matrices beyond mat4 Uses `mat3` for a normal matrix, and demonstrates matrix truncation, transpose and multiplication.](https://typeshade.dev/playground/#example=normal-matrix)
- [Null, undefined and present values Nullable classes and members retain three states through optional chaining.](https://typeshade.dev/playground/#example=null-values)
- [Optional fields, elements and parameters A struct field, an array element and a parameter hold `T | undefined` (§76, change 0093).](https://typeshade.dev/playground/#example=optional-fields)
- [Optional values: T | undefined A function, a local and a callback hold `T | undefined`, and the compiler carries whether the value is there.](https://typeshade.dev/playground/#example=optional-values)
- [A method that changes its object A `class Body` whose `step`, `turn` and `advance` assign to `this`, so each takes its object by reference.](https://typeshade.dev/playground/#example=orbit-inout)
- [Packed 4x8 integer builtins The eight builtins that read a `u32` as four bytes or write four back.](https://typeshade.dev/playground/#example=packed-bytes)
- [Packing, bitcast and the constructors Examples of packing, bitcast and constructor operations available to TypeShade shaders.](https://typeshade.dev/playground/#example=packing-bitcast)
- [Module vector and array constants A fullscreen triangle banded by a module-scope `array<vec4, 3>` palette and an `array<f32, 3>` of stops, with a `vec3` constant built from an earlier scalar one.](https://typeshade.dev/playground/#example=palette-const)
- [Methods that change their object A `class Particle` whose `step`, `bounce` and `tick` assign to `this`, called on a storage element.](https://typeshade.dev/playground/#example=particle-step)
- [A conditional on a struct and on an array Two arms that are structs, and two that are fixed-length arrays, chosen at run time.](https://typeshade.dev/playground/#example=pick-composite)
- [Per-invocation state A plain top-level `let seed: u32` is WGSL's `var<private>`, one copy per invocation that every function of the invocation shares.](https://typeshade.dev/playground/#example=private-state)
- [Class methods A `class Ray` with a constructor, a method and a static function, and a `class Sphere` whose `hit(ray)` method returns the distance along the ray.](https://typeshade.dev/playground/#example=ray-class)
- [Objects are passed as JavaScript passes them A function that writes a field or an element of its parameter changes the caller's object, with no mark on the parameter or at the call.](https://typeshade.dev/playground/#example=reference-parameters)
- [A method that changes its object and returns a value A `class Rng` whose `next()` advances the generator's state and returns the draw.](https://typeshade.dev/playground/#example=rng-method)
- [A sample under a branch, and the compiler rewrites it WGSL requires `textureSample` to be called from uniform control flow.](https://typeshade.dev/playground/#example=sample-branch)
- [Separable blur A blur in two passes.](https://typeshade.dev/playground/#example=separable-blur)
- [A shadow map, read by comparison A depth texture read through a `sampler_comparison` with `textureSampleCompare` and `textureSampleCompareLevel`, on a plain 2D shadow map and on a cascade array.](https://typeshade.dev/playground/#example=shadow-compare)
- [Inheritance An `abstract class Shape` with a concrete method and an abstract one, two classes that extend it, and one that extends a subclass and calls `super`.](https://typeshade.dev/playground/#example=shape-inheritance)
- [A storage texture An image a compute entry writes by texel coordinate, with no sampler and no filtering.](https://typeshade.dev/playground/#example=storage-texture)
- [Subgroup reduction before an atomic `subgroupAdd` folds each subgroup's values in one instruction and `subgroupElect` picks one lane to add the fold into the bin with `atomicAdd`.](https://typeshade.dev/playground/#example=subgroup-reduce)
- [Texture, sampler and overrides A fullscreen triangle sampling a `texture_2d<f32>` through a `sampler`, tinted by two `override<f32>` specialization constants.](https://typeshade.dev/playground/#example=textured-quad)
- [A tuple and a branded alias A tuple is a list of a length the type fixes, which is what `array<T, N>` is, so `[f32, f32]` is `array<f32, 2>`.](https://typeshade.dev/playground/#example=tuple-and-brand)
- [Twin IO structs Two IO structs with identical fields, a vertex output and a fragment input, with object literals in all three positions that declare which one they build.](https://typeshade.dev/playground/#example=twin-structs)
- [A uniform holding a list A `uniform` holding `array<f32, 4>`.](https://typeshade.dev/playground/#example=uniform-array)
- [Workgroup size override One `override<u32>` sets the compute entry's workgroup size and the outer length of its shared scratch array.](https://typeshade.dev/playground/#example=workgroup-override)
- [Workgroup reduction 64 invocations sum 64 values into one through workgroup memory, with `workgroupBarrier()` ordering the rounds.](https://typeshade.dev/playground/#example=workgroup-reduce)
- [Workgroup scratch memory `let tile: workgroup<array<f32, 64>>` is WGSL's `var<workgroup>`, one copy per workgroup its invocations share, here as scratch each invocation owns a slot of, beside a workgroup array of atomics and a per-invocation counter.](https://typeshade.dev/playground/#example=workgroup-scratch)
- [Two-dimensional workgroup `@compute([8, 8])` is WGSL's `@workgroup_size(8, 8)`.](https://typeshade.dev/playground/#example=workgroup-tile-2d)

### Host examples

- [Module and host.ts Draw into a canvas A full-screen `@fragment` entry and the host that draws it.](https://typeshade.dev/playground/#example=host-draw)
- [Module and host.ts Dispatch a compute entry A `@compute(...)` entry and its host.](https://typeshade.dev/playground/#example=host-compute)
- [Module and host.ts Call a kernel function Two kernel functions and the host that calls them.](https://typeshade.dev/playground/#example=host-kernel)
- [Module and host.ts Keep data on the GPU Three kernel functions and a host that chains them over `Buffer`s that `array()` makes.](https://typeshade.dev/playground/#example=host-resident)
- [Module and host.ts One helper on the CPU and the GPU A terrain `height` function that the fragment entry draws on the GPU and the host calls on the CPU.](https://typeshade.dev/playground/#example=host-helper)
- [Module and host.ts String keys and Record A fixed set of channel names becomes `u32` ids, and a `Record` becomes an array in id order.](https://typeshade.dev/playground/#example=string-keys-record)
- [Module and host.ts Run the compiled program A vertex and a fragment entry, and a host that runs them as an engine does.](https://typeshade.dev/playground/#example=host-program)
- [Module and host.ts Fuse a chain of kernel calls Five kernel functions and a host that calls them inside `fuse()` from `typeshade/fuse`.](https://typeshade.dev/playground/#example=loop-fuse)
- [Module and host.ts Collect into a Set and a Map Four kernel functions accept JavaScript `Set` and `Map` values, and a host calls them.](https://typeshade.dev/playground/#example=host-set-unique)

**hello.shade.ts**

The smallest program that draws: one fragment entry that returns one colour for every pixel.

`TS`

Diagnostics Ready to compile

Loading the program…

Compile a module with a vertex entry and a fragment entry to see it drawn.
