Fast face normals

kainsin
Unregistered
 
Post: #16
Math rules.
Quote this message in a reply
Member
Posts: 145
Joined: 2002.06
Post: #17
Quote:Originally posted by kainsin
Math rules.
Well put.

"He who breaks a thing to find out what it is, has left the path of wisdom."
- Gandalf the Gray-Hat

Bring Alistair Cooke's America to DVD!
Quote this message in a reply
Member
Posts: 145
Joined: 2002.06
Post: #18
BTW, a friend of mine realized this just now:

(1/sqrt(x))*x = sqrt(x)

DOY!

so to summarize:
Code:
static const float gOneHalf = 0.5;

// calculate 1/sqrt(x) with pretty good accuacy
// x is double to prevent frsp generation before call
// return type is float to prevent frsp generation after call
float asm fastSqrtRecip(register double x) {
    frsqrte     fp2,x; // inv = 1/sqrt(x)
    lfs         fp3,gOneHalf(RTOC);
    fmuls       x,x,fp2; // f*inv
    fres        x,x; // 1/(f*inv)
    fadds       x,x,fp2; // 1/(f*inv)+inv
    fmuls       x,x,fp3; // .5*(1/(f*inv)+inv)
    blr;
}

// calculate sqrt(x) with pretty good accuacy
// x is double to prevent frsp generation before call
// return type is float to prevent frsp generation after call
float asm fastSqrt(register double x) {
    frsqrte     fp2,x; // inv = 1/sqrt(x) // inv = 1/sqrt(x)
    lfs         fp3,gOneHalf(RTOC); // load 0.5
    fmuls       x,x,fp2; // f*inv
    fres        fp2,fp2; // 1/inv
    fadds       x,x,fp2; // 1/inv+f*inv
    fmuls       x,x,fp3; // .5*(1/inv+f*inv)
    blr;
}

"He who breaks a thing to find out what it is, has left the path of wisdom."
- Gandalf the Gray-Hat

Bring Alistair Cooke's America to DVD!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Calculate face direction from bvh or 3d skeleton data harisz 3 3,055 May 29, 2013 10:50 AM
Last Post: OneSadCookie
  glDrawElements and Face indices Ashford 8 13,005 Nov 11, 2009 03:03 PM
Last Post: Ashford
  Simple ray-face intersect optimization NYGhost 8 6,339 Aug 17, 2007 12:01 PM
Last Post: NYGhost
  Indexed Face Sets (meshes) wyrmmage 4 4,173 Dec 15, 2006 11:18 AM
Last Post: wyrmmage
  Face Problems when Z-Near down!!! leodeus 5 4,961 Oct 31, 2005 12:14 PM
Last Post: OneSadCookie