Improved performance of raycasting

Aug 26, 2009 at 6:23 PM
Edited Aug 26, 2009 at 6:23 PM

Just kidding, this post is really about my new girlfriend.


Naah, it is really about a performance increase in the RayHelper class (used to be called CollisionHelper) :)

I just wrote about ray casting on my blog and decided to take a look at the RayHelper.LineIntersect() implementation (it is a user contribution). replaced the float equality checks with manual range checks. The fastest line intersection algorithm I know about is still the same old one from 1989, and that is what is used in this case. Here are the results:

Old: 1036 ms
Result: x212.4556 y122.5799
New: 36 ms
Result: x212.4556 y122.5799
~29x speedup

Old: 573 ms
Result: 0 0
New: 14 ms
Result: 0 0
~41x speedup

Not parallel:
Old: 361 ms
Result: 0 0
New: 22 ms
Result: 0 0
~16x speedup

Old: 568 ms
Result: 0 0
New: 14 ms
Result: 0 0
~41x speedup


There is still an epsilon float check when checking the denominator is equal to zero. Everywhere else there is a rangecheck, but they are not 100% accurate since they use floats (I also explained this on my blog and how it works). I think we can live without the 100% accuracy in this case.

Could you download the 58434 changeset and test it out?

Aug 29, 2009 at 7:51 AM

Amazing work Genbox !

That is an incredible improvment.
really nice ill give a try later today.

Aug 29, 2009 at 1:58 PM

Forgot to mention that it was over 1000000 iterations on my 2.33 Ghz Xeon computer. It is measured in ms and thus the results can't be directly translated to other computers.

The improvement might not be noticeable in common scenarios, but everything counts right?

I'm interested in the accuracy since it should be reduced in some scenarios.

Sep 1, 2009 at 4:00 PM

very impressive genbox!

Sep 19, 2009 at 12:07 AM

I recently applied the changeset and the difference is really noticeable. Thanks a lot!