Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Binormals and tangents

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2001
    Location
    Norway
    Posts
    1

    Binormals and tangents

    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...


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

    If it doesn't work, keep trying Btw it's a picture of a binding (from a cover)...

    Thanks,
    Morten Versvik

  2. #2

    Re: Binormals and tangents

    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...


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

    If it doesn't work, keep trying Btw it's a picture of a binding (from a cover)...

    Thanks,
    Morten Versvik

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Feb 2001
    Location
    Switzerland
    Posts
    1,840

    Re: Binormals and tangents

    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 )

    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..
    http://davepermen.net - if i could stay true to my heart, i would feel totally free

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Sep 2000
    Location
    Santa Clara, CA
    Posts
    1,463

    Re: Binormals and tangents

    md2shader already has to deal with this problem. You might refer to its source code.

    - Matt

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Feb 2001
    Location
    Switzerland
    Posts
    1,840

    Re: Binormals and tangents

    sorry, but the md2shader is not my code not so nice to read, i think..
    http://davepermen.net - if i could stay true to my heart, i would feel totally free

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Feb 2001
    Location
    Switzerland
    Posts
    1,840

    Re: Binormals and tangents

    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;
    }
    http://davepermen.net - if i could stay true to my heart, i would feel totally free

  7. #7

    Re: Binormals and tangents

    That's it.

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •