Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: Shadow Volumes with Animated Meshes

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2003
    Location
    IL, USA
    Posts
    5

    Shadow Volumes with Animated Meshes

    I've coded and successfully rendered shadow volumes with static meshes. I just recently implemented my own bone based model format where each vertex is attached to at most 1 bone. Each frame I transform the vertex positions and normals in a vertex program using bone matricies that I pass in. My question is how would I find which triangles face my light source for these animated meshes. Assuming that a triangle can have 3 verts transformed by 3 different bone matricies. I also have the original triangle normals at my disposal incase that matters. Assuming this needs to be done on cpu.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    May 2001
    Location
    Beloit, Wisconsin
    Posts
    562

    Re: Shadow Volumes with Animated Meshes

    The silhouette edge information is only calculated once, when animating you only modify the vertices, right? So the indices stay the same, so you shouldn't really have to do anything... Unless you use a vertex program or something to do the animation of course.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2003
    Location
    IL, USA
    Posts
    5

    Re: Shadow Volumes with Animated Meshes

    I already have the edges precomputed, I mean when I decide WHICH edges to extrude, i check to see which triangles face the light source(light dot triangle normal), my problem is that when i modify the vert positions in the vertex program, the triangle normal is changed.

  4. #4
    Intern Contributor
    Join Date
    Mar 2001
    Location
    Marlborough, MA, USA
    Posts
    68

    Re: Shadow Volumes with Animated Meshes

    Originally posted by AMahajan:
    I already have the edges precomputed, I mean when I decide WHICH edges to extrude, i check to see which triangles face the light source(light dot triangle normal), my problem is that when i modify the vert positions in the vertex program, the triangle normal is changed.

    You need to rotate the normals using the bone matrix before doing your N.L test.
    Christopher Oat
    ATI Research, Inc.
    3D Application Research Group

  5. #5
    Member Regular Contributor
    Join Date
    Mar 2002
    Location
    Vancouver
    Posts
    314

    Re: Shadow Volumes with Animated Meshes

    Originally posted by chrisATI:

    You need to rotate the normals using the bone matrix before doing your N.L test.

    I don't think that is entirely correct. If you transform a vertex by a matrix then you need to transform the normal by the inverse transpose of the matrix.

  6. #6
    Junior Member Newbie
    Join Date
    Feb 2003
    Posts
    3

    Re: Shadow Volumes with Animated Meshes

    If you only have the 3 vertices for the triangles one the transform is complete, then you need to recompute the normal of the triangle.

    This can be accomplished by doing a cross-product of two edges of the triangle. Example:


    a triangles with vertices A, B, C:

    vector = CrossProduct( (B-A), (C-A) );

    //
    // Make sure to normalize it!
    //
    normal = Normalize(vector);


    If your triangles is clockwise wound from the front, this should produce the desired normal. If your triangles is clockwise wound from the back, then your normal will be reversed. You can simply, negate the components of the new vector to flip it, or reverse the input vectors to your cross-product.

    Also, note to properly test for light in front or back you need to make a plane equation from the triangle, which is a normal AND and distance. The distance can be found by taking the triangles new normal, and doing a dot product with one of it's vertices.

    Hope that helps.
    --
    -- JoeR
    -- Programmer, Contraband Entertainment
    --

  7. #7
    Member Regular Contributor
    Join Date
    Mar 2002
    Location
    Vancouver
    Posts
    314

    Re: Shadow Volumes with Animated Meshes

    An inverse transpose per mesh and 3 dot products per vertex should be cheaper than a cross-product and normalize for each vertex.

    [This message has been edited by PK (edited 02-20-2003).]

  8. #8
    Junior Member Newbie
    Join Date
    Feb 2003
    Posts
    3

    Re: Shadow Volumes with Animated Meshes

    Originally posted by PK:
    An inverse transpose per mesh and 3 dot products per vertex should be cheaper than a cross-product and normalize for each vertex.

    [This message has been edited by PK (edited 02-20-2003).]
    Yes it would be cheaper, if you need per vertex information. However, if you re-read my post more carefully you will note that we are generating a per triangle plane, so we can test front/back conditions with a light source.

    Performing a per-vertex light test would be useless for shadow-mesh edge determination.
    --
    -- JoeR
    -- Programmer, Contraband Entertainment
    --

  9. #9
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Re: Shadow Volumes with Animated Meshes

    PK,

    For a general transform-to-normal transform, you need the inverse transpose.

    However, if you use no non-uniform scale, and dont' apply the transform part of the matrix to the normal, then you can run the normal through the regular matrix. That's why the suggestion was to ROTATE the normal by the transform matrix for the bone.

    That's why you sometimes see vertices specified with a w of 1 (at that point meaning "full translation") and normals with a w of 0 (meaning "no translation") -- that way, the math just magically comes out right.

    Again, assuming no non-uniform scale.

    If you use non-uniform scale, you need one inverse transpose per bone matrix, and your cache will run a little warmer because you might have two matrices where previously you had one.

    Last, I agree: If you want to extrude 100% correct, you end up having to re-derive the face normal on the CPU.
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

  10. #10
    Junior Member Newbie
    Join Date
    Feb 2003
    Location
    IL, USA
    Posts
    5

    Re: Shadow Volumes with Animated Meshes

    Thanks for all of the suggestions guys, im already transforming all of the vertex normals in the vertex program. Calculating the triangle/plane normal and distance is gonna be much harder than I thought. I guess I might as well transform the verticies/normals on cpu and then generate the plane from there if I want accurate shadowing.

Posting Permissions

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