Index of every page on this site: llms.txt
All skills
Run it yourself

Use when using the Three.js WebGPU renderer, node-based materials, TSL (Three Shading Language), or compute shaders. Prevents the common mistake of not checking browser support, missing async init, or using GLSL with WebGPU. Covers WebGPURenderer, node materials, TSL, compute shaders, WebGL fallback, migration guide. Keywords: WebGPU, WebGPURenderer, TSL, Three Shading Language, node material, compute shader, WGSL, MeshStandardNodeMaterial, next-gen rendering, modern GPU, WebGPU setup.

Use this Skill: https://skilld.dev/gh/impertio-studio/three.js-claude-skill-package/threejs-impl-webgpu

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesexamples.md

≈1.8k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Working Code Examples (Three.js WebGPU)

Example 1: Minimal WebGPU Scene with Fallback

import * as THREE from 'three/webgpu';
import { WebGPU } from 'three/webgpu';

async function init() {
  let renderer;

  if (WebGPU.isAvailable()) {
    renderer = new THREE.WebGPURenderer({ antialias: true });
    await renderer.init();
  } else {
    renderer = new THREE.WebGLRenderer({ antialias: true });
  }

  renderer.setSize(window.innerWidth, window.innerHeight);
  renderer.setPixelRatio(window.devicePixelRatio);
  document.body.appendChild(renderer.domElement);

  const scene = new THREE.Scene();
  const camera = new THREE.PerspectiveCamera(
    75, window.innerWidth / window.innerHeight, 0.1, 1000
  );
  camera.position.z = 5;

  const geometry = new THREE.BoxGeometry();
  const material = new THREE.MeshStandardNodeMaterial({ color: 0x00ff00 });
  const cube = new THREE.Mesh(geometry, material);
  scene.add(cube);

  const light = new THREE.DirectionalLight(0xffffff, 1);
  light.position.set(5, 5, 5);
  scene.add(light);

  renderer.setAnimationLoop((time) => {
    cube.rotation.x = time * 0.001;
    cube.rotation.y = time * 0.0015;
    renderer.render(scene, camera);
  });
}

init();

Example 2: TSL Custom Material with Animated Color

import * as THREE from 'three/webgpu';
import { color, oscSine, time, mix, vec4 } from 'three/tsl';

async function init() {
  const renderer = new THREE.WebGPURenderer({ antialias: true });
  await renderer.init();
  renderer.setSize(window.innerWidth, window.innerHeight);
  document.body.appendChild(renderer.domElement);

  const scene = new THREE.Scene();
  const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 100);
  camera.position.z = 3;

  // Create node material with animated color
  const material = new THREE.MeshStandardNodeMaterial();
  const colorA = color(0xff0000); // red
  const colorB = color(0x0000ff); // blue
  const t = oscSine(time);        // oscillate 0-1 over time
  material.colorNode = vec4(mix(colorA, colorB, t), 1.0);

  const sphere = new THREE.Mesh(new THREE.SphereGeometry(1, 32, 32), material);
  scene.add(sphere);

  const light = new THREE.DirectionalLight(0xffffff, 2);
  light.position.set(3, 3, 3);
  scene.add(light);
  scene.add(new THREE.AmbientLight(0x404040));

  renderer.setAnimationLoop(() => {
    renderer.render(scene, camera);
  });
}

init();

Example 3: Vertex Displacement with TSL

import * as THREE from 'three/webgpu';
import { positionLocal, normalLocal, sin, time, float, vec3 } from 'three/tsl';

async function init() {
  const renderer = new THREE.WebGPURenderer({ antialias: true });
  await renderer.init();
  renderer.setSize(window.innerWidth, window.innerHeight);
  document.body.appendChild(renderer.domElement);

  const scene = new THREE.Scene();
  const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 100);
  camera.position.z = 4;

  const material = new THREE.MeshStandardNodeMaterial({ color: 0x44aaff });

  // Displace vertices along their normals using a sine wave
  const displacement = sin(
    positionLocal.y.mul(float(4.0)).add(time.mul(float(2.0)))
  ).mul(float(0.3));

  material.positionNode = positionLocal.add(normalLocal.mul(displacement));

  const geometry = new THREE.SphereGeometry(1, 64, 64);
  const mesh = new THREE.Mesh(geometry, material);
  scene.add(mesh);

  const light = new THREE.DirectionalLight(0xffffff, 2);
  light.position.set(5, 5, 5);
  scene.add(light);
  scene.add(new THREE.AmbientLight(0x222222));

  renderer.setAnimationLoop(() => {
    renderer.render(scene, camera);
  });
}

