/qadri-motion:threejs-errors-renderingfrom qadri-motion
Use when a Three.js scene renders incorrectly: black screen, invisible objects, wrong colors, z-fighting, or broken shadows. Prevents the common mistake of wrong color space, missing material.side, or forgetting updateProjectionMatrix. Covers all common rendering errors with diagnosis steps and fix patterns. Keywords: black screen, invisible, wrong color, z-fighting, shadow artifact, rendering error, debug, nothing visible, dark, broken, nothing shows, model not appearing, screen is blank.
Ships in qadri-motion. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
When a Three.js scene does not render correctly, ALWAYS follow this sequence:
renderer.getSize(new THREE.Vector2()))display: none)renderer.render(scene, camera) is called (in a loop or at least once)side, visible, opacity, and transparent propertiesvisible, layers, and frustumCulled propertiesThe canvas has 0x0 dimensions. This happens when setSize() is called before the container is in the DOM or when the container has no CSS dimensions.
Fix:
// ALWAYS ensure the container is in the DOM and has dimensions before setSize
document.body.appendChild(renderer.domElement);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
The camera is at (0, 0, 0) and the object is also at (0, 0, 0), so the camera is inside the mesh. Or the camera is pointing in the wrong direction.
Fix:
camera.position.set(0, 2, 5); // ALWAYS move camera away from origin
camera.lookAt(0, 0, 0);
Objects closer than near or farther than far are clipped. Default PerspectiveCamera near is 0.1, far is 2000.
Fix:
const camera = new THREE.PerspectiveCamera(75, aspect, 0.1, 1000);
// NEVER set near to 0 -- causes z-fighting and depth buffer issues
// ALWAYS keep far/near ratio below 100000 for stable depth precision
MeshStandardMaterial, MeshPhongMaterial, and MeshLambertMaterial require lights. Without light, they render black. MeshBasicMaterial does NOT require lights.
Fix:
scene.add(new THREE.AmbientLight(0xffffff, 0.5));
scene.add(new THREE.DirectionalLight(0xffffff, 1));
The animation loop is not started, or renderer.render(scene, camera) is missing.
Fix:
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate(); // ALWAYS call the function to start the loop
Passing an empty scene or an uninitialized camera to render().
Diagnosis: Log scene.children.length and camera.type before the render call.
Back faces are culled by default (FrontSide). If the camera sees the back of a plane or thin geometry, it is invisible.
Fix:
const material = new THREE.MeshStandardMaterial({
side: THREE.DoubleSide // ALWAYS use for planes, leaves, thin objects
});
Setting opacity: 0.5 without transparent: true has NO effect.
Fix:
const material = new THREE.MeshStandardMaterial({
opacity: 0.5,
transparent: true // ALWAYS pair with opacity < 1
});
The camera and the object MUST share at least one layer. By default both are on layer 0. If the object is moved to another layer, the camera must enable that layer too.
Fix:
object.layers.set(1);
camera.layers.enable(1); // camera must see layer 1
visible = false on a parent makes ALL descendants invisible. Check the full parent chain.
Diagnosis:
let node = object;
while (node) {
if (!node.visible) console.log('Hidden ancestor:', node.name || node.type);
node = node.parent;
}
If the bounding sphere is wrong (e.g., after manual vertex changes without computeBoundingSphere()), the object may be culled even when visible.
Fix:
geometry.computeBoundingSphere(); // ALWAYS call after modifying positions
// Or disable frustum culling for objects that must always render:
mesh.frustumCulled = false;
Object is at a position far from the camera, or scale.set(0, 0, 0).
Diagnosis: Log object.position, object.scale, object.matrixWorld.
This is the MOST COMMON color error in Three.js r160+.
Rules:
texture.colorSpace = THREE.SRGBColorSpaceTHREE.LinearSRGBColorSpacerenderer.outputColorSpace = THREE.SRGBColorSpace (default in r160+)Symptoms of wrong color space:
SRGBColorSpace (double gamma)LinearSRGBColorSpace (no gamma applied)Fix:
const texture = await loader.loadAsync('diffuse.png');
texture.colorSpace = THREE.SRGBColorSpace; // for color textures
const normalMap = await loader.loadAsync('normal.png');
// NEVER set SRGBColorSpace on normal maps -- corrupts surface data
Without tone mapping, HDR values are clamped, producing flat or incorrect colors.
Fix:
renderer.toneMapping = THREE.ACESFilmicToneMapping; // or AgXToneMapping
renderer.toneMappingExposure = 1.0;
material.color.set() works, but material.color = new THREE.Color() after construction also works. The common mistake is setting color as a hex number directly: material.color = 0xff0000 does NOT work.
Fix:
material.color.set(0xff0000); // Correct
material.color = new THREE.Color(0xff0000); // Correct
// material.color = 0xff0000; // WRONG -- silently fails
Z-fighting occurs when two surfaces overlap at nearly the same depth, causing the depth buffer to alternate between them.
const material = new THREE.MeshStandardMaterial({
polygonOffset: true,
polygonOffsetFactor: -1,
polygonOffsetUnits: -1
});
const renderer = new THREE.WebGLRenderer({ logarithmicDepthBuffer: true });
// Trades performance for better depth precision across large near/far ranges
// NEVER use with EffectComposer post-processing -- causes artifacts
Move one surface slightly:
decalMesh.position.z += 0.01; // small offset to prevent overlap
// ALWAYS keep the near plane as large as possible
camera.near = 1; // not 0.001
camera.far = 1000; // not 1000000
camera.updateProjectionMatrix();
For complete shadow configuration, see the threejs-impl-shadows skill. Common quick fixes:
renderer.shadowMap.enabled = true, light.castShadow = true, mesh.castShadow = true, ground.receiveShadow = truelight.shadow.bias (e.g., -0.005)light.shadow.bias is too large, reduce itlight.shadow.mapSize.set(2048, 2048)The browser reclaims the WebGL context under memory pressure or GPU reset.
renderer.domElement.addEventListener('webglcontextlost', (event) => {
event.preventDefault(); // ALWAYS prevent default to allow restoration
cancelAnimationFrame(animationId);
}, false);
renderer.domElement.addEventListener('webglcontextrestored', () => {
// Re-initialize materials, textures, render targets
initScene();
animate();
}, false);
NEVER ignore context loss -- the canvas goes black permanently. ALWAYS add both event listeners.
After modifying vertex data, the GPU buffer is stale:
positions.array[0] = newX;
positions.needsUpdate = true; // ALWAYS set after modifying attribute data
After changing structural properties (adding/removing maps, changing defines):
material.map = newTexture;
material.needsUpdate = true; // triggers shader recompilation
// NEVER set needsUpdate = true every frame -- causes constant recompilation
After modifying texture image data:
texture.image = newImage;
texture.needsUpdate = true; // triggers GPU re-upload
After setMatrixAt() or setColorAt():
mesh.instanceMatrix.needsUpdate = true; // ALWAYS after setMatrixAt
mesh.instanceColor.needsUpdate = true; // ALWAYS after setColorAt
ALWAYS call camera.updateProjectionMatrix() after changing:
camera.fovcamera.aspectcamera.nearcamera.farcamera.zoomcamera.left/right/top/bottom (OrthographicCamera)window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix(); // NEVER forget this
renderer.setSize(window.innerWidth, window.innerHeight);
});
Transparent objects render in the wrong order (back-to-front sorting fails).
// Force specific rendering order
backgroundMesh.renderOrder = 0;
transparentMesh.renderOrder = 1;
frontMesh.renderOrder = 2;
const material = new THREE.MeshStandardMaterial({
transparent: true,
opacity: 0.5,
depthWrite: false // prevents transparent objects from writing to depth buffer
});
For textures with hard alpha edges (foliage, fences):
const material = new THREE.MeshStandardMaterial({
map: leafTexture,
alphaTest: 0.5, // discards fragments below threshold
side: THREE.DoubleSide
// NEVER set transparent: true for hard-edge alpha -- use alphaTest instead
});
| Warning | Cause | Fix |
|---|---|---|
THREE.WebGLRenderer: Texture is not power of two | NPOT texture with repeat wrapping | Use power-of-two textures or ClampToEdgeWrapping |
THREE.WebGLProgram: shader error | GLSL compilation failure | Check custom shader code for syntax errors |
THREE.PropertyBinding: Can not bind to... | Animation targets missing property | Ensure skeleton/morph targets match the animation clip |
THREE.BufferGeometry: .addAttribute() removed | Using deprecated API | Use setAttribute() instead |
GL_INVALID_OPERATION: Feedback loop | Reading from a texture that is also a render target | Use separate textures for reading and writing |
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub qadri-uk/claude-skills --plugin qadri-motion149 skills in this plugin
/60fps-animationThis skill should be used when the user asks to "fix janky CSS animation", "make animation 60fps", "stop layout thrashing", "animate width/height/top/left smoothly", "convert animation to transform", "animate box-shadow performantly", "animate height auto", "FLIP animation", or "why is my scroll/hover animation choppy"./accessible-animationThis skill should be used when the user asks to "respect prefers-reduced-motion", "honor reduced motion", "make my animations accessible", "fix vestibular / motion-sickness issues", "add a useReducedMotion hook", "gate GSAP / Framer Motion / Lenis for reduced motion", or "meet WCAG 2.3.3 / C39". Provides tiered (not all-or-nothing) reduced-motion patterns in CSS and JS./