wtc-gl

WebGL2,
without the boilerplate.

A lightweight toolkit for building fragment shaders, scroll-driven scenes, and simple WebGL scenes.

npm install wtc-gl View on GitHub
What is it?

WebGL2 primitives and high-level recipes that compose.

wtc-gl provides the scaffolding - programs, meshes, cameras, render loops, texture utilities - so you spend time on the interesting parts. Use just the pieces you need, or reach for the opinionated recipes.

FragmentShader

Full-screen fragment shaders

One class, one shader. FragmentShader creates a canvas, wires up u_time and u_resolution, and starts the render loop. Mouse, resize, and pixel-ratio are all handled for you.

View demo →
ScrollRenderer

Inline scenes on any element

One fixed canvas, scissor-tested viewports, one shared render loop. ScrollRenderer anchors independent WebGL programs to DOM elements - no iframes, no per-canvas GPU contexts, no scheduling jank.

View demo →
TransformFeedback

GPU particle simulations

TransformFeedback handles ping-pong buffers automatically. Write your velocity kernel in GLSL, read positions back as attributes - millions of particles without touching the CPU each frame.

View demo →
Demos

See the primitives in action.

Each demo isolates one or two core concepts - textures, framebuffers, webcam input, GPU particles - so you can pull the code apart and adapt it.

Video texture demo
FragmentShader Texture

Video texture

A video element sampled as a live Texture and fed into a fragment shader each frame. The onBeforeRender hook marks the texture dirty so the GPU always sees the current video frame.

Open demo →
Transform feedback particles demo
TransformFeedback Geometry Camera

GPU particle simulation

Thousands of particles simulated entirely on the GPU using TransformFeedback ping-pong buffers. Velocity is computed in a vertex shader and fed back as position attributes each frame - zero CPU involvement per particle.

Open demo →
A swarm of thousands of arrows gathering around the pointer
TransformFeedback Geometry Program

Swarm

8,192 agents chase the pointer through a flow field. One TransformFeedback simulation is stepped several times a frame without drawing, then drawn twice from the same buffers: as instanced arrows pointing along each agent's velocity, and as an additive glow. Position and velocity are captured interleaved, each agent's seed is a static attribute, and Reset restarts the simulation.

Open demo →
Framebuffer post-processing demo
Framebuffer Texture Program

Framebuffer post-processing

A scene rendered to an off-screen Framebuffer, then composited through a second pass. Demonstrates the render-to-texture pipeline for effects like bloom, blur, and feedback loops.

Open demo →
Verlet cloth simulation deforming a photo of sand
ScrollImage ScrollHTML ScrollRenderer

ScrollImage & ScrollHTML

Three scenes on one canvas. Scene 1: hue ripple at the cursor via Rodrigues rotation. Scene 2: a Verlet cloth simulation deforming an image — scroll to inject inertia, click to grab. Scene 3: the same cloth with a live HTML form as its texture using the experimental HTML-in-Canvas API.

Open demo →
A full-width rainbow plasma shader behind a dark card titled React ScrollRenderer
ScrollRendererProvider useScrollScene

React ScrollRenderer

The ScrollRenderer demo rebuilt with @wethegit/react-wtc-gl: a provider owns the canvas and render loop, hooks register scenes from components, and React state pauses the loop. Runs in StrictMode to exercise the cleanup paths.

Open demo →
Teal box modules coiled around a line on helical strands
useScrollScene RenderTarget GeometryAttribute

React Manifold Divider

A section divider: instanced box modules coil around a line on helical strands and flow along it. Each divider renders a float G-buffer offscreen, then composites outlines, AO and fog into its strip of the shared ScrollRenderer canvas.

Open demo →
Rings of box modules forming a funnel-shaped mandala
RenderTarget DollyCamera GeometryAttribute

Manifold Mandala

Thirty rings of instanced box modules form a funnel that reads as a mandala head-on. Rings spin, ripple and regrow as new shapes; click to sweep a new palette through them. The same float G-buffer and outline, AO and fog pass as the divider.

Open demo →
A rainbow plasma shader panel on a cream, dotted map, with region tabs along the bottom
ScrollRendererProvider useScrollScene

React DragWorld

A click-and-drag explorable world in the style of the Super Mario Odyssey site: a 4,400px map panned with momentum and elastic bounds, where shader regions registered with useScrollScene light up as you approach them.

Open demo →
A glowing blue Voronoi shader panel on a cream, dotted map, with region tabs along the bottom
ScrollRendererProvider useScrollScene

React DragWorld Infinite

The drag world wrapped into a torus: no edges, no bounds — each region is a single DOM element folded back around the seam while off-screen, with a compass pointing the shortest way home across the wrap.

