View Full Version : Tangent Vector
08-27-2002, 09:53 AM
Hi guys! I'm trying to use Lighting in OpenGL, and I'm having some problems.
The problem is glNormal3f.
I've read about this on the Internet, and found that I need to find the Normal Vector and the Tangent vector of two vectors. I know how to find the Normal Vector, but I don't know how to find the Tangent vector.
08-27-2002, 10:03 AM
well, i think you read about perpixellighting stuff, and you want to try that?
search on this forum for tangentspace, texturespace, and generation of it. search as well on flipcode..
i remember i've read this topic about a week ago, eighter here, or there..
for the rest, check demo codes from nvidia and ati..
08-27-2002, 10:12 AM
I'll try it!
08-27-2002, 03:26 PM
Ok it sounds like to me that you are trying to do perpixel lighting since you say you need the tangent vector. If so then you will also need the binormal. What you need to do to find these vectors is first for each poly, setup three plane equations like so:
Ax + Bu + Cv + D = 0
Ay + Bu + Cv + D = 0
Az + Bu + Cv + D = 0
Ok now I hope you know how to do partial derivatives because that is needed for this. http://www.opengl.org/discussion_boards/ubb/smile.gif Ok to find the tangent vector you need to find du/dx, du/dy and du/dz. The binormal is computed by finding dv/dx, dv/dy and dv/dz. While the 'texture space' normal can be computed by crossing these vectors. Example, the x component of the normal will be computed by (du/dx)X(dv/dx), where X means cross product here. Do that for the y and z components. The tangent space matrix is setup as:
|dudx dvdx tnx|
|dudy dvdy tny|
|dudz dvdz tnz|
So then your tangent space light vector will be found by: tsl = (TSM)(lvec), where TSM is the matrix above and lvec is the surface to light vector.
Ok there is my intro to all this stuff, reading the docs on this subject would be very good to do. Any specific questions can be asked here and I or someone else (if they beat me to it http://www.opengl.org/discussion_boards/ubb/wink.gif) will help in any way possible.
Oh BTW, if you dont know how to compute the partial derivatives that you need i'll be glad to compute them for you for you to use. It's pretty simple.
[This message has been edited by SirKnight (edited 08-27-2002).]
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.