Skip to content

About

GPU modules on TypeGPU for lit 3D scenes, post-processing, particles, text, glTF models and simulations, on the web and React Native

Topics

Resources

Contributing

Stars

119 stars

Watchers

0 watching

Forks

Repository files navigation

TypeGPU Kit is a set of GPU modules on TypeGPU, for the web and React Native. It covers rendering, post-processing, particles, text and simulation. Use the modules you want and write the rest yourself. A module borrows your TypeGPU root and records into the encoder or pass you give it. You own the loop, the canvas and the pass order, and each frame ends in one submit.

import { tgpu } from 'typegpu';
import { bloom, frames, finish, targets } from '@typegpu/kit';
import * as web from '@typegpu/kit/web';

const root = await tgpu.init();
const surface = web.surface(root, document.querySelector('canvas')!);
const screen = targets.create(root, surface, { hdr: { format: 'rgba16float', sampled: true } });
const source = () => screen.textures.hdr;

const glow = bloom.create(root, { source });
const final = finish.create(root, { format: surface.format, source, glow });

frames.animate(
  frames.create(root, (frame) => {
    screen.fit();

    const scene = frame.encoder.beginRenderPass({ colorAttachments: { view: screen.views.hdr } });
    // the scene, in linear colour
    scene.end();

    glow.record(frame);
    final.record(frame, surface.view(frame));
  }),
);

Install

Start a new Vite project with the kit, the TypeGPU plugin and one of four starter scenes:

npm create @typegpu/kit my-scene

Or add the kit to a project you have:

pnpm add @typegpu/kit typegpu @typegpu/noise @typegpu/color
pnpm add -D vite unplugin-typegpu typescript@npm:tsover@6.0.2 @webgpu/types

tsover, TypeGPU's fork of TypeScript, is optional. It type-checks vector operators such as a * b in your 'use gpu' functions. With plain TypeScript, write them as functions, such as std.mul(a, b). The web entries need neither tsover nor React.

Setting up a project covers the bundler plugin and React Native.

A frame

The fish tank's frame function wired to the commands it records: a compute pass, a copy, the shadow and scene passes, 11 bloom passes and the final pass, then one submit

You make modules once, at setup, from your root. Each frame, the loop hands its encoder to the modules you call, in the order you call them. The fish tank's frame records one compute pass, a copy when it reads the bites back, and 14 render passes: the shadow, the scene, 11 for bloom and the final pass. Then it submits once.

What's in it

  • Frame: a frame loop, clocks with fixed steps and springs, coroutines, pipeline warm-up, helpers for writing modules and an owner that frees what a scene made.
  • Passes and targets: scene passes, last-frame history, render targets that resize together, textures baked from a shader function, mip chains, cameras and shared bind groups.
  • Data on the GPU: tables of rows, live lists, state machines, a neighbour grid, workgroup reduce and scan, and a radix sort.
  • Reading back: buffer readback, event counters, a picker and dynamic resolution.
  • Rendering: shapes, a mesh pool that holds them and glTF models, instances, impostors, skinned poses, lines with joins, caps and dashes, lighting with a sun, sky, fog, point lights and shadows, environment light, physically based shading and materials, and ambient occlusion.
  • Post-processing: bloom, auto exposure, FXAA, TAA, depth of field, and a final pass with tone curves, grading, a vignette and dither.
  • Particles and text: particles with your own update and shading, trails, and MSDF text from fonts you bake at build time, laid out in JavaScript.
  • Assets: a glTF reader with skins and animation clips, images from files, pixels or Radiance HDR, and camera and video frames.
  • Hosts: web and React Native canvases, scene files hosted on either, and scenes on a worklet runtime with useScene.
  • Tools: a recording root for tests without a GPU, Dawn tests, GPU timers, a pipeline census and a GPU debug panel for any WebGPU page.

The module map shows every module by area.

Examples

Six examples: Ocean, Falling sand, Night market, Censer, Classroom and Jelly world

Every example opens full-screen, with a Profile button for the GPU debug panel, and its source is in packages/typegpu-kit-examples/src. The same examples run on an iPhone in the Expo app in apps/typegpu-kit-native.

Tutorials and recipes

Slime mould growing from a blob into a network

Tutorials build an example from an empty canvas, starting with Slime mould. Write a module builds a module of your own. Recipes combine modules for one job. The docs list them all.

Coding agents

The package ships a skill for coding agents at node_modules/@typegpu/kit/skills/typegpu-kit/SKILL.md. It holds the kit's rules and an index of every module, linked to the docs pages that ship as Markdown in the package's docs/. TypeGPU ships its own skill at node_modules/typegpu/skills/typegpu/SKILL.md. Install both with pnpm dlx @tanstack/intent@latest install, or name both in your own AGENTS.md. The site serves each page as Markdown too, listed in llms.txt.

Repository

pnpm install
pnpm dev      # docs and examples, in a WebGPU browser
pnpm dev:host # the same over LAN HTTPS, for WebGPU on a phone
pnpm test     # types, lint, format, unit and GPU tests, then the docs build

Community Discord

Join the Software Mansion Community Discord to chat about TypeGPU Kit, TypeGPU and other Software Mansion libraries.

TypeGPU Kit is created by Software Mansion

swm

Since 2012 Software Mansion is a software agency with experience in building web and mobile apps. We are Core React Native Contributors and experts in dealing with all kinds of React Native issues. We can help you build your next dream product – Hire us.

About

GPU modules on TypeGPU for lit 3D scenes, post-processing, particles, text, glTF models and simulations, on the web and React Native

Topics

Resources

Contributing

Stars

119 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages