PDA

View Full Version : Binormals and tangents



Morten
02-20-2001, 12:30 AM
I'm implementing BRDF in our 3d-engine, but I don't know how to calculate binormals and tangents for a bunch of triangles.
I downloaded a demo from nvidia, but it uses patches, not triangles, no help there...
http://www.opengl.org/discussion_boards/ubb/confused.gif

Screenshot: http://climax.nextframe.net/cgi-bin/rotate.cgi?SIZE=3

If it doesn't work, keep trying http://www.opengl.org/discussion_boards/ubb/smile.gif Btw it's a picture of a binding (from a cover)...

Thanks,
Morten Versvik

Cory Bloyd
02-20-2001, 07:09 AM
The binormal and tangent are vectors perpendicular to the normal and to eachother. Given the position and normal of a vertex, you can figure out the plane the vectors lie in, but not the specific directions that they point. For that you need more information.
The vectors should align themselves along and acrossed the "grain" of the material. I'm assuming the Nvidia demo uses the gradients of the patches to define this. If you don't have patches but do have textures, you could use the gradient to the texture coordinate UV's. If all you have is positions and normals... try picking some arbitrary but consistent vector, like the local z-axis, and do a cross product with your normal to get the tangent and then cross the tangent and the normal to get the binormal. It won't correspond to anything specific, but at least it's a start!
In the end, the tangent/binormal of a vertex is a separate property that realy should be specifically assigned, but I am not aware of any 3D modeling packages that currently support this concept.

-Cory


Originally posted by Morten:
I'm implementing BRDF in our 3d-engine, but I don't know how to calculate binormals and tangents for a bunch of triangles.
I downloaded a demo from nvidia, but it uses patches, not triangles, no help there...
http://www.opengl.org/discussion_boards/ubb/confused.gif

Screenshot: http://climax.nextframe.net/cgi-bin/rotate.cgi?SIZE=3

If it doesn't work, keep trying http://www.opengl.org/discussion_boards/ubb/smile.gif Btw it's a picture of a binding (from a cover)...

Thanks,
Morten Versvik

davepermen
02-20-2001, 07:48 AM
do have textures, you could use the gradient to the texture coordinate UV's.

what are the gradients (language problems.. could you use the official language: c++ or pseudocode, plz http://www.opengl.org/discussion_boards/ubb/smile.gif )

its just i'm not far enought in math yet.. i know what the tangent and binormal has to look like, but no change how to get it..

mcraighead
02-20-2001, 10:21 AM
md2shader already has to deal with this problem. You might refer to its source code.

- Matt

davepermen
02-20-2001, 10:30 AM
sorry, but the md2shader is not my code http://www.opengl.org/discussion_boards/ubb/smile.gif not so nice to read, i think..

davepermen
02-20-2001, 10:38 AM
ok looks like ife found it..is it here in?

md2ComputeModelInstant(Md2ModelInstant *instant,
int frameA, int frameB, float frameBlendWeight,
Vector objectSpaceLightPosition[],
Vector objectSpaceEyePosition[])

if so, is it that?

/* Compute the partial derivatives of X, Y, and Z with respect to S and T. */
{
GLfloat vec0[4], vec1[4]; /* Five components: X, Y, Z, S, T. */

/* Need difference vectors to find cross product. */
vec0[0] = v[1][0] - v[0][0];
vec0[1] = v[1][1] - v[0][1];
vec0[2] = v[1][2] - v[0][2];
vec0[3] = stc[1][0] - stc[0][0];

vec1[0] = v[2][0] - v[0][0];
vec1[1] = v[2][1] - v[0][1];
vec1[2] = v[2][2] - v[0][2];
vec1[3] = stc[2][0] - stc[0][0];

pxpt = (vec0[3] * vec1[0] - vec0[0] * vec1[3]);
pypt = (vec0[3] * vec1[1] - vec0[1] * vec1[3]);
pzpt = (vec0[3] * vec1[2] - vec0[2] * vec1[3]);
invlen = invSqrt(pxpt*pxpt + pypt*pypt + pzpt*pzpt);
pxpt *= invlen;
pypt *= invlen;
pzpt *= invlen;
}

Cory Bloyd
02-21-2001, 10:04 AM
That's it.

gradient == partial derivative == the amount the UV changed relative to the amount the XYZ changed between the vertices of the face