Fast face normals
Quote:Originally posted by kainsinWell put.
Math rules.
"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!
BTW, a friend of mine realized this just now:
(1/sqrt(x))*x = sqrt(x)
DOY!
so to summarize:
(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!
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| glDrawElements and Face indices | Ashford | 8 | 8,009 |
Nov 11, 2009 03:03 PM Last Post: Ashford |
|
| Simple ray-face intersect optimization | NYGhost | 8 | 4,646 |
Aug 17, 2007 12:01 PM Last Post: NYGhost |
|
| Indexed Face Sets (meshes) | wyrmmage | 4 | 3,137 |
Dec 15, 2006 11:18 AM Last Post: wyrmmage |
|
| Face Problems when Z-Near down!!! | leodeus | 5 | 3,951 |
Oct 31, 2005 12:14 PM Last Post: OneSadCookie |
|
| keep always visible a polygon face...!!! | alert | 5 | 3,880 |
Apr 14, 2005 09:46 AM Last Post: alert |
|

