Flash 10, Massive amounts of 3D Particles (with haXe)

A couple of months ago I was playing a round with strange attractors in flash, using AS3 and flex, then a post caught my attention.

Ralph Hauwert somehow managed to push 300k+ 3D particles around in realtime using alchemy, pixelbender and flash 10; I played around with the code a bit and made similar in pure as3, nothing magnificent.. a month later in a totally unrelated event (namely me getting thoroughly p'd off with PHP) I discovered haXe and set to work playing around with it.

Finally in another totally unrelated event I came across Joa Eberts AS3 only version of Ralphs earlier work; upon closer inspection I found it wasn't as fast as Ralph's alchemy version but completely awesome code non-the-less, to do this in pure AS3 is simply amazing.

As if you can't guess where this is going.. I thought I'd give it a go in "pure haXe" to see if one could replicate the speed of Ralphs version or maybe even top it. Sparing any further detail..

Here's haXe pushing 300k+ 3d particles around in realtime (source included)

and...

here's haXe pushing 600k particles (twice as many), and erm 1 Million (a bit stuttery but hell why not)

and.. (just for fun)

here's haXe pushing 300k particles in color, and 500k in color for good measure! - before downplaying the color versions, it's worth noting that each r,g,b value is independantly calculated and weighted as a float then combined to a render color right before updating the bitmap, so in effect it's not just x,y,z stored for each pixel, it's r,g,b as well - so 2x more number crunching + a bit more.

think I can safely say I love haXe and since doign this I've been going nuts doing lots of experiments using similar code :p

so, any doublts about haXe's perfomance with flash can be considered resolved imho.

regards, nathan

300k-lol

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Printed from: http://webr3.org/blog/haxe/flash-10-massive-amounts-of-3d-particles-with-haxe/ .
© Your Name Here 2012.

12 Comments   »

  • hosey says:

    None of the haxe links are working for me (blank screen). 64 bit Ubuntu (64 bit plugin)
    Ralphs did not work
    Joa Ebert worked

    None of yours. Wonder what is going on?

  • hosey says:

    Downloaded 300k color and it ran in standalone, but not in firefox
    10,0,22,87 installed

  • nathan says:

    strange, mine and ralphs both use the new opcodes supported in alchemy and haxe - maybe the plugin version doesn't support them in 64bit ubuntu? I'd test but I can only check in 32 bit here as running it in openbox on 32bit vista

  • tonypee says:

    This is great - i've been waiting for this to be done for a while - a perfect exampe of the power of haxe! One thins which you REALLY need to add is the same fps/memory counter in the top left - this will allow people to see the speed difference more clearly. I hope you can add this soon - and then lets show this puppy off ;P

  • nathan says:

    hi tony, good idea and thought the same myself; need to port mr doobs stats class over to haXe! unless there is already one or somebody else has done this?

  • Dr. Green says:

    Hmm. Strange. In Your code the in the updateMatrix option use the:

    matrix.appendRotation( flash.Memory.getFloat(_tx), Vector3D.Y_AXIS );
    matrix.appendRotation( flash.Memory.getFloat(_ty), Vector3D.X_AXIS );

    But whene i try to compile, HaXe says: there are no Y_AXIS, X_AXIS field the Vector3D class, and did not compile the swf.
    If i modify these 2 into YAXIS, XAXIS, then HaXe compile the code without any error message, but the swf does not draw anything.
    If i comment out this 2 line, then thew swf draw the particles, but no rotation.
    Any idea?

  • Dr. Green says:

    Hi again! :) /Thanks for Your e-mail!/
    Whene I tried to fix the upper mentioned HaXe bug, I have found an optimization.
    In the AS3 reference, I read, that Vector3D.X_AXIS is a constant, so I replace it with my own
    private static inline var X_axis : Vector3D = new Vector3D(1, 0, 0);
    private static inline var Y_axis : Vector3D = new Vector3D(0, 1, 0);

    static variables. The result, with 1 million particles:
    11 FPS with Vector3D.X_AXIS.
    14 FPS with static X_axis. (cca. 20% speed up is not bad.)
    And it is working well with 300k particles, too.

  • theRemix says:

    truly inspiring! keep the experiments coming :)

    i love haXe

  • Very cool stuff. I keep debating on whether I should spend some of my very limited free time on Haxe. Things like this are making it hard for me to avoid!

Trackbacks/Pingbacks

  1. Philippe.me » haXe – what’s in it for you
  2. Philippe.me » AS3 – Fast memory access without Alchemy

RSS feed for comments on this post , TrackBack URI

Leave a Reply

Additional comments powered by BackType

  • webr3 avatar