These are some helper methods to create uniforms for common types. Note that you can also pass in a default value to most uniform type when defining the uniform.
Uniform arrays requires in addition to the name of the uniform the type it should contain and an IntNode to represent the size of the array which needs to be known at compile time.
The example below illustrates how to refer to the directional shadow matrix uniform provided by ThreeJS. In this case, the number of elements is provided with a defined constant NUM_DIR_LIGHT_SHADOWS.
Structs exist in GLSL but are normally not necessary when using this library as regular JavaScript objects and classes can do their job. However, when passing an array of a struct type to the shader, the struct needs to be defined.
The example below illustrates how this can be done to create a struct for the DirectionalLight type.
import { StructType } from"@hology/core/shader-nodes"abstractclassDirectionalLightextendsStructType {staticreadonly typeName ='DirectionalLight';readonly direction =this.get(Vec3Node,'direction');readonly color =this.get(RgbNode,'color');}
A struct should be defined as an abstract class.
It must have its name defined using a static property named typeName. This does not need to match the class name.
All properties must be defined with a call to this.get(type, name)
The class is abstract as you should not try to instantiate it on your own. Internally, a subclass will be defined during the build process of the shader and passed to array methods.
With this struct defined, it can now be used to create a uniform struct array.
The time uniforms can be useful to animate colors or vertex transforms.
import { timeUniforms } from"@hology/core/shader-nodes"timeUniforms.elapsed // FloatNode - Time in seconds.
Particles
import { particleUniforms } from"@hology/core/shader-nodes"particleUniforms.energy // FloatNode - A value going from 1 to 0 over the lifetime of the particleparticleUniforms.velocity // Vec3Node - The velocity of the particle
Depth
The depth uniforms can be used to get the depth behind a fragment on a triangle to the geometry behind it. This can be useful create create effects like water where the edges are more translucent.