ND2D – Particles GPU vs. CPU
October 5th, 2011 | Posted by in Experiments | Molehill / Stage3D | ND2D | TalkA few people where wondering why they can’t control individual particles in the ND2D particlesystem. Let me explain why:
The ParticleSystem2D is built for speed. This means, that everything and really everything for each particle is calculated on the GPU. When you create a system, initially the starting values for each particles are created and uploaded to the GPU. From now on, everything is calculated in shaders based on the current time step. This way ND2D is able to render 10.000 (or even more) particles at 60hz without any CPU usage. The drawback is, that you don’t have control over each particle, but you’ll have a lot of CPU time left for more important stuff. The ParticleSystem2D can be used for effects like rain, fire or water, but you won’t be able to animate a swarm of birds with it. You can play around with the system below, but be careful. Depending on the size of the particles you can display 10.000 at 60hz or nearly freeze your machine. The larger, the slower.
If you want to have control over individual particles, you can use one of the batch nodes provided by ND2D. The Sprite2DCloud or the Sprite2DBatch. With these batch nodes you’re able to move each child, but they are slower, because all the positional information has to be uploaded to the GPU every single frame. When I say slower, I mean that you can still display 1000 (or a lot more) particles alphablended at 60hz. This should be enough for a whole army of kinghts or a fancy mousefollower. Play around with it here:
And if you haven’t installed the new Flash Player 11 that has been released yesterday, grab it here.
You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.






Pretty cool stuff. Thanks for sharing.
OFFTOPIC – I am just curious – what do you think about the Starling fw? Any thoughts on this?
wow, really stunning perfomance, will look into this soon!
BTW, just a note: First example crashes having max particles set to zero.
Having real fun playing with this API! I started this morning, and then an hour ago you went and updated it again :) Quick question – what happens to “irregular” sized textures? For example if I provide a bitmap that is 220×104 then the texture size will be 256×128 – so my question is where do the extra pixels (36 on X and 24 on Y) get added? To the right/bottom? Or is the original bitmap centered with the excess around the edge? Also is there a way to view the Scene to see all of the outlines of the objects? (like a wireframe mode)
@Richard: True. If a BitmapData doesn’t match the 2^n sizes, a new BitmapData of the required size (for example 256×128) is genrerated and the old is drawn in the center of the new one. Currently there is no “wireframe” mode, but if you want to see the textures including the transparent areas, change the default color of the generated BitmapData in TextureHelper.generateTextureFromBitmap() to something visible.
where can i get the source code of this example? who can tell me ?or drop an email to me.
@Solo: Just click on one of the various ‘ND2D’ links in this post. All examples are included in the /example folder.
but how i can download the example to my computer. i can only read it online.
i have download the example,but there are many errors, can’t find the package “com.bit101.components”.why?
Pingback: ND2D best practices – howto - nulldesign // lars gerckens
@solo http://www.bit-101.com/minimalcomps/ you can find the components in there