Normal Mapping question

Started by
0 comments, last by mrr 14 years, 4 months ago
1) From what I understand so far, I'm suppose to pre-compute the tangent vectors before I start callig the vertex shader, right? 2) And to compute a tangent vector for vertex p1, which requires the position and the texture coordinates of p1, p2, and p3 (p1, p2, and p3 make up a triangle in a mesh), do I do this:

    (v3 - v1).(p2 - p1) - (v2 - v1).(p3 - p1)
T = -----------------------------------------
    (u2 - u1).(v3 - v1) - (v2 - v1).(u3 - u1)


? I got that from http://jerome.jouvie.free.fr/OpenGl/Lessons/Lesson8.php 3) Also since I'm using vertex arrays to render my meshes, I'm not sure how to pass these tangent vectors to the vertex shader. So, assuming 1) and 2) are correct, do I do something like this?

(in my shader)
attribute vec3 tan_vec;

(in my OpenGL app)
float tangentvectors[ ... ];          //contains pre-computed tangent vectors, every 3 floats make up a tangent vector

...

loc = glGetAttribLocation( prog, "tan_vec" );

glEnableVertexAttribArray( loc );
glEnableClientState( GL_VERTEX_ARRAY );

glVertexAttribPointer( loc, 3, GL_FLOAT, 0, 0, tangentvectors );
glVertexPointer( 3, GL_FLOAT, 0, vertices );


Advertisement
I create the tangent vectors in the plane of the vertex and then I do the cross product to get the normal. There are other faster ways though.

This topic is closed to new replies.

Advertisement