Use this file to discover all available pages before exploring further.
Shaders are programs that run on the GPU to position and color your particles. Phenomenon uses WebGL shaders written in GLSL (OpenGL Shading Language).
The vertex shader receives attributes (per-particle data) and uniforms (shared values), then outputs the final position.
attribute vec3 aPositionStart;attribute vec3 aPositionEnd;attribute vec3 aPosition;attribute vec3 aColor;attribute float aOffset;uniform float uProgress;uniform mat4 uProjectionMatrix;uniform mat4 uModelMatrix;uniform mat4 uViewMatrix;varying vec3 vColor;void main(){ // Calculate position based on progress vec3 newPosition = mix(aPositionStart, aPositionEnd, uProgress); // Transform to screen space gl_Position = uProjectionMatrix * uModelMatrix * uViewMatrix * vec4(newPosition + aPosition, 1.0); // Set particle size gl_PointSize = 1.0; // Pass color to fragment shader vColor = aColor;}
The matrices uProjectionMatrix, uModelMatrix, and uViewMatrix are automatically provided by Phenomenon. Always include them in your vertex shader for proper 3D transformation.
Move static calculations outside the shader or into uniforms:
// BAD: Recalculated for every particlefloat value = 3.14159 * 2.0 / 360.0;// GOOD: Pass as uniformuniform float uConstantValue;
2
Use built-in functions
GLSL provides optimized built-in functions:
// Use mix() instead of manual interpolationvec3 pos = mix(start, end, progress);// Use normalize() for unit vectorsvec3 normal = normalize(direction);// Use smoothstep() for smooth interpolationfloat t = smoothstep(0.0, 1.0, progress);
3
Avoid conditionals
Branches can slow down GPU execution. When possible, use mathematical alternatives:
// SLOWER: Using if statementif (uProgress > 0.5) { color = color * 2.0;}// FASTER: Using step functioncolor = color * (1.0 + step(0.5, uProgress));