TheDocumentation 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.
Instance class represents a single particle system with its own shaders, geometry, and attributes. You don’t instantiate this class directly—it’s created by calling renderer.add().
Instance Settings
When you callrenderer.add(), you pass an InstanceProps object that configures the particle instance.
vertex
GLSL vertex shader source code. This shader determines the position and appearance of each particle.
Example
fragment
GLSL fragment shader source code. This shader determines the color of each particle.
Example
uniforms
Custom uniforms to pass to the shaders. The renderer automatically provides
uProjectionMatrix, uModelMatrix, and uViewMatrix.Example
attributes
Custom vertex attributes. Each attribute defines data that varies per particle.
The attribute name used in the vertex shader (e.g.,
aOffset, aVelocity).Number of components per vertex (1 for float, 2 for vec2, 3 for vec3, 4 for vec4).
Function that returns the attribute data for each particle. Called once per particle during initialization.
Example
geometry
The base geometry for each particle. By default, each particle is a single point at the origin.
Array of vertex positions. Each particle instance uses this geometry.
Array of vertex normals. If provided, an
aNormal attribute is automatically created.Example
multiplier
Number of times to repeat the geometry. This is how you create multiple particles—each particle gets its own copy of the geometry.
Example
mode
WebGL drawing mode. Use
0 for POINTS, 4 for TRIANGLES, 5 for TRIANGLE_STRIP, etc.Example
onRender
Optional callback invoked after each frame is rendered. Use this to update uniforms or perform per-frame calculations for this specific instance.
Example
modifiers
modifiers
{ [attributeName: string]: (data: any, vertexIndex: number, component: number, instance: Instance) => number }
Functions that modify attribute values during buffer creation. Each modifier receives the attribute’s data and returns a modified value.
Example
Methods
These methods are available on Instance objects, but you typically don’t call them directly.prepareAttribute()
Prepares a single attribute by generating its buffer data.The attribute to prepare with
name, size, and optional data function.- Creates a
Float32Arraybuffer sized for all particles - Calls the attribute’s
datafunction for each particle - Applies any modifiers for the attribute
- Stores the buffer data on the attribute
- Calls
prepareBuffer()to upload to GPU
prepareBuffer()
Creates a WebGL buffer and uploads attribute data to the GPU.The attribute with prepared data to upload.
render()
Renders the instance for a single frame.Shared uniforms from the renderer (projection, view, and model matrices).
- Activates the instance’s shader program
- Binds all vertex attribute buffers
- Updates all uniforms (shared and instance-specific)
- Calls
gl.drawArrays()to render - Invokes the
onRendercallback if defined
destroy()
Cleans up WebGL resources for this instance.- Deletes all vertex buffers
- Deletes the shader program
- Nullifies the WebGL context reference
Properties
Instance objects expose these public properties:The WebGL rendering context.
The compiled and linked shader program.
All uniforms for this instance, including shared renderer uniforms.
All vertex attributes with their buffer data.
WebGL buffer objects for each attribute.
The base geometry configuration.
Number of particles (geometry instances).
WebGL drawing mode.
Optional callback invoked after each render. Use this to update uniforms or perform per-frame calculations.