Uniforms are global GLSL variables. They are passed to shader programs.


When declaring a uniform of a ShaderMaterial, it is declared by value or by object.

uniforms: { time: { value: 1.0 }, resolution: new v3d.Uniform(new v3d.Vector2()) }

Uniform types

Each uniform must have a value property. The type of the value must correspond to the type of the uniform variable in the GLSL code as specified for the primitive GLSL types in the table below. Uniform structures and arrays are also supported. GLSL arrays of primitive type must either be specified as an array of the corresponding v3d objects or as a flat array containing the data of all the objects. In other words; GLSL primitives in arrays must not be represented by arrays. This rule does not apply transitively. An array of vec2 arrays, each with a length of five vectors, must be an array of arrays, of either five Vector2 objects or ten numbers.

Uniform types
GLSL type JavaScript type
int Number
uint (WebGL 2) Number
float Number
bool Boolean
bool Number
vec2 v3d.Vector2
vec2 Float32Array (*)
vec2 Array (*)
vec3 v3d.Vector3
vec3 v3d.Color
vec3 Float32Array (*)
vec3 Array (*)
vec4 v3d.Vector4
vec4 v3d.Quaternion
vec4 Float32Array (*)
vec4 Array (*)
mat2 Float32Array (*)
mat2 Array (*)
mat3 v3d.Matrix3
mat3 Float32Array (*)
mat3 Array (*)
mat4 v3d.Matrix4
mat4 Float32Array (*)
mat4 Array (*)
ivec2, bvec2 Float32Array (*)
ivec2, bvec2 Array (*)
ivec3, bvec3 Int32Array (*)
ivec3, bvec3 Array (*)
ivec4, bvec4 Int32Array (*)
ivec4, bvec4 Array (*)
sampler2D v3d.Texture
samplerCube v3d.CubeTexture

(*) Same for an (innermost) array (dimension) of the same GLSL type, containing the components of all vectors or matrices in the array.


Uniform(value : Object)

value -- An object containing the value to set up the uniform. It's type must be one of the Uniform Types described above.


.value : Object

Current value of the uniform.


.clone () : Uniform

Returns a clone of this uniform.
If the uniform's value property is an Object with a clone() method, this is used, otherwise the value is copied by assignment. Array values are shared between cloned Uniforms.

See WebGL deferred animation for an example of this method in use.


For more info on how to obtain the source code of this module see this page.