init();

Example 4: Compute Shader — Particle Position Update

import * as THREE from 'three/webgpu';
import {
  compute, storage, float, vec3, Fn,
  globalId, sin, cos, time
} from 'three/tsl';

async function init() {
  const renderer = new THREE.WebGPURenderer({ antialias: true });
  await renderer.init();
  renderer.setSize(window.innerWidth, window.innerHeight);
  document.body.appendChild(renderer.domElement);

  const scene = new THREE.Scene();
  const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
  camera.position.z = 50;

  const particleCount = 10000;

  // Create storage buffer for positions
  const positionAttribute = new THREE.StorageBufferAttribute(
    new Float32Array(particleCount * 3), 3
  );

  // Initialize positions
  for (let i = 0; i < particleCount; i++) {
    positionAttribute.setXYZ(i,
      (Math.random() - 0.5) * 40,
      (Math.random() - 0.5) * 40,
      (Math.random() - 0.5) * 40
    );
  }

  // Compute shader: update positions with circular motion
  const positionStorage = storage(positionAttribute, 'vec3', particleCount);
  const computeFn = Fn(() => {
    const idx = globalId.x;
    const pos = positionStorage.element(idx);
    const angle = time.add(float(idx).mul(float(0.01)));
    pos.x.assign(sin(angle).mul(float(20.0)));
    pos.z.assign(cos(angle).mul(float(20.0)));
  });

  const computeNode = compute(computeFn, particleCount);

  // Create points geometry
  const geometry = new THREE.BufferGeometry();
  geometry.setAttribute('position', positionAttribute);

  const material = new THREE.PointsNodeMaterial({
    size: 0.2,
    sizeAttenuation: true,
    color: 0x00ffaa,
  });

  const points = new THREE.Points(geometry, material);
  scene.add(points);

  renderer.setAnimationLoop(async () => {
    await renderer.computeAsync(computeNode);
    renderer.render(scene, camera);
  });
}

init();

Example 5: WebGPU Post-Processing with Bloom

import * as THREE from 'three/webgpu';
import { PostProcessing } from 'three/webgpu';
import { pass, bloom, renderOutput } from 'three/tsl';

async function init() {
  const renderer = new THREE.WebGPURenderer({ antialias: true });
  await renderer.init();
  renderer.setSize(window.innerWidth, window.innerHeight);
  renderer.toneMapping = THREE.ACESFilmicToneMapping;
  document.body.appendChild(renderer.domElement);

  const scene = new THREE.Scene();
  const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 100);
  camera.position.z = 5;

  // Emissive sphere for bloom effect
  const material = new THREE.MeshStandardNodeMaterial({
    color: 0x000000,
    emissive: 0xff6600,
    emissiveIntensity: 2,
  });

  const sphere = new THREE.Mesh(new THREE.SphereGeometry(1, 32, 32), material);
  scene.add(sphere);
  scene.add(new THREE.AmbientLight(0x111111));

  // Set up post-processing pipeline
  const postProcessing = new PostProcessing(renderer);
  const scenePass = pass(scene, camera);
  const bloomPass = bloom(scenePass, {
    strength: 1.5,
    radius: 0.4,
    threshold: 0.6,
  });
  postProcessing.outputNode = renderOutput(bloomPass);

  renderer.setAnimationLoop((time) => {
    sphere.rotation.y = time * 0.001;
    postProcessing.render();
  });
}

init();

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts5mo3 checks · Risk SAFE
  • Gen Agent Trust Hub5mo

    This skill provides comprehensive documentation and best practices for using the Three.js WebGPU renderer and Three Shading Language (TSL). It is entirely educational and contains no malicious instructions or code.

  • Socket5mo

    No alerts

  • Snyk5mo

    Risk: LOW · No issues

Signed by skilld at 6c190f0. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Steadyupdated 8 months ago
metadata
{
  "author": "OpenAEC-Foundation",
  "version": "1.0"
}
Other metadata
compatibility
Designed for Claude Code. Requires Three.js r160+. WebGPU: Chrome 113+, Safari 18+.

README badge

README badge for impertio-studio/three.js-claude-skill-package/threejs-impl-webgpu