Open demo →
A webcam portrait redrawn as speckled cellular-automaton noise, in warm and cool tones on black
Framebuffer Texture getUserMedia

Webcam cellular automata

A ping-pong Framebuffer runs Conway's Game of Life where webcam brightness seeds new cells. Living cells inherit the webcam's colour at the moment of their birth, creating a living portrait that evolves frame by frame.

Open demo →
A blue, softly glowing raymarched box nested inside a cube, on a dark background
Mesh Box DollyCamera

Raymarching on a mesh

A raymarching SDF rendered inside the volume of a rotating Box mesh. The fragment shader casts rays from each mesh surface point, infinitely repeating a frame-and-sphere lattice. The cube's model matrix is passed as a uniform so the SDF space rotates in sync with the geometry.

Open demo →
A winding ribbon of motion-blurred blocks, rendered in tiles
Framebuffer Drawable Renderer viewport

Progressive render

A raymarcher far too heavy for one frame, rendered a tile at a time. Each tile goes into one Framebuffer through a viewport, a composition pass adds it to the image so far in another, and the tile size adapts to keep frames responsive. Click for a new image.

Open demo →
The heading Scroll Image. over a dark blue, cloudy shader background
ScrollRenderer ScrollScene ScrollImage

Scroll blades

An editorial scroll layout: a fullscreen animated background via ScrollScene, four alternating image/text blades each using ScrollImage for cover-fit, parallax, and chromatic aberration — all on one shared WebGL context.

Open demo →
A glowing portal among boxes, showing a world of spheres
RenderTarget DollyCamera Renderer

Stencil & depth texture

A portal into another world, drawn with a RenderTarget whose depth and stencil share one texture. The stencil limits the second world to the portal, and a post pass samples the depth texture for fog and outlines. Switch views to see the depth and stencil on their own.

Open demo →
A galaxy of cubes beside an overview of the camera and its frustum
Mesh Renderer DollyCamera Camera InstancedMesh

Many meshes

A spiral galaxy of up to 6,000 separate meshes, each moved and rotated every frame. One pane is the camera you control; the other watches it from above, showing its frustum and only the meshes it didn't cull. Matrices, uniforms and render lists are updated in place, so the render loop makes almost no garbage. Switch to one InstancedMesh to draw the same galaxy in a single draw call, still culled cube by cube, for a fraction of the CPU time, and hover to pick out one cube with a Raycast.

Open demo →
Concentric rings of block and sphere modules in a shallow bowl, over a peach and mint sky
Geometry mergeGeometries Box Sphere Triangle DollyCamera

Building geometry

Concentric rings of modules, built in code and drawn as one mesh. Boxes and spheres placed with applyMatrix merge into a module, copies of the module (every other one mirrored) merge into a ring, and the rings merge into the sculpture. A regrow wave rebuilds one ring at a time while the shader grows it and explodes the sculpture, so it stays a single draw call. Flat and smooth shading come from toNonIndexed and mergeVertices.

Open demo →
A box, sphere, plane, cylinder, cone, torus, capsule and vase in two rows, with their triangle edges drawn
Box Sphere Plane Cylinder Torus Capsule Lathe NormalProgram VertexNormalsHelper FaceNormalsHelper

Primitives

Every built-in primitive side by side, with its options in the pane: segments, radii, partial sweeps and open ends. Changing an option rebuilds that shape. Switch between lit, a uv checker and NormalProgram in view or world space, flat and smooth shading, and turn off back-face culling to see inside the open shapes. The helpers add vertex normals, face normals and local axes to every shape, and clicking one shows the triangle and uv under the pointer. The vase is a Lathe of a 2D profile, and a cone is a Cylinder with radiusTop: 0.

Open demo →
A sphere, torus, checkered box, faceted sphere, two-tone capsule and open cup in a row on a grey floor, lit from the upper left by a small yellow sun
LitProgram Lights GridHelper AxesHelper WireMesh Raycast

Lighting

The built-in lit program, one option per shape: plain Lambert, a Blinn-Phong highlight, a texture map, flat shading, vertex colours and a double-sided open cylinder. Every shape shares one Lights, so moving the sun or changing the sky and ground colours relights them all. The light is fixed in the world as you orbit, and the highlights follow the camera. A GridHelper and AxesHelper mark the floor and origin, and a WireMesh can show each shape's triangles. Hover a shape to see a Raycast hit: the point, the surface normal, the face and the uv.

Open demo →
A low-poly floating island with pine trees, grey rocks, a lamp post with a glowing orange lamp and a wooden sign with an arrow
GLTFLoader Texture.fromURL InstancedMesh LitProgram

glTF

