Webgpu Threejs Tsl

dgreenheck/webgpu-claude-skill/skills/webgpu-threejs-tsl

作者 dgreenheckaf2319bd01bb7cc881267a9ef42cafdaf5e9029d無授權條款1.2K 個星標收錄於 2026年10月9日更新於 2026年10月9日儲存庫6 個月前更新

Comprehensive guide for developing WebGPU-enabled Three.js applications using TSL (Three.js Shading Language). Covers WebGPU renderer setup, TSL syntax and node materials, compute shaders, post-processing effects, and WGSL integration. Use this skill when working with Three.js WebGPU, TSL shaders, node materials, or GPU compute in Three.js.

AI 產生的概覽

指導使用 TSL 節點著色器開發支援 WebGPU 的 Three.js 應用,並提供文件、範例與範本。

功能
提供參考文件與程式碼範例,用於以 WebGPU 渲染器並使用 TSL(Three.js 著色語言)建構 Three.js 應用。內容涵蓋渲染器初始化、節點材質、計算著色器、後處理效果、WGSL 整合、裝置遺失處理以及裝置限制。同時附上可執行的範例指令碼與專案、自訂材質、粒子與後處理的起始範本。
適用情境
適用於為 Three.js 設定 WebGPU 渲染器、以 TSL 撰寫自訂著色器材質、撰寫 GPU 計算著色器或建立後處理管線。也用於將 GLSL 著色器移轉至 TSL,以及實作粒子、水面、地形等視覺效果。
執行需求
需要一個使用 three 套件及其 WebGPU 進入點與 TSL 模組的 JavaScript 專案,以及支援 WebGPU 的執行環境或瀏覽器。附有可執行的範例與範本指令碼;未說明需要憑證或網路存取。

WebGPU Three.js with TSL

TSL (Three.js Shading Language) is a node-based shader abstraction that lets you write GPU shaders in JavaScript instead of GLSL/WGSL strings.

Quick Start

javascript
import * as THREE from 'three/webgpu';import { color, time, oscSine } from 'three/tsl';
const renderer = new THREE.WebGPURenderer();await renderer.init();
const material = new THREE.MeshStandardNodeMaterial();material.colorNode = color(0xff0000).mul(oscSine(time));

Skill Contents

Documentation

  • docs/core-concepts.md - Types, operators, uniforms, control flow
  • docs/materials.md - Node materials and all properties
  • docs/compute-shaders.md - GPU compute with instanced arrays
  • docs/post-processing.md - Built-in and custom effects
  • docs/wgsl-integration.md - Custom WGSL functions
  • docs/device-loss.md - Handling GPU device loss and recovery
  • docs/limits-and-features.md - WebGPU device limits and optional features

Examples

  • examples/basic-setup.js - Minimal WebGPU project
  • examples/custom-material.js - Custom shader material
  • examples/particle-system.js - GPU compute particles
  • examples/post-processing.js - Effect pipeline
  • examples/earth-shader.js - Complete Earth with atmosphere

Templates

  • templates/webgpu-project.js - Starter project template
  • templates/compute-shader.js - Compute shader template

Reference

  • REFERENCE.md - Quick reference cheatsheet

Key Concepts

Import Pattern

javascript
// Always use the WebGPU entry pointimport * as THREE from 'three/webgpu';import { /* TSL functions */ } from 'three/tsl';

Node Materials

Replace standard material properties with TSL nodes:

javascript
material.colorNode = texture(map);        // instead of material.mapmaterial.roughnessNode = float(0.5);      // instead of material.roughnessmaterial.positionNode = displaced;         // vertex displacement

Method Chaining

TSL uses method chaining for operations:

javascript
// Instead of: sin(time * 2.0 + offset) * 0.5 + 0.5time.mul(2.0).add(offset).sin().mul(0.5).add(0.5)

Custom Functions

Use Fn() for reusable shader logic:

javascript
const fresnel = Fn(([power = 2.0]) => {  const nDotV = normalWorld.dot(viewDir).saturate();  return float(1.0).sub(nDotV).pow(power);});

When to Use This Skill

  • Setting up Three.js with WebGPU renderer
  • Creating custom shader materials with TSL
  • Writing GPU compute shaders
  • Building post-processing pipelines
  • Migrating from GLSL to TSL
  • Implementing visual effects (particles, water, terrain, etc.)

Resources

來源與署名

來源:dgreenheck/webgpu-claude-skill位於skills/webgpu-threejs-tsl提交af2319b

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架