# OpenGL Normal Mapping question

This topic is 3331 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 );



##### Share on other sites
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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634092
• Total Posts
3015447
×