webgpu-threejs-tsl
ساخت جلوههای GPU، شیدر و پارتیکل با Three.js، WebGPU و TSL
این مهارت توسعه پروژههای Three.js با WebGPURenderer و زبان شیدر TSL را راهنمایی میکند؛ از راهاندازی رندرر و node material تا نوشتن compute shader و اتصال کد WGSL.
برای ساخت پارتیکلهای GPU، متریالهای سفارشی، post-processing، جابهجایی هندسه و جلوههایی مانند آب یا زمین کاربرد دارد و نمونهها و الگوهای آماده، شروع پروژه را سریعتر میکنند.
چه چیزی میگیرید
- راهاندازی استاندارد Three.js با `WebGPURenderer` و `three/tsl`
- ساخت node material و منطق شیدر با chaining و `Fn()`
- پیادهسازی compute shader و سیستمهای پارتیکل مبتنی بر GPU
- طراحی pipelineهای post-processing و اتصال توابع سفارشی `WGSL`
- راهنمای مدیریت device loss، محدودیتهای WebGPU و قابلیتهای اختیاری
برای چه کاری خوب است
- توسعهدهندگانی که جلوههای تعاملی و سنگین سهبعدی برای وب میسازند
- پروژههایی که به پارتیکل، شیدر سفارشی، post-processing یا محاسبات GPU نیاز دارند
- تیمهایی که میخواهند از GLSL به TSL و WebGPU مهاجرت کنند
- ساخت نمونههای بصری مانند آب، زمین، جو و متریالهای پویا در Three.js
برای چه کاری نیست
- پروژههایی که فقط به رندر ساده WebGL یا متریالهای آماده Three.js نیاز دارند
- محیطهایی که مرورگر هدفشان WebGPU را پشتیبانی نمیکند و fallback ندارند
- کارهایی که به شیدرهای مستقل GLSL خارج از اکوسیستم Three.js نیاز دارند
دربارهٔ این اسکیل
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
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 flowdocs/materials.md- Node materials and all propertiesdocs/compute-shaders.md- GPU compute with instanced arraysdocs/post-processing.md- Built-in and custom effectsdocs/wgsl-integration.md- Custom WGSL functionsdocs/device-loss.md- Handling GPU device loss and recoverydocs/limits-and-features.md- WebGPU device limits and optional features
Examples
examples/basic-setup.js- Minimal WebGPU projectexamples/custom-material.js- Custom shader materialexamples/particle-system.js- GPU compute particlesexamples/post-processing.js- Effect pipelineexamples/earth-shader.js- Complete Earth with atmosphere
Templates
templates/webgpu-project.js- Starter project templatetemplates/compute-shader.js- Compute shader template
Reference
REFERENCE.md- Quick reference cheatsheet
Key Concepts
Import Pattern
// Always use the WebGPU entry point
import * as THREE from 'three/webgpu';
import { /* TSL functions */ } from 'three/tsl';
Node Materials
Replace standard material properties with TSL nodes:
material.colorNode = texture(map); // instead of material.map
material.roughnessNode = float(0.5); // instead of material.roughness
material.positionNode = displaced; // vertex displacement
Method Chaining
TSL uses method chaining for operations:
// Instead of: sin(time * 2.0 + offset) * 0.5 + 0.5
time.mul(2.0).add(offset).sin().mul(0.5).add(0.5)
Custom Functions
Use Fn() for reusable shader logic:
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
- Three.js TSL Wiki
- WebGPU Examples (files prefixed with
webgpu_)