nodeObjects
Automatically maps a JavaScript array of objects to a uniform array accessible in the shader, enabling a single material to perceive and react to multiple other objects in the scene.
Core Advantages
By automating data aggregation, it empowers a material with the ability to sense multiple objects in the scene, drastically simplifying the creation of complex environmental interaction effects like water ripples or multi-light illumination.
Common Uses
Implementing custom multi-light rendering
Creating group-aware visual effects (e.g., gravity fields)
Simulating environmental interaction effects (e.g., water ripples, grass trampling)
How to adjust
By modifying the source array in JavaScript (e.g., by `push`ing a new object or `pop`ping an old one), the number of accessible objects in the shader can be changed in real-time, dynamically adding or removing visual effects, such as making a new light source appear in the scene.
Code Examples
1// Track a JS array of objects
2const lightObjects = nodeObjects( lights );
3
4// Get an array of all object positions (vec3[]) in the shader
5const lightPositions = lightObjects.position;