The Renderer (also called Phenomenon) is the core class that manages your WebGL context, canvas setup, and rendering loop. It handles the heavy lifting of WebGL initialization, viewport management, and orchestrating all instances.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/vaneenige/phenomenon/llms.txt
Use this file to discover all available pages before exploring further.
Creating a renderer
You create a renderer by instantiating thePhenomenon class. The constructor accepts an optional configuration object:
If you don’t provide a canvas element, the renderer will automatically select the first
<canvas> element in your document.Configuration options
Canvas and context
- canvas: The HTMLCanvasElement to render to (defaults to
document.querySelector('canvas')) - context: Additional WebGL context attributes passed to
getContext() - contextType: The context type string (defaults to
'experimental-webgl')
Settings
Thesettings object controls rendering behavior:
- devicePixelRatio: Multiplier for canvas resolution (default:
1) - clearColor: Background color as RGBA array (default:
[1, 1, 1, 1]) - position: Camera position with
{x, y, z}coordinates (default:{x: 0, y: 0, z: 2}) - clip: Near and far clipping planes as array (default:
[0.001, 100]) - onRender: Callback function executed on each frame
- onSetup: Callback function executed once before first render
Debug mode
Whendebug: true, the renderer logs shader compilation errors to the console:
Managing instances
The renderer stores instances in aMap and provides methods to manage them.
Adding instances
Useadd() to create and register an instance:
Removing instances
Remove an instance and clean up its resources:destroy() on the instance, which deletes all buffers and the shader program.
The render loop
The renderer starts automatically and usesrequestAnimationFrame for smooth rendering:
Pausing and resuming
Control the render loop withtoggle():
Per-frame callbacks
Use theonRender callback to update uniforms or perform calculations each frame:
Automatic viewport management
The renderer handles canvas sizing and viewport updates automatically. On window resize or initialization, it:- Updates canvas dimensions based on
devicePixelRatio - Adjusts the WebGL viewport to match buffer size
- Recalculates projection, view, and model matrices
- Updates shared uniforms for all instances
Shared uniforms
The renderer provides three matrix uniforms available to all instances:- uProjectionMatrix: Perspective projection matrix (mat4)
- uViewMatrix: View transformation matrix (mat4)
- uModelMatrix: Model transformation matrix (mat4)
resize() and passed to each instance during rendering.
You must declare these uniforms in your vertex shader to use them:
Cleanup
Destroy the renderer and all its instances:Accessing the WebGL context
The renderer exposes the WebGL context asrenderer.gl:
The renderer enables
DEPTH_TEST by default with LEQUAL depth function.