Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Uniforms types

Mr.doob edited this page · 12 revisions

These mappings are also available since r68:

switch ( type ) {

    case '1i':
        _gl.uniform1i( location, value );
        break;

    case '1f':
        _gl.uniform1f( location, value );
        break;

    case '2f':
        _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
        break;

    case '3f':
        _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
        break;

    case '4f':
        _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
        break;

    case '1iv':
        _gl.uniform1iv( location, value );
        break;

    case '3iv':
        _gl.uniform3iv( location, value );
        break;

    case '1fv':
        _gl.uniform1fv( location, value );
        break;

    case '2fv':
        _gl.uniform2fv( location, value );
        break;

    case '3fv':
        _gl.uniform3fv( location, value );
        break;

    case '4fv':
        _gl.uniform4fv( location, value );
        break;

    case 'Matrix3fv':
        _gl.uniformMatrix3fv( location, false, value );
        break;

    case 'Matrix4fv':
        _gl.uniformMatrix4fv( location, false, value );
        break;

}

These still work:

var uniformsExample = {

"uInt" :  { type: "i", value: 1 },     // single integer
"uFloat" : { type: "f", value: 3.14 }, // single float

"uVec2" : { type: "v2", value: new THREE.Vector2( 0, 1 ) },       // single Vector2
"uVec3" : { type: "v3", value: new THREE.Vector3( 0, 1, 2 ) },    // single Vector3
"uVec4" : { type: "v4", value: new THREE.Vector4( 0, 1, 2, 3 ) }, // single Vector4

"uCol" : { type: "c", value: new THREE.Color( 0xffaa00 ) }, // single Color

"uMat4" : { type: "m4", value: new THREE.Matrix4() }, // single Matrix4

/*
// till r50
"uTex" :     { type: "t", value: 0, texture: THREE.ImageUtils.loadTexture( "texture.jpg" ) }, // regular texture
"uTexCube" : { type: "t", value: 1, texture: THREE.ImageUtils.loadTextureCube( [ "px.jpg", "nx.jpg", // cube texture
                                                                                 "py.jpg", "ny.jpg", 
                                                                                 "pz.jpg", "nz.jpg" ] ) },
*/

// since r51
"uTex" :     { type: "t", value: THREE.ImageUtils.loadTexture( "texture.jpg" ) }, // regular texture
"uTexCube" : { type: "t", value: THREE.ImageUtils.loadTextureCube( [ "px.jpg", "nx.jpg", // cube texture
                                                                     "py.jpg", "ny.jpg", 
                                                                     "pz.jpg", "nz.jpg" ] ) },

"uIntArray"  : { type: "iv1", value: [ 1, 2, 3, 4, 5 ] },    // integer array (plain)
"uIntArray3" : { type: "iv", value: [ 1, 2, 3, 4, 5, 6 ] },   // integer array (ivec3)

"uFloatArray"  : { type: "fv1", value: [ 0.1, 0.2, 0.3, 0.4, 0.5 ] },    // float array (plain)
"uFloatArray3" : { type: "fv",  value: [ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6 ] }, // float array (vec3)

"uVec2Array" : { type: "v2v", value: [ new THREE.Vector2( 0.1, 0.2 ), 
                                       new THREE.Vector2( 0.4, 0.5 ) ] }, // Vector2 array

"uVec3Array" : { type: "v3v", value: [ new THREE.Vector3( 0.1, 0.2, 0.3 ), 
                                       new THREE.Vector3( 0.4, 0.5, 0.6 ) ] }, // Vector3 array

"uVec4Array" : { type: "v4v", value: [ new THREE.Vector4( 0.1, 0.2, 0.3, 0.4 ), 
                                       new THREE.Vector4( 0.4, 0.5, 0.6, 0.7 ) ] }, // Vector4 array

"uMat4Array" : { type: "m4v", value: [ new THREE.Matrix4(), new THREE.Matrix4() ] }, // Matrix4 array

"uTexArray" : { type: "tv", value: [ new THREE.Texture(), new THREE.Texture() ] } // texture array (regular)
                                                                                              // texture units start from value

};

Shader (GLSL)

uniform int uInt;
uniform float uFloat;

uniform vec2 uVec2;
uniform vec3 uVec3;
uniform vec4 uVec4;

uniform vec3 uCol;

uniform mat4 uMat4;

uniform sampler2D uTex;
uniform samplerCube uTexCube;

uniform int uIntArray[ 5 ];
uniform ivec3 uIntArray3[ 2 ];

uniform float uFloatArray[ 5 ];
uniform vec3 uFloatArray3[ 2 ];

uniform vec2 uVec2Array[ 2 ];
uniform vec3 uVec3Array[ 2 ];
uniform vec4 uVec4Array[ 2 ];

uniform mat4 uMat4Array[ 2 ];

uniform sampler2D uTexArray[ 2 ];
Something went wrong with that request. Please try again.