Results 1 to 2 of 2

Thread: why donīt i need uNormalMatrix?

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    10

    why donīt i need uNormalMatrix?

    Hi!

    I have another question.

    This is my vertex shader:
    Code :
    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:
    Code :
    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:
    Code :
    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:
    Code :
    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.

  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    10

    Re: why donīt i need uNormalMatrix?

    OK, was a mistake. Of course i had to transform the normals too. Now i can see the difference.

Similar Threads

  1. Replies: 5
    Last Post: 02-05-2011, 09:47 AM
  2. I don't know this error.
    By phoebe0105 in forum OpenCL
    Replies: 13
    Last Post: 04-29-2010, 02:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •