Three Best Practices
Three.js performance optimization and best practices guidelines. Use when writing, reviewing, or optimizing Three.js code. Triggers on tasks involving 3D scenes, WebGL/WebGPU rendering, geometries, materials, textures, lighting, shaders, or TSL.
Specification
- Skill ID
- emalorenzo/three-agent-skills/three-best-practices
- Publisher
- emalorenzo
- Repository
- three-agent-skills
- Installs
- 0
- Files
- 29
- License
- MIT
- Synced
- Sep 23, 2026
How to use it
Open any RiverX project, open the Skills panel in the chat, and search for this identifier. The files are fetched from the source repository at install time.
emalorenzo/three-agent-skills/three-best-practicesInstalls these files- SKILL.md
- rules/_sections.md
- rules/animation-system.md
- rules/asset-compression.md
- rules/audio-spatial.md
- rules/core-web-vitals.md
- rules/debug-devtools.md
- rules/draw-call-optimization.md
- rules/error-handling-recovery.md
- rules/geometry-instanced-mesh.md
- rules/gltf-loading-optimization.md
- rules/lighting-shadows-advanced.md
- rules/memory-dispose-geometry.md
- rules/migration-checklist.md
- rules/mobile-optimization.md
- rules/object-pooling.md
- rules/physics-integration.md
- rules/postprocessing-optimization.md
- rules/raycasting-optimization.md
- rules/render-delta-time.md
- rules/setup-use-import-maps.md
- rules/shader-mobile.md
- rules/tsl-complete-reference.md
- rules/tsl-compute-shaders.md
- rules/tsl-material-slots.md
- rules/tsl-post-processing.md
- rules/tsl-why-use.md
- rules/webgpu-renderer.md
- rules/webxr-setup.md
What this skill tells the agent
Three.js Best Practices
Comprehensive performance optimization guide for Three.js applications. Contains 120+ rules across 18 categories, prioritized by impact.
Sources & Credits
This skill compiles best practices from multiple authoritative sources: - Official guidelines from Three.js llms branch maintained by mrdoob - 100 Three.js Tips by Utsubo - Excellent comprehensive guide covering WebGPU, asset optimization, and performance tipsWhen to Apply
Reference these guidelines when:
- Setting up a new Three.js project
- Writing or reviewing Three.js code
- Optimizing performance or fixing memory leaks
- Working with custom shaders (GLSL or TSL)
- Implementing WebGPU features
- Building VR/AR experiences with WebXR
- Integrating physics engines
- Optimizing for mobile devices
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 0 | Modern Setup & Imports | FUNDAMENTAL | setup- |
| 1 | Memory Management & Dispose | CRITICAL | memory- |
| 2 | Render Loop Optimization | CRITICAL | render- |
| 3 | Draw Call Optimization | CRITICAL | drawcall- |
| 4 | Geometry & Buffer Management | HIGH | geometry- |
| 5 | Material & Texture Optimization | HIGH | material- |
| 6 | Asset Compression | HIGH | asset- |
| 7 | Lighting & Shadows | MEDIUM-HIGH | lighting- |
| 8 | Scene Graph Organization | MEDIUM | scene- |
| 9 | Shader Best Practices (GLSL) | MEDIUM | shader- |
| 10 | TSL (Three.js Shading Language) | MEDIUM | tsl- |
| 11 | WebGPU Renderer | MEDIUM | webgpu- |
| 12 | Loading & Assets | MEDIUM | loading- |
| 13 | Core Web Vitals | MEDIUM-HIGH | vitals- |
| 14 | Camera & Controls | LOW-MEDIUM | camera- |
| 15 | Animation System | MEDIUM | animation- |
| 16 | Physics Integration | MEDIUM | physics- |
| 17 | WebXR / VR / AR | MEDIUM | webxr- |
| 18 | Audio | LOW-MEDIUM | audio- |
| 19 | Post-Processing | MEDIUM | postpro- |
| 20 | Mobile Optimization | HIGH | mobile- |
| 21 | Production | HIGH | error-, migration- |
| 22 | Debug & DevTools | LOW | debug- |
Quick Reference
0. Modern Setup (FUNDAMENTAL)
setup-use-import-maps- Use Import Maps, not old CDN scriptssetup-choose-renderer- WebGLRenderer (default) vs WebGPURenderer (TSL/compute)setup-animation-loop- Userenderer.setAnimationLoop()not manual RAFsetup-basic-scene-template- Complete modern scene template
1. Memory Management (CRITICAL)
memory-dispose-geometry- Always dispose geometriesmemory-dispose-material- Always dispose materials and texturesmemory-dispose-textures- Dispose dynamically created texturesmemory-dispose-render-targets- Always dispose WebGLRenderTargetmemory-dispose-recursive- Use recursive disposal for hierarchiesmemory-dispose-on-unmount- Dispose in React cleanup/unmountmemory-renderer-dispose- Dispose renderer when destroying viewmemory-reuse-objects- Reuse geometries and materials
2. Render Loop (CRITICAL)
render-single-raf- Single requestAnimationFrame looprender-conditional- Render on demand for static scenesrender-delta-time- Use delta time for animationsrender-avoid-allocations- Never allocate in render looprender-cache-computations- Cache expensive computationsrender-frustum-culling- Enable frustum cullingrender-update-matrix-manual- Disable auto matrix updates for static objectsrender-pixel-ratio- Limit pixel ratio to 2render-antialias-wisely- Use antialiasing judiciously
3. Draw Call Optimization (CRITICAL)
draw-call-optimization- Target under 100 draw calls per framegeometry-instanced-mesh- Use InstancedMesh for identical objectsgeometry-batched-mesh- Use BatchedMesh for varied geometries (same material)geometry-merge-static- Merge static geometries with BufferGeometryUtils
4. Geometry (HIGH)
geometry-buffer-geometry- Always use BufferGeometrygeometry-merge-static- Merge static geometriesgeometry-instanced-mesh- Use InstancedMesh for identical objectsgeometry-lod- Use Level of Detail for complex modelsgeometry-index-buffer- Use indexed geometrygeometry-vertex-count- Minimize vertex countgeometry-attributes-typed- Use appropriate typed arraysgeometry-interleaved- Consider interleaved buffers
5. Materials & Textures (HIGH)
material-reuse- Reuse materials across meshesmaterial-simplest-sufficient- Use simplest material that worksmaterial-texture-size-power-of-two- Power-of-two texture dimensionsmaterial-texture-compression- Use compressed textures (KTX2/Basis)material-texture-mipmaps- Enable mipmaps appropriatelymaterial-texture-anisotropy- Use anisotropic filtering for floorsmaterial-texture-atlas- Use texture atlasesmaterial-avoid-transparency- Minimize transparent materialsmaterial-onbeforecompile- Use onBeforeCompile for shader mods (or TSL)
6. Asset Compression (HIGH)
asset-compression- Draco, Meshopt, KTX2 compression guideasset-draco- 90-95% geometry size reductionasset-ktx2- GPU-compressed textures (UASTC vs ETC1S)asset-meshopt- Alternative to Draco with faster decompressionasset-lod- Level of Detail for 30-40% frame rate improvement
7. Lighting & Shadows (MEDIUM-HIGH)
lighting-limit-lights- Limit to 3 or fewer active lightslighting-shadows-advanced- PointLight cost, CSM, fake shadowslighting-bake-static- Bake lighting for static sceneslighting-shadow-camera-tight- Fit shadow camera tightlylighting-shadow-map-size- Choose appropriate shadow resolution (512-4096)lighting-shadow-selective- Enable shadows selectivelylighting-shadow-cascade- Use CSM for large sceneslighting-shadow-auto-update- Disable autoUpdate for static sceneslighting-probe- Use Light Probeslighting-environment- Environment maps for ambient lightlighting-fake-shadows- Gradient planes for budget contact shadows
8. Scene Graph (MEDIUM)
scene-group-objects- Use Groups for organizationscene-layers- Use Layers for selective renderingscene-visible-toggle- Use visible flag, not add/removescene-flatten-static- Flatten static hierarchiesscene-name-objects- Name objects for debuggingobject-pooling- Reuse objects instead of create/destroy
9. Shaders GLSL (MEDIUM)
shader-precision- Use mediump for mobile (~2x faster)shader-mobile- Mobile-specific optimizations (varyings, branching)shader-avoid-branching- Replace conditionals with mix/stepshader-precompute-cpu- Precompute on CPUshader-avoid-discard- Avoid discard, use alphaTestshader-texture-lod- Use textureLod for known mip levelsshader-uniform-arrays- Prefer uniform arraysshader-varying-interpolation- Limit varyings to 3 for mobileshader-pack-data- Pack data into RGBA channelsshader-chunk-injection- Use Three.js shader chunks
10. TSL - Three.js Shading Language (MEDIUM)
tsl-why-use- Use TSL instead of onBeforeCompiletsl-setup-webgpu- WebGPU setup for TSLtsl-complete-reference- Full TSL type system and functionstsl-material-slots- Material node properties referencetsl-node-materials- Use NodeMaterial classestsl-basic-operations- Types, operations, swizzlingtsl-functions- Creating TSL functions with Fn()tsl-conditionals- If, select, loops in TSLtsl-textures- Textures and triplanar mappingtsl-noise- Built-in noise functions (mx_noise_float, mx_fractal_noise)tsl-post-processing- bloom, blur, dof, aotsl-compute-shaders- GPGPU and compute operationstsl-glsl-to-tsl- GLSL to TSL translation
11. WebGPU Renderer (MEDIUM)
More from emalorenzo
Use this skill in a project
Open any RiverX project, search the Skills panel for emalorenzo/three-agent-skills/three-best-practices, and install it in one click.
