Hi!
I have another question.
This is my vertex shader:
attribute vec3 aVertex;
attribute vec3 aNormal;
uniform mat4 uModelView;
uniform mat3 uNormalMatrix;
uniform mat4 uProjection;
varying vec4 vPosition;
varying vec3 vNormal;
varying vec3 vColor;
void main(void) {
vColor = aVertex.xyz * 0.5 + 0.5;
//vNormal = uNormalMatrix * aNormal; // <-------------
vNormal = aNormal;
vPosition = uModelView * vec4(aVertex, 1.0);
gl_Position = uProjection * vPosition;
}
Script for animation:
function cycle() {
// Animation:
var position = [0, 0, -5];
var rotation = Date.now() / 1000;
var axis = [0, 1, 0.5];
var mvMatrix = webgl.setModelView(gl, program, position, rotation, axis);
//webgl.setNormalMatrix(gl, program, mvMatrix); // <----------
draw(); // drawing the elements in the function draw ...
var id = requestAnimationFrame(cycle);
}
Method setModelView sets uModelView:
function setModelView(gl, prgm, pos, rot, axis) {
var mvMatrix = mat4.create();
mvMatrix = mat4.identity(mvMatrix);
mat4.translate(mvMatrix, pos);
mat4.rotate(mvMatrix, rot, axis);
// sets uModelView:
gl.uniformMatrix4fv(
gl.getUniformLocation(prgm, 'uModelView'),
false,
mvMatrix
);
return mvMatrix;
}
And method setNormalMatrix sets uNormalMatrix:
function setNormalMatrix(gl, prgm, mv) {
var normalMatrix = mat4.toMat3(mv);
// sets uNormalMatrix:
gl.uniformMatrix3fv(
gl.getUniformLocation(prgm, 'uNormalMatrix'),
false,
normalMatrix
);
}
Currently i don´t use uNormalMatrix. Everything seems to work fine.
But i don´t understand why it isn´t necessary to set uNormalMatrix.?.?.?.?
The vertices are transformed by uModelView.