Game Development Reference
In-Depth Information
In the following code snippet, we obtain the reference of the light and material
ambient colors from the shader code:
function initShaders() {
...
shaderProgram.specularColorUniform =
gl.getUniformLocation(shaderProgram, "uSpecularColor");
...
shaderProgram.materialSpecularColor =
gl.getUniformLocation(shaderProgram, "materialSpecularColor");
...
}
In the following code snippet, we set the value of the material and light specular colors:
function setMatrixUniforms() {
...
gl.uniform3f(shaderProgram.materialSpecularColor,
specularColor[0],specularColor[1],specularColor[2]);
gl.uniform3f(shaderProgram.specularColorUniform,1.0,1.0,1.0);
...
}
Implementing Phong shading - Blinn-Phong
reflection
Open the 02-Loading-Model-Phong-Blinn-Phong.html file in your favorite text
editor. It contains the following code:
<script id="shader-fs" type="x-shader/x-fragment">
precision mediump float;
varying vec3 transformedNormal;
varying vec3 vertexPos;
uniform vec3 uAmbientColor;
uniform vec3 uLightingPosition;
uniform vec3 uDirectionalColor;
uniform vec3 uSpecularColor;
uniform vec3 materialDiffuseColor;
uniform vec3 materialAmbientColor;
uniform vec3 materialSpecularColor;
void main(void) {
vec3 normal=normalize(transformedNormal);
 
Search WWH ::




Custom Search