Skip to content

Packs / threejs-public

custom-shader-material

Write a custom GLSL ShaderMaterial (time-animated vertex displacement + fragment gradient) that compiles cleanly and reports shader errors loudly

Install

logicpacks pack use threejs-public/custom-shader-material
get_pack threejs-public/custom-shader-material

The second line is the MCP tool call for the LogicPacks connector (Claude Code, Codex, Claude.ai and others). The first run of a pack someone else wrote asks for your yes.

Keys it needs (names only)

None.

Playbooks included

  • Spec: spec/SPEC.md (goal, steps, edge cases, don’ts)
  • Routes: static-local
  • Checks: 1 in outcome/checks.yaml
  • Code: boot.jsindex.htmlmain.jsshaders.js
  • Tools: python3, playwright-python, chromium

Usage, last 8 weeks

New: no recorded use yet.

Purpose (from spec/SPEC.md)

Goal

A working ShaderMaterial template with uniforms (time, resolution, colour), vertex displacement and a fragment effect, plus a compile-error hook so broken shaders fail loudly in checks.

Steps

  1. Copy code/; edit shaders.js (vertex + fragment strings).
  2. Uniforms update in the loop; keep per-frame JS work to uniform writes.
  3. Compile errors are caught by renderer.debug.onShaderError and reported as console errors (so checks fail).
  4. Check: python3 ../tools/webgl_check.py code --js "window.__shader.compiled".

Edge cases

  • Precision: use highp for positions; mobile GPUs may lack highp in fragment shaders (rare today).
  • Use onBeforeCompile to extend built-in materials instead when you need lighting.

Don'ts

  • Don't branch heavily per pixel; prefer mix/step.
  • Don't allocate new uniforms objects per frame.