A floating island made in Blender and loaded from a .glb with GLTFLoader. Its materials become LitPrograms sharing one Lights: vertex-coloured rocks, a textured double-sided sign and an emissive lamp. The trees are exported with EXT_mesh_gpu_instancing, so they load as InstancedMeshes. Look through the file's camera, or hover to name the node under the pointer.

Open demo →
Twisting towers of navy and plum hexagons, rings of yellow and lilac triangles and pink pillars crowding a pale blue haze
FlyCamera Stage InstancedMesh litShading

Fly

Fly through endless space with a FlyCamera: drag to steer like a joystick, or use WASD or the arrows, Q and E to roll, R and F to change speed and space to stop. Each cell of space grows towers, spirals and rings of prisms from a small rule grammar, seeded by where it is, and cells are regrown ahead of you as you fly. Each cell is two InstancedMeshes, drawn with litShading and fog.

Open demo →
A clump of chunky coloured icons — red hearts, blue crosses, yellow bolts, green triangles and white discs — casting a soft shadow onto a dark backdrop
GLTFLoader Shadow InstancedMesh Raycast

Icon swarm

Five icons loaded from .glbs, their materials made into instanced LitPrograms so every copy of an icon is one InstancedMesh. Their convex colliders drive Rapier physics with no gravity: the icons drip in and clump, the pointer's Raycast pushes them aside and a click blasts them apart. They cast a Shadow onto each other and onto a backdrop drawn with shadowShading.

Open demo →
A pale cube with a spherical bite taken out of one corner, the hollow coloured orange, casting a shadow onto a grid floor
toManifold fromManifold LitProgram Shadow

CSG

Booleans with manifold-3d, which wtc-gl doesn't depend on: the demo loads the WASM and toManifold converts wtc-gl primitives for it. A cutter orbits through a box, cylinder, torus or extruded star and the subtraction, intersection or union is redone every frame. The cut faces keep the cutter's colour and its normals, flipped to face the right way.

Open demo →
A translucent trefoil-knot tube with small red, green and blue axes along its centre line
Curve Path Tube Extrude computeFrames Raycast

Paths

A tube swept along a Catmull-Rom curve through points you can drag. Markers compare samples spaced evenly by distance with parametric ones that bunch up, and axes show the rotation-minimising frames the tube follows, matched up around a closed trefoil. Twist and taper the tube, and switch alpha to see the uniform curve loop on a hairpin where the centripetal one doesn't. Tension tightens or loosens the curve, and the B-spline type is smoother still, pulled towards the points rather than through them. The extrude preset turns a flat outline and hole into a bevelled solid as you drag, with hard edges wherever it turns sharper than the crease angle. Handles are picked and dragged with a Raycast.

Open demo →
A tapered, dashed blue spiral line, with a short orange trail tapering to a point
Polyline

Lines

A spiral that draws itself on, tapered and dashed, with dashes measured by the distance travelled so they keep their length. As a billboard it always faces the camera, in pixels or world units. Switch it to a ribbon and it becomes a flat strip in world space that twists along its length and banks into its turns. Move the pointer to draw a trail, which pushes a new point every frame.

Open demo →
A dense, swirling cluster of thin orange and teal particle trails on a dark background
Polyline RenderTarget Framebuffer

Polyline trails

16,384 particles swirl through a force field, each drawn as a ribbon through its recent positions. A float simulation writes into a history texture, and one instanced Polyline with a custom vertex shader reads it back and extrudes each trail with polylineExtrude. Click for the next shot.

Open demo →
Get started

A shader on screen in five lines.

import { FragmentShader } from 'wtc-gl'
import myFrag from './my-shader.frag'

const fs = new FragmentShader({
  fragment: myFrag,
  container: document.querySelector('.canvas-wrap')
})

// u_time and u_resolution are wired up automatically.
// Add your own uniforms any time:
fs.setUniform('u_mouse', [x, y])

Install via npm, import from your bundler, and point it at a container. The canvas is created, sized, and animated for you.

For scroll-driven multi-scene layouts see ScrollRenderer →

Core

The building blocks.

Renderer

WebGL2 context creation, pixel-ratio handling, and the main render loop.

Program

Shader compilation, uniform management, and attribute binding in one place.

Mesh

Geometry + program pairing with transform hierarchy via parent/child scene graph.

Geometry

Triangle, Plane, and Box primitives; or supply your own attribute buffers.

Texture

Create textures from typed arrays, images, or video — with format helpers.

Framebuffer

Off-screen render targets for post-processing and ping-pong feedback.

Camera

Perspective and orthographic cameras with look-at and dolly helpers.

Uniform

Typed uniform wrappers that track dirty state and batch-upload efficiently.