webgl-shader-constraints
WebGL Shader Constraints and Workarounds for Unity
TRIGGER
Use this skill when the user is developing Unity shaders for WebGL browser deployment. Triggers include: "WebGL", "browser game", "web build", "WebGL 1.0", "WebGL 2.0", "WebGPU", "GLSL", "OpenGL ES 2.0/3.0", "shader compilation web", "web build size", "shader variants web", "Always Included Shaders", or any mention of deploying Unity content to browsers. Also trigger when the user reports shader errors only on web builds, or when dealing with build size issues related to shaders.
CORE RULES
-
WebGL 1.0 (OpenGL ES 2.0) forbids dynamic array indexing. You can only index arrays with constants or loop counter variables. This is the #1 cause of shader failures on WebGL 1.0.
-
WebGL 1.0 only allows counting
forloops. Nowhileloops, nodo-whileloops. The loop counter must be initialized, compared, and incremented in theforstatement. The loop bound must be a constant expression. -
WebGL 2.0 (OpenGL ES 3.0) removes loop and indexing restrictions but adds mandatory precision qualifiers. All variables must have explicit precision (
highp,mediump,lowp) or use the default precision statement. -
WebGL only supports baked GI and non-directional lightmaps. No real-time GI, no directional lightmaps, no light probes with L2 spherical harmonics.
-
Never use the Standard Shader for WebGL builds. It compiles hundreds of variants and can add 50MB+ to build size. Use Simple Lit, Unlit, or custom shaders with minimal keywords.