struct
The struct node allows you to define custom, composite data types, enabling you to group multiple related nodes (e.g., a light's position, color, and intensity) into a single, organized unit. This is essential for managing complex data in shaders.
Core Advantages
Its core advantage is data encapsulation and organization. It makes the node graph cleaner, more readable, and easier to maintain by grouping related variables, which in turn promotes modular and reusable shader code.
Common Uses
Defining a data packet for material properties like PBR (e.g., color, normal, roughness).
Encapsulating all parameters of a light source (e.g., position, color, intensity, range) for easy passing.
In GPGPU, defining the data structure of a single element (like a particle) in a compute buffer.
How to adjust
Tuning a struct instance is done by changing the input nodes used to initialize its members. The struct itself is just a container; its effect depends entirely on the data it holds. For example, swapping a static color node for a texture node as a baseColor member will change the object's surface from a solid color to textured.
Code Examples
1// 1. Define a new type containing color and roughness
2const MaterialInfo = struct({
3 baseColor: vec3(),
4 roughness: float()
5});
6
7// 2. Create an instance and access its members
8const myData = MaterialInfo({ baseColor: vec3(1, 0, 0), roughness: float(0.5) });
9const color = myData.baseColor; // <-- results in a vec3 node