◈ Rollshade Open the tool

Using Rollshade effects in three.js

Rollshade gives three.js games ready-made moves, status effects and placed effects. The easiest way to use them is the npm package rollshade (part 1). The tool can also export effects as files and generate looping TSL shaders you edit as node graphs (part 2). Everything runs on WebGPURenderer, which falls back to WebGL2.

Part 1 · The rollshade package

Install

npm i rollshade [email protected]

The package is the same runtime the tool uses, under the MIT License. It needs three r186 and a WebGPURenderer from three/webgpu, which falls back to WebGL2 on its own. Try everything in the demo game first if you like.

import * as THREE from 'three/webgpu';
import { FXSystem, effect } from 'rollshade';

const renderer = new THREE.WebGPURenderer({ antialias: true });
renderer.toneMapping = THREE.ACESFilmicToneMapping;
await renderer.init();

const fx = new FXSystem({ scene, camera, renderer, post: true, feel: true });
fx.add(effect('meteor', 'fire'));
await fx.prewarm();

const timer = new THREE.Timer();
renderer.setAnimationLoop((ms) => {
  timer.update(ms);
  fx.update(Math.min(timer.getDelta(), 0.05));
  fx.render();
});

Moves

A move is a complete attack, heal or warp: charge-up, travel, impact, lights and smoke. effect(recipe, element) makes its definition; fx.play() fires it and returns a handle whose hit events tell your game when to apply damage.

fx.play('fire-meteor', { from: hero.hand, to: enemy }).on('hit', (e) => enemy.damage(10 * e.power));

Status effects

Put a status on any mesh or animated character. Its textures stay, the pattern sticks to the surface while it animates, and the original materials come back when the status is gone.

await fx.prewarmStatus(enemyModel);                 // once per kind of model; it need not be in the scene
const frozen = fx.status(enemy, 'freeze', { duration: 1.2 });
frozen.on('full', () => (mixer.timeScale = 0));    // stopping the animation is up to you
frozen.stop();                                     // thaw; the ice shatters

Burn, freeze, shock, poison, petrify, dissolve, appear, bless, curse, shield and stun. progress (0–1) drives how far freeze, petrify and dissolve have spread; a shield ripples where you call impact(point). Statuses last until you stop them, or for lasts seconds (fx.status(enemy, 'burn', { lasts: 4 })); appear ends by itself. Browse them in the Status effects group of the Motion mode.

Placed effects

fx.loop('torch', new THREE.Vector3(2, 0, -3));
fx.loop('portal', gate.position, { rotation: Math.PI / 2, element: 'dark' });
const aura = fx.loop('aura', hero);          // follows the character
aura.stop();

Torch (torch), campfire (campfire), candles (candles), portal (portal), magic circle (sigil), save point (savepoint), barrier dome (barrier), aura (aura) and beacon (beacon). They come with simple low-poly stands; pass prop: false to put the effect on your own model. Loops share a fixed pool of point lights (loopLights, 4 by default) because changing the number of lights makes three.js recompile every material.

React Three Fiber

import { FX, useFX, Status, Loop } from 'rollshade/react';

<Canvas gl={async (props) => { const r = new THREE.WebGPURenderer(props); await r.init(); return r; }}>
  <FX effects={[effect('meteor', 'fire')]} feel>
    <Status target={enemyRef} name="burn" active={burning} />
    <Loop name="torch" position={[2, 0, -3]} />
  </FX>
</Canvas>

useFX() returns the system once it has prewarmed, for fx.play(). Needs React Three Fiber 9 or later.

Coming from WebGLRenderer

rollshade is written in TSL, which only WebGPURenderer runs, so a game on the classic WebGLRenderer switches renderers first. You do not lose devices without WebGPU: WebGPURenderer falls back to WebGL2 by itself. Meshes, lights, standard materials, textures, GLTF models, skinning and animation, loaders, controls and raycasting carry over. What changes (checked against three r186):

The step-by-step list with code is in the README under “Coming from WebGLRenderer”, and the three.js manual page “WebGPURenderer” gives the official overview.

With AI coding assistants

The package ships an agent skill at node_modules/rollshade/skills/rollshade/SKILL.md; install it for Claude Code, Cursor, Codex and others with npx skills add ./node_modules/rollshade/skills/rollshade. An overview for language models is at /llms.txt and the full reference at /llms-full.txt. Unknown names throw errors that list the valid ones, so an assistant can correct itself.

A request that works well: “Use the rollshade npm package for the spell effects in my three.js game. Read https://rollshade.tsuyatt.com/llms-full.txt first.” We tested it by having assistants with no prior knowledge build small games from these docs alone; what they stumbled on is now in the docs.

Performance

Part 2 · Exporting from the tool and the TSL shader lab

Every mode exports for the same shared runtime, rollshade-fx.js (also on npm as rollshade). The export area at the top of the right-hand panel works the same in every mode: Video…, Sprite sheet… and PNG save what you see, Download sample (.zip) gives you a project that runs with a double-click, and Project saves or reopens your work as a .json file. The Shader modes write a TSL module that does export default defineLoop(...): node materials, the meshes the effect needs and its bloom settings.

Set up the renderer

npm install three

The quickest start is Download sample (.zip): it holds the runtime, the effect as fx/<id>.js, an fx/index.js that imports it, a runnable example.html with the same code as example.js, a README.md and LICENSE.txt. To add an effect to your own project, copy the runtime and the definition (Definition .js and Runtime .js under Files) next to your script:

import * as THREE from 'three/webgpu';
import { FXSystem } from './rollshade-fx.js';
import fire from './fx/fire-loop-k3x9ab.js';

const renderer = new THREE.WebGPURenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.toneMapping = THREE.ACESFilmicToneMapping;
document.body.append(renderer.domElement);
await renderer.init();

