## Fast face normals

kainsin
Unregistered

Post: #16
Math rules.
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!
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!