Advertisement

Orthonormal basis

Started by April 29, 2001 02:00 PM
1 comment, last by Jallen 23 years, 9 months ago
Anyone know how to construct an orthonormal basis for use in Dot product bumpmapping? I know the vertex normal vector and if I could figure out how to calculate the tangent vector I could calculate the binormal (N x T) and these would form the orthonormal basis. Thanks, Jason A. --- I write code. DelphiGL (http://delphigl.cfxweb.net)
---I write code.DelphiGL (http://delphigl.cfxweb.net)
The way I do it is to find the direction that the texture is mapped onto a polygon which gives you the second vector.
You could calculate the other two as simply any perpendicular to the normal but this would give you problems with real world models where polys are not mapped consistently.
The following is the code used per polygon for an indexed mesh. Its part of an inner loop - the resultant basis vectors are averaged for the basis for all vertices in that poly (same way as averaging vertex normals):

  // get vertex indices for facea = pIndices[ j+0 ];b = pIndices[ j+1 ];c = pIndices[ j+2 ];// get edge 1 of polyedge1[0] = v[b].x  - v[a].x;	// xedge1[1] = v[b].y  - v[a].y;	// yedge1[2] = v[b].z  - v[a].z;	// zedge1[3] = v[b].tu - v[a].tu;	// s// get edge 2 of polyedge2[0] = v[c].x  - v[a].x;	// xedge2[1] = v[c].y  - v[a].y;	// yedge2[2] = v[c].z  - v[a].z;	// zedge2[3] = v[c].tu - v[a].tu;	// s// cross product of edges is d_du vectord_du.x = edge1[3]*edge2[0] - edge1[0]*edge2[3];d_du.y = edge1[3]*edge2[1] - edge1[1]*edge2[3];d_du.z = edge1[3]*edge2[2] - edge1[2]*edge2[3];d_du = Normalize( d_du );// texture space z is same as smoothed face normaltz.x = v[a].nx + v[b].nx + v[c].nx;tz.y = v[a].ny + v[b].ny + v[c].ny;tz.z = v[a].nz + v[b].nz + v[c].nz;tz = Normalize( tz );// use dot projection to make a perpendicular to tzt = DotProduct( d_du, tz );tx.x = d_du.x - (t * tz.x);tx.y = d_du.y - (t * tz.y);tx.z = d_du.z - (t * tz.z);// tx x tz gets final perpendicular vector tyty = CrossProduct( tx, tz );  


edge1[] and edge2[] are float[4] arrays.

d_du, tx, ty and tz are 3 component vectors.



--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Advertisement
Sweet! Thanks for the reply, this helps quite a bit.

Jason A.
---
I write code.
DelphiGL (http://delphigl.cfxweb.net)

Edited by - Jallen on May 2, 2001 1:11:22 PM
---I write code.DelphiGL (http://delphigl.cfxweb.net)

This topic is closed to new replies.

Advertisement