threejs-performance-and-packing

Optimizes Three.js shader register packing, precision qualifiers, and mobile WebGL compilation performance.

Updated Jul 13, 2026
One-click install
npx skills add https://github.com/Ohmnia/site-build --skill threejs-performance-and-packing-ohmnia
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: threejs-performance-and-packing
Source: https://github.com/Ohmnia/site-build/tree/main/.opencode/skills/threejs-performance-and-packing
Command: npx skills add https://github.com/Ohmnia/site-build --skill threejs-performance-and-packing-ohmnia

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Mobile WebGL and Three.js shaders often fail to compile or run slowly because varying and uniform variables exceed hardware register limits, precision qualifiers are misconfigured, or fragment shaders lack explicit precision declarations. This Skill provides the rules to pack variables within register budgets and configure precision correctly. ## Core Features & Use Cases - Register Allocation Packing: Enforces a 16x4 virtual register grid with strict type-ordered packing (mat4, mat2, vec4, mat3, vec3, vec2, float) and no-backtracking constraints. - Precision Management: Defines highp, mediump, and lowp range and bit-resolution boundaries, plus mandatory fragment shader precision declarations like precision mediump float;. - Use Case: When a Three.js fragment shader fails to compile on a mobile GPU, apply the packing hierarchy to reorder varyings and uniforms, flatten structures, and set explicit precision qualifiers so the shader fits the target register grid. ## Quick Start Use the threejs-performance-and-packing skill to review my fragment shader and repack its uniforms and varyings to fit mobile WebGL register limits.

Frequently Asked Questions about threejs-performance-and-packing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix Three.js shader register limit errors on mobile?

Pack vertex outputs and fragment inputs into a 16-row by 4-column register grid, flattening structures and ordering variables by type from mat4 down to float. Non-square matrices reserve space equal to the larger dimension, so reduce matrix sizes where possible.

What is the correct variable packing order for WebGL shaders?

Allocate variables in strict type order: mat4 arrays and instances, then mat2, vec4, mat3, vec3, vec2, and finally float. The allocator does not backtrack, so non-contiguous column saturation causes immediate layout failure.

Why does my fragment shader fail to compile without a precision qualifier?

Fragment shaders have no default floating-point precision in GLSL ES, so compilation fails without an explicit declaration. Add a statement like `precision mediump float;` at the top of the shader to satisfy multi-pass compilation checks.

What is the difference between highp, mediump, and lowp in GLSL?

highp is 32-bit with range near IEEE-754 single precision, mediump is minimum 16-bit with 2^-10 relative precision, and lowp is minimum 9-bit with 2^-8 absolute precision intended for 8-bit color values. Choose the lowest precision that preserves visual correctness on mobile.

Can I use lowp precision for all mobile shader variables?

No, lowp only covers the range (-2, 2) with 2^-8 absolute precision and is designed strictly for 8-bit color map representations. Positions, normals, and lighting calculations typically require mediump or highp to avoid visible artifacts.