3D Particle Waveform (Composition by dust)

Author: dust
License: MIT
Date: 2010.10.18
Compatibility: 10.6
Categories:
Required plugins:
(none)

this patch generates 3d particles from the waveform of kineme audio tools.

inspiration and credit goes to t-link....

PreviewAttachmentSize
3DpAudio.qtz112.98 KB

dust's picture
Re: 3D Particle Waveform (Composition by dust)

so yeah this is just something i came up with today while matthais and i where trying to convert boids pseudo code to cl, which is now successfully working like it should. so this is a bi product of sorts i'm sharing. blah blah....

;)

jrs's picture
Re: 3D Particle Waveform (Composition by dust)

Hi Dustin

boids in cl......cool - don't suppose you would be happy to share it? I've been asked to take a high school class through the boids algorithm and this would be an excellent start

even if your not keen to share it could you post some videos please?

Cheers James

toneburst's picture
Re: 3D Particle Waveform (Composition by dust)

Would love to see that boids OpenCL code too! I started putting together some boids scripts in JS, but got sidetracked (as is so often the case). and never finished it. Makes much more sense to do it in CL though.

a|x

cybero's picture
Re: 3D Particle Waveform (Composition by dust)

Nicely turned out indeed, dust.

gtoledo3's picture
Re: 3D Particle Waveform (Composition by dust)

I'd be interested in seeing a boids openCL implementation, especially depending on what rules it actually implements.

I may as well post here; been looking at this - a pretty good breakdown in pseudocode.

http://www.vergenet.net/~conrad/boids/pseudocode.html

Almost makes me feel like I could do it with built in patches >)

dust's picture
Re: 3D Particle Waveform (Composition by dust)

so this is a 3 rule boid kernel. it seems a gl point patch is rendering the flock more correctly. not really sure whats going on with the mesh creator.

next is to make them stay on the screen etc... mouse xy is the perceived center of the boids which they flock to etc...

its not pretty yet but any help pushing this along would be awesome.

__kernel void main(
   __global const float4 *old_pos, __global const float4 *old_vel, __global const float *old_birth,
   __global const float4 *init_pos, __global const float4 *init_vel, __global const float *init_birth,
   __global const float *lifespan, float time, uint reset, float4 gravity, float dampen, float mx, float my, float4 color, 
   __global float4 *pos, __global float4 *vel, __global float *birth, __global float4 *col, __rd image2d_t srcimg, uint img_w, uint img_h)
{
   int  tid = get_global_id(0);
   int tsize = get_global_size(0);
   float4 p, a; 
   float age, nAge;
 
   // Calculate Age
   age = (time - old_birth[tid]);
   nAge = fmax(fmin(age/lifespan[tid], 1.f), 0.f);
 
   // Reset particle system if reset == 1
   if (reset == 1) {   
      pos[tid] = init_pos[tid];// + emit_pos;
      vel[tid] = init_vel[tid];
      col[tid]=(float4)(0.f);
      birth[tid] = time + init_birth[tid];
   } 
   // Particle pre-birth: Set the color to 0 and feedback the other values
   else if (age < 0.f) {
      pos[tid]=old_pos[tid];// + emit_pos;
      vel[tid]=old_vel[tid];
      col[tid]=(float4)(0.f);
      birth[tid] = old_birth[tid];
   }   
   // Particle life: Apply forces
   else if (nAge < 1.f) {   
 
 
      float4 v1 = (float4)(0.f);   // Centre of Mass
      float4 v2 = (float4)(0.f);   // Small Distance
      float4 v3 = (float4)(0.f);    // Match Velocity
 
      float4 oldV = old_vel[tid];
      float4 oldP = old_pos[tid];
 
      float4 pcJ = (float4)(0.f);
      float4 bJ = old_pos[tid];
      float4 c = (float4)(0.f);
      float4 pvJ = (float4)(0.f);
      float N = (float)0;
      for (int i=0; i<tsize; i++) {
         if (tid != i) {
         pcJ.x = mx;
         pcJ.y =my;
            N++;
            pcJ += old_pos[i];   
            float d = distance(old_pos[i], bJ);
            if (d < 0.01)   c -= d; 
            pvJ = pvJ + oldV;
         }
      } 
      pcJ = pcJ / N;
 
      v1 = (pcJ - oldP) / 100.;
      v2 = c;
 
      pvJ = pvJ / N;
      v3 = (pvJ - oldV) / 8.;
 
      vel[tid] = oldV + v1 + v2 + v3;
      pos[tid] = oldP + vel[tid] ;
 
 
 
 
 
      // Color
      col[tid] = (float4)(1.f-nAge)*color;
      birth[tid] = old_birth[tid];
   } 
   // Particle death: Reset all values
   else if (nAge == 1.f) {
      pos[tid] = init_pos[tid];// + emit_pos;
      vel[tid] = init_vel[tid];
      col[tid] = (float4)(0.f);
      birth[tid] = time;
   }
}
PreviewAttachmentSize
Boidz-MouseFlock.qtz65.54 KB

