Uniforms are global [link:https://www.opengl.org/documentation/glsl/ GLSL] variables. They are passed to shader programs.
When declaring a uniform of a [page:ShaderMaterial], it is declared by value or by object.
uniforms: {
time: { value: 1.0 },
resolution: new v3d.Uniform(new v3d.Vector2())
}
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 [page:Vector2] objects or ten *number*s.
GLSL type | JavaScript type |
---|---|
int | [page:Number] |
float | [page:Number] |
bool | [page:Boolean] |
bool | [page:Number] |
vec2 | [page:Vector2 v3d.Vector2] |
vec2 | [page:Float32Array Float32Array] (*) |
vec2 | [page:Array Array] (*) |
vec3 | [page:Vector3 v3d.Vector3] |
vec3 | [page:Color v3d.Color] |
vec3 | [page:Float32Array Float32Array] (*) |
vec3 | [page:Array Array] (*) |
vec4 | [page:Vector4 v3d.Vector4] |
vec4 | [page:Quaternion v3d.Quaternion] |
vec4 | [page:Float32Array Float32Array] (*) |
vec4 | [page:Array Array] (*) |
mat2 | [page:Float32Array Float32Array] (*) |
mat2 | [page:Array Array] (*) |
mat3 | [page:Matrix3 v3d.Matrix3] |
mat3 | [page:Float32Array Float32Array] (*) |
mat3 | [page:Array Array] (*) |
mat4 | [page:Matrix3 v3d.Matrix4] |
mat4 | [page:Float32Array Float32Array] (*) |
mat4 | [page:Array Array] (*) |
ivec2, bvec2 | [page:Float32Array Float32Array] (*) |
ivec2, bvec2 | [page:Array Array] (*) |
ivec3, bvec3 | [page:Int32Array Int32Array] (*) |
ivec3, bvec3 | [page:Array Array] (*) |
ivec4, bvec4 | [page:Int32Array Int32Array] (*) |
ivec4, bvec4 | [page:Array Array] (*) |
sampler2D | [page:Texture v3d.Texture] |
samplerCube | [page:CubeTexture v3d.CubeTexture] |
(*) Same for an (innermost) array (dimension) of the same GLSL type, containing the components of all vectors or matrices in the array.
value -- An object containing the value to set up the uniform. It's type must be one of the Uniform Types described above.
Current value of the uniform.
Returns a clone of this uniform.
If the uniform's value property is an [page:Object] with a clone() method, this is used, otherwise the value is copied by assignment.
Array values are shared between cloned [page:Uniform]s.
See [example:webgldeferred_animation WebGL deferred animation] for an example of this method in use.