Advertisement Jump to content
Sign in to follow this  
16bit_port

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!