dust's picture
Re: 3D Particle Waveform (Composition by dust)

so i posted the rudimentary code. the pseudo code that GT linked might be easier than explaining CL.

i get it CL but its weird and i'm defiantly not on a level to really explain something like this.

matthais helps with some high school he might be better at explaining but to tell you the truth we where both stumped for a while.

any ways if you where to explain the meat of the algorithm is this.

float4 v1 = (float4)(0.f);   // Centre of Mass
      float4 v2 = (float4)(0.f);   // Small Distance
      float4 v3 = (float4)(0.f);    // Match Velocity
 
      float4 oldV = old_vel[tid];
      float4 oldP = old_pos[tid];
 
      float4 pcJ = (float4)(0.f);
      float4 bJ = old_pos[tid];
      float4 c = (float4)(0.f);
      float4 pvJ = (float4)(0.f);
      float N = (float)0;
      for (int i=0; i<tsize; i++) {
         if (tid != i) {
         pcJ.x = mx;
         pcJ.y =my;
            N++;
            pcJ += old_pos[i];   
            float d = distance(old_pos[i], bJ);
            if (d < 0.01)   c -= d; 
            pvJ = pvJ + oldV;
         }
      } 
      pcJ = pcJ / N;
 
      v1 = (pcJ - oldP) / 100.;
      v2 = c;
 
      pvJ = pvJ / N;
      v3 = (pvJ - oldV) / 8.;
 
      vel[tid] = oldV + v1 + v2 + v3;
      pos[tid] = oldP + vel[tid] ;

jrs's picture
Re: 3D Particle Waveform (Composition by dust)

Cheers - I'll have a play around and repost and modifications

M.Oostrik's picture
Re: 3D Particle Waveform (Composition by dust): boids

Dust and I are still working on it.

If you guys are interested we can share the boid code, once it is a little more cleaned up

dust's picture
Re: QC_CL Boids

@ties i got this running all in cl now. its pretty smooth but i can only push 24,000 particles using a gaussian gradient for particle textures. I have them flocking to the mouse and added some feedback trails. I can do about 100,000 with a particle size of 6 px with no texture. hit me up on skype and i can send you this new version or vise versa and we can see how many more particle you can push. still thinking about how we can do real trails. now that i got it outputting to a mesh we can add filters or what ever.

gtoledo3's picture
Re: QC_CL Boids

The one screen cap shows some collision going on at boundaries...that's pretty cool. This will be interesting to see develop.

You can do real trails by queueing past particle positions and rendering to mesh, line or quad. You may need to sort your structure by some kind of value that would denote time of particle, like if you particles do a color change over time (thanks smokris).

If the screen caps are definable as boids, then I happened to have posted a node based boid implementation a few minutes ago to the repository.

dust's picture
Re: QC_CL Boids

yes just saw your post nice one. like its all noodles. i can send you the code for this my skype is ter.maximus.

the code is on the net just not in qc yet. the first 3 rules where taken from the pseudo code you linked and then added some more behavioral stuff from this guys c++ code. http://www.behaviorworks.com/people/ckline/

also added is repulsion, repulsion step, velocity limiter, velocity match force, and center of mass force parameters as well as some others.

edit

i answered your question GT but it seems you edited out the question form the post.... so others can follow along george asked about the difference between boids and flocks and if this is flock or boid when avoidance rules are added.

end edit

to answer your question in part this video shows the boids algorithm. what matthais posted is the classic boid. once you add a mouse then your kind of changing it a bit.

seeing the boids flock to the center of the boids as a whole as well as flock to the center of them selfs until they hit and find the new center. so in theory they kind of wander around unless you limit to screen boundaries.

