Particle Effect in a shader

I had an idea for a particle effect which left all the heavy lifting to the shader. Basically upfront when you add a particle you tell it the start and end position, time, rotation and scale. Then the shader can interpolate this at render time. This is a first rough go at it, it interpolates linearly. Also it never removes the old particles even though it stops rendering them, so there’s a lot more to do to make this optimal. It will drop down to about 20fps at about 2000-2500 particles on my iPad 2.

Code:
https://gist.github.com/sp4cemonkey/5254122

this is great! The optimization would of course be needed in order to have an aprr run any deent length of time, but I really like the look of the shader!

Actually it was my debug print statements that made it too slow. Even the first version runs 40fps with 10k particles (not 10k rendered, that includes dead ones).

I have now updated (gist in first post) so it reuses a particle that has expired when adding new ones, so it now should run just as fast forever.

One interesting side effect of reusing particles, is “new” ones won’t necessarily be top of the Z order stack…

Beautiful!

Another tweaked version in the gist. It now allows for easing modes (like tweens). You can ease position, rotation, size and alpha with different easings, and it’ll do linear, quad and exponential, either in or out.

Also, it will apply “gravity” as well. Now I need to do something with it… I’m thinking fireworks :wink:

https://gist.github.com/sp4cemonkey/5254122

I’ve refactored the particle system into a class. This also means if you want to run more than one particle system simultaneously with different textures it should be easy to do. Also put color back in, so it will tint the texture by the color specified in the particle.

The main class has a simple touch based dropping 100 particles each time you touch and retained backgrounds for nice fading/trails (which you’d never do in your app :wink: )

Update in the gist

Here’s another one that uses the particle system to create fireworks.

https://gist.github.com/sp4cemonkey/5335250

It can stutter a bit when touching as it does all the particle creation at touch time.

This great. Do you have the sound too?