Game Development Reference
In-Depth Information
gl.uniform3f(shaderProgram.materialDiffuseColor,diffuseColor[0],
diffuseColor[1],diffuseColor[2]);
gl.uniform3f(shaderProgram.materialAmbientColor,ambientColor[0],
ambientColor[1],ambientColor[2]);
gl.uniform3f(shaderProgram.ambientColorUniform,1.0,1.0,1.0);
var lightingDirection = [-0.25,-0.25,-1.0];
gl.uniform3fv(shaderProgram.lightingDirectionUniform,
lightingDirection);
gl.uniform3f(shaderProgram.directionalColorUniform,0.2,0.0,0.0);
...
}
In the preceding code, we first calculate the normal matrix from mvMatrix . A normal
matrix is the transpose of the inverse of a matrix. We pass the matrix as a uniform so
that we can calculate new transformed normal vectors for illumination calculations.
We then pass our different uniform values using the uniform3f or uniform3fv
function. In these functions, 3 stands for the number of elements we want to pass
and f stands for the data type. The uniform3f function is explained in the following
code line:
void uniform[1234][fi](uint location,x,[y],[z])
Here, [1234] denotes the number of elements and [fi] denotes that we are passing a
float or an integer.
Examples are given in the following code lines:
gl.uniform3f( shaderProgram.ambientColorUniform, 1.2,1.3,1.4)
gl.uniform4i( shaderProgram.ambientColorUniform, 1,1,1,7)
The uniform3fv function is explained in the following code line:
void uniform[1,234][fi]v(uint location, Array value)
Here, [1,234] denotes the number of elements in the value parameter and [fi]
denotes that we are passing a float or an integer.
Examples are given in the following code lines:
gl.uniform3fv(shaderProgram.lightingDirectionUniform,
lightingDirection);
The uniformMatrix3fv function is explained in the following code line:
void uniformMatrix[234]fv(uint location, bool transpose, Array)
 
Search WWH ::




Custom Search