i added the mouse to the perceived (average) center of the flock so it kind of changes how the boids flock a bit by not being an average center of the group but where ever i put the mouse but the three basic rules still apply.

the rules applied in the simplest Boids world are as follows:

separation: steer to avoid crowding local flockmates

alignment: steer towards the average heading of local flockmates

cohesion: steer to move toward the average position (center of mass) of local flockmates

more complex rules can be added, such as obstacle avoidance and goal seeking etc..

flocking in unity is really cool because of the physics engine. it lets you simply add a collision sphere around a model making somethings simpler in code.

to do the collision is cl you use a distance function.

as per the amount of particles and the speed i am getting my number from t-linked. he has a particle patch that he says is 100 thousand particles and im doing half the amount his patch is. he must have made a typo cause his grid is only 100 x 100 which makes 10,000. just tried to re confirm but his site is down at the moment. maybe he is fixing a typo or i read his blog wrong.

;)

goto10's picture
Re: 3D Particle Waveform (Composition by dust)

yes! I've been hoping for someone smarter than me to implement boids on qc for so long now! massive props to dust and matthias!

gtoledo3's picture
Re: QC_CL Boids

I guess the reason I edited my post is because the sample screen cap seemed a bit chaotic, and I didn't see what I expect... it looked more like a QC particle system following a mouse, instead of a more nuanced movement with physics properties. Matthias's screen cap seemed a little more like what I would expect... since it's still in the works, I edited that aspect of questioning out of my post.

I'm looking forward to seeing how this ends up!

dust's picture
Re: 3D Particle Waveform (Composition by dust)

respect goto... this is sort of the first small step to a much larger installation. when the boids part is finalized one of us will post the source, only seems fit to put it back on the net as thats where it came from.

gtoledo3's picture
Re: QC_CL Boids

When you get your OpenCL boid code going, it would be interesting to add in some stuff to shape the flow like I have going in this screen cap. If you have a "flow" of vertices going, it will push them into the paths that you wish.

Man, I went all day and totally forgot about the Skype. I'm not a habitual video-chat guy... more like, write a letter on paper, give it to a pigeon. I'm an old-school holdout at heart.

dust's picture
Re: QC_CL Boids

i watched this a few hours ago... most defiantly once the boids are wandering the plan is to use pixelS based motion detection to shape the flock. actually you don't really see this in action but the boid file i posted here has a convenient macro made for this sort of thing; orginally by shaping the snow particle dev example. i have since abandoned that example but yes that is the idea.

no worries GT your in my gmail i will send you a link. just suggested skype as i use that for a telephone and its always open. i don't use the video feature really. i screen cast sometimes don't really know many people that like to video phone i have a few friends that sometimes chat with me over skype video but normally just my uncle in california calls me on it. talked with lee a couple times over skype. he is big into video chat and what not.

i'm really a loser i just signed up for another gmail account so i can star-trek i mean face-time with my self now that face-time works on my laptop. seriously i'm face-timming my self right now with my ipod and laptop.

but yeah so yeah my face time or email is dustin.oconnor@gmail.com or oconnor.dust@gmail.com im really bad at returning emails and what not so probably better i send to you.

i see you on gtalk sometimes but never for more than a min. or two. i only notice because your the only person that ever shows up on my list. i don't know how you got there must have answered a qc dev question of yours ?

gtoledo3's picture
Re: QC_CL Boids

Here's a tip; forget about pixelS and use OpenCL for that part. If you think about it, the OpenCL example that demonstrates text extrusion shows you how to return the color structure of an image, and it has the benefit of giving you vec4's off top.

Usually, I leave my gmail chat set to "away" but I flipped it on the other day, so you've probably seen me. I doubt it's because I was asking you any questions (no offense, I just never use it), it's probably just because of QC dev list emails. If you show up in someone's emails enough, they get pushed to the chat column if they also have gmail.

dust's picture
Re: QC_CL Boids

no the pixelS plugin has been remade in CL is what i was trying to say or well a monochrome version. that make sense about the qc list populating my g mail thing. i was thinking it was because i must have answered a dev list question that had your email reply to it a few years ago as i seem to be on a moderated list right now so it has been sometime sense i have been able to participate on that list. but i read the threads. i guess i don't really have many questions anymore so it doesn't bother me not being able to reply to things.