making of 1 million particles

this time I will give you some insights on how to create a gpu driven particle system with opengl and glsl. for most of my opengl work I choose cinder and highly recommend to get in touch with it. already knowing cinder is not essential but gives a better understanding of the text. also since this is just a making of, not a step by step guide, some OpenGL and shader knowledge is required.

1mp_bw

before we dive into the code I think it’s good to get an overview on how the system works. the base of this particle system is a so called ping-pong framebuffer object. ping-pong means that you have two framebuffer objects (fbo) which are drawn alternately. when fbo A is drawn fbo B is used for calculations. on the next frame B will be drawn and A is used for calculations and so on. the particle movement is calculated by an glsl shader, all results (current position, velocity,…) are saved into textures. the drawing of the particles is also controlled by a shader who controls opacity and size. each particle has a time to live, if it’s old enough it will be respawned at a new position with it’s initial velocity. you see there is not that much going on, so now let’s look at the code a little bit deeper!

get some more…

1 million particles revisited

1million particles

here we go again, I reworked my gpgpu particle system which I did some time ago (link). the new version offers a better particle movement driven by perlin noise. also it is a bit more colorful since the original version was black & white only. aside from some minor code tweaks the big thing is that you can grab a copy on github now! i’ve got some requests to share the code but never felt that it is good enough to give it to others (the new version might not be that better… ;-) ). i hope it will help people to learn something about gpgpu programming and OpenGL in general :-) at the moment I am also writing a “making of” to explain some of the nifty stuff a bit more, so check the blog the next days!

github

new processing sketch — cubicle

we have updated our home with some new furniture. as a result we now have more space to hang some pictures and what is better than creating the pictures by yourself? yes right, code them by yourself!!! at least if you can’t draw.

the sketch I made today is called “cubicle” and does nothing more than drawing some quads and rotate every quad by some degrees. the result is vortex of quads :-)

cubicle

 

 

 

the code behind it is fairly simple, nothing special to explain. just some basic setup of size and settings and after that we’re ready to go. draw a lot of quads till they reach the border which is set in the condition of the while iteration. have a look:

size(1000,1000);
background(255);

smooth();
strokeWeight(0.5);
noFill();

float initialSize = 20.0f;
float rotation = 0.430f;

float strokeAlph = 30.0f; 

while(initialSize < height - 300)
{
  stroke(0,strokeAlph); 
  pushMatrix();
  translate(width/2, height/2);
  rotate(rotation);
  rect( 0 - initialSize / 2, 0 - initialSize / 2, initialSize, initialSize);
  popMatrix();

  initialSize += sqrt( 2 * pow(initialSize,2)) * .0033;
  strokeAlph += .1f;
  rotation += noise(PI / 3);
}

if you want you can grab the code (and other sketches too) on my github!

 

i’m on github now!

i finally managed it to commit my processing sketches to github where you can grab / edit and share them! when i  get some time to clean up my c++ stuff I will commit them too but at the moment I’m not sure when this will be…

have fun with the code: my processing sketches on github