Inverse SQRT hack for grown ups

So, I was reading my usual daily tech internets when I saw this awesome article about implementing fast inverse root. this is something that game developers use a lot when calculating distances.

here is the link
http://blog.quenta.org/2012/09/0x5f3759df.html

The hack is a C hack.
I’m guessing this is fringe. but it would be awesome if we could get a lua fastInvSqrt().

I’d also like to know if anyone knows if this hack is implemented in box2d (faster collision detection and so on)

last question, in the future, will non-enterprise corona clients will be able to run their own C funcs? I believe this can help us greatly (open source wise).

[import]uid: 80469 topic_id: 31022 reply_id: 331022[/import]

my brain just exploded :slight_smile: [import]uid: 70635 topic_id: 31022 reply_id: 124056[/import]

This was an interesting question to me as I’d never really seen it previously; so I went and asked a couple of friends about the “magic number inverse square root” - and one of them told me;

The oldest trick in the book, some engineers in SGI hacked it back in 1992 for speeding up graphics intensive CPU computations, but given all of the advances in GPU, from a graphics GPU rendering pipeline, makes this routine almost obsolete - specifically advances such as parallax shading where a map of the vector normal is stored as an RGB image and a relief texture also represented in a grayscale image.

But purely talking about Corona, the Lua interpreter and the binding glue to C would have a huge impact on penalty. Especially because Lua doesn’t support bit operators and Lua only has a notion of a number and depending on your compiler setttings, that number could be a short, short integer, integer, long, long long, double long, double or float.
Also Lua doesn’t have a notion of “casting”, so you can’t cast from one type to another - plus Lua doesn’t have the notion of pointers and addresses - so this has to be done in pure C and/or assembly. [import]uid: 52491 topic_id: 31022 reply_id: 124121[/import]

my brain just exploded :slight_smile: [import]uid: 70635 topic_id: 31022 reply_id: 124056[/import]

This was an interesting question to me as I’d never really seen it previously; so I went and asked a couple of friends about the “magic number inverse square root” - and one of them told me;

The oldest trick in the book, some engineers in SGI hacked it back in 1992 for speeding up graphics intensive CPU computations, but given all of the advances in GPU, from a graphics GPU rendering pipeline, makes this routine almost obsolete - specifically advances such as parallax shading where a map of the vector normal is stored as an RGB image and a relief texture also represented in a grayscale image.

But purely talking about Corona, the Lua interpreter and the binding glue to C would have a huge impact on penalty. Especially because Lua doesn’t support bit operators and Lua only has a notion of a number and depending on your compiler setttings, that number could be a short, short integer, integer, long, long long, double long, double or float.
Also Lua doesn’t have a notion of “casting”, so you can’t cast from one type to another - plus Lua doesn’t have the notion of pointers and addresses - so this has to be done in pure C and/or assembly. [import]uid: 52491 topic_id: 31022 reply_id: 124121[/import]