const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(35, innerWidth / innerHeight, 0.05, 100);
camera.position.set(0, 1.6, 6);
camera.lookAt(0, 0.75, 0);

const fx = new FXSystem({ scene, camera, renderer, post: true });
fx.add(fire);

Import everything from three/webgpu, not from three. Loading both copies in one page breaks node materials. The definition imports its helpers from ../rollshade-fx.js; if you use the npm package instead, change that import to 'rollshade'.

A standalone effect

const h = fx.spawn(fire.id, { at: new THREE.Vector3(0, 0, 0) });

const timer = new THREE.Timer();
renderer.setAnimationLoop((ms) => {
  timer.update(ms);
  fx.update(Math.min(timer.getDelta(), 0.05));
  fx.render();
});

The effect stands on the ground at at and is about two units tall. at can also be an Object3D, which the effect follows; h.moveTo() moves it later and scale in the spawn options resizes it. Place as many as you like: they share one render pass and one bloom with the Motion effects, and the helpers are never duplicated.

An effect on a model

Effects made in Shader on a model take the object to decorate:

import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';

const gltf = await new GLTFLoader().loadAsync('hero.glb');
scene.add(gltf.scene);
scene.environment = myEnvironmentMap;

const h = fx.spawn(aura.id, { object: gltf.scene });

Time and the loop

fx.update(seconds) advances every placed effect, and each one sets its phase to (time / period) % 1. Every moving part repeats exactly once per period, so the effect always loops seamlessly. The period defaults to the loop length you picked in Rollshade; pass period to fx.spawn to change it. h.pause() and h.resume() stop and restart one effect, and setting h.time scrubs it.

Motion effects

Effects from the Motion mode are built differently from the other modes. Instead of one file that holds everything, you get two kinds of files:

Download sample (.zip) packs the runtime, its types, the chosen effects, an fx/index.js that imports them all, a runnable example.html with the same code as example.js, a README.md and LICENSE.txt. example.html opens straight from the folder with a double-click; no local server is needed. To put several effects in one sample, press Add this one under Several in one sample for each of them, then download them together.

import * as THREE from 'three/webgpu';
import { FXSystem } from './rollshade-fx.js';
import effects from './fx/index.js';

const fx = new FXSystem({ scene, camera, renderer, post: true, feel: true });
fx.add(...effects);
await fx.prewarm();

const h = fx.play('fire-projectile-k3', { from: hero.hand, to: enemy });
h.on('hit', (e) => enemy.damage(10 * e.power));

const timer = new THREE.Timer();
renderer.setAnimationLoop((ms) => {
  timer.update(ms);
  fx.update(Math.min(timer.getDelta(), 0.05));
  fx.render();
});

Sprite sheets for 2D games

Sprite sheet… plays the effect once and lays every frame out in one PNG. The dummies, the sword and the floor are left out; only the effect remains. For freeze, petrify, dissolve and appear, which change the body itself, tick Include the dummy.

Video

Video… plays the effect once from the start and writes WebM, MP4 or numbered PNGs. Choose the size and frame rate, the Part (the camera then centres on that part and follows a projectile), the Camera (the preview's view or the sprite sheet views), Zoom, the Background (the scene with floor and fog, black, or transparent, which needs WebM or PNG) and whether to show the caster and target. In the Shader modes it records whole loops instead (choose the length) and can turn the camera once per loop.

PNG and project files

PNG saves the current view at the chosen size (the long side, in pixels). Save .json under Project writes everything you set up, in every mode, and Open .json brings it back.

Bloom and your render loop

With post: true, fx.render() renders the scene and adds bloom only to the effects, so the rest of your scene does not glow. With Bloom ticked under Include, the definition carries the bloom settings you tuned, and the runtime uses the strongest of the effects that are placed. fx.setBloom() changes it while running.

If you already have your own post-processing, create the system with post: false and render as usual with renderer.render(scene, camera) or your own pipeline. The effect still writes its glow to the emissive output, so a bloom pass that reads emissive picks it up.

Adjusting the effect at runtime

h.uniforms holds the sliders from the Layers panel, named after the layer:

h.uniforms.flame1Intensity.value = 2;
h.uniforms.flame1Color.value.set('#ff8800');

Changing a uniform does not rebuild any shader, so it is cheap to animate every frame.

Removing the effect

h.stop();

stop puts the original materials back on the model, removes the meshes and particles the effect added and frees its GPU resources. fx.dispose() frees everything the system made.

Models without UVs

Some patterns can follow a mesh's UV layout. With Coordinates set to Auto, the code checks each mesh and uses its UVs when it has them and its positions when it does not, so models without UVs still work. If you know your models, choose UV only or Position only under Include to remove that branch from the code. Most patterns use positions in any case, so they stay attached to the surface and need no UVs.

What to include

The preview follows these switches, so what you see is what the code does.

TypeScript

The code is JavaScript. The sample carries rollshade-fx.d.ts (and the npm package its own types), so editors and TypeScript projects get types for the runtime; allow JavaScript files (allowJs) to import the definitions from TypeScript.

Troubleshooting

License

Everything you export from Rollshade (effect definitions and code, sprite sheets, images and videos) is released under CC0 1.0: no conditions, no credit needed. Use it, modify it, share it or sell it, commercial or not. The shared runtime (rollshade-fx.js, also on npm as rollshade) is under the MIT License, so keep its copyright notice. The helper functions based on psrdnoise are MIT too; keep the notice at the top of the file. three.js is MIT. Every ZIP carries LICENSE.txt. Models shown in images and videos keep their own license: the preset Rollpoly models are CC0 1.0 as well. See License and Terms of Use for the details.