Phenomenon is a very small, low-level WebGL library that provides the essentials to deliver a high performance experience. Its core functionality is built around the idea of moving millions of particles around using the power of the GPU.
- Small in size, no dependencies
- GPU based for high performance
- Low-level & highly configurable
- Helper functions with options
- Add & destroy instances dynamically
Want to see some magic right away? Have a look here!
$ npm install --save phenomenon
// Import the library import Phenomenon from 'phenomenon'; // Create a renderer const phenomenon = new Phenomenon(options); // Add an instance phenomenon.add("particles", options);
For a better understanding of how to use the library, read along or have a look at the demo!
Returns an instance of Phenomenon.
Throughout this documentation we'll refer to an instance of this as
The element where the scene, with all of its instances, will be rendered to. The provided element has to be
<canvas> otherwise it won't work.
Overrides that are used when getting the WebGL context from the canvas. The library overrides two settings by default.
||Setting this property to
||Setting this property to
Read more about all the possible overrides on MDN.
@TODO Overrides that can be used to alter the behaviour of the experience.
||The resolution multiplier by which the scene is rendered relative to the canvas' resolution. Use
||The color in
||The distance in 3D space between the center of the scene and the camera.|
||A boolean indicating whether the scene should start rendering automatically.|
||Shared values between all instances that can be updated at any given moment. By default this feature is used to render all the instances with the same
||A render hook that is invoked every frame before / after the scene is rendered to the screen. Use this to update
Update all values that are based on the dimensions of the canvas to make it look good on all screen sizes.
Toggle the rendering state of the scene. When shouldRender is false
requestAnimationFrame is disabled so no resources are used.
An optional boolean to set the rendering state to a specific value. Leaving this value empty will result in a regular boolean switch.
This function is used to add instances to the renderer. These instances can be as simple or complex as you'd like them to be. There's no limit to how many of these you can add. Make sure they all have a different key!
Every instance should have a unique name. This name can also be used to destroy the instance specifically later.
An object containing overrides for parameters that are used when getting the WebGL context from the canvas.
||-||Values used in the program that are stored once, directly on the GPU.|
||Values used in the program that can be updated on the fly.|
||-||The vertex shader is used to position the geometry in 3D space.|
||-||The fragment shader is used to provide the geometry with color or texture.|
||-||The amount of duplicates that will be created for the same instance.|
||Vertices (and optional normals) of a model.|
||Modifiers to alter the attributes data on initialize.|
||A render hook that is invoked every frame before the instance is rendered.|
||A render hook that is invoked every frame after the instance is rendered.|
Note: Less instances with a higher multiplier will be faster than more instances with a lower multiplier!
Remove an instance from the scene (and from memory) by its key.
Remove all instances and the renderer itself. The canvas element will remain in the DOM.
Are you excited about this library and have interesting ideas on how to improve it? Please tell me or contribute directly!
npm install > npm run demo > http://localhost:8080
MIT © Colin van Eenige