Particles affected by Shader

Dummy question on shaders: if I want a shader to distort particles in an array but so it affects in a different fashion to each particle…
Is it possible?
Do I need an array of shaders?
How can I do it?

Thanks a lot everybody!
D!

In what way will it distort or alter them?

My aim: circles to bubbles.
I have added a shader object in my particle class, but it is kind of slow.

Yeah… that sounds like it’d probably be wicked slow.

You could probably just write a short global shader that draws a “bubble” (hollow circle) around each particle, with a variable to control for the radius of the bubble.

Did you see this?


Yeaaaaaahhhh F*king amazing :smile:
Your point sound good, let me check it :wink:
Thanks a lot!
D!

If I understand what you are trying to do is apply a shader to all your array of particles and then take certain number of particles and apply another shader to it. It all boils down to how many particles if you are dealing with performances.

It will indeed be slow. Again it all comes down to how many particles separately you are trying to affect. Usually when you want to use shaders you want to combine them with FBOs to improve performance, e.g:

    blurPassX.begin();{// FBO for shader
       ofClear (0,0,0,0);// I clear my FBO
       blurX.begin();{// I start my Shader
           blurX.setUniform1f("blurAmnt", (blurAmount/2));// Shader parameter
           particle.draw(0,0);// I draw my particles FBO
       }blurX.end();
    }blurPassX.end();

Now let’s say that I want to apply a shader to certain particles and not all of them:

    particle.begin();{// FBO for shader
       ofClear (relativeBoidColor.r, relativeBoidColor.g, relativeBoidColor.b, 0);// I clear my FBO
           for ( int i = 0; i < 30; i++){ // I want to draw 30 particles              
              if ( i % 2){// if the particle is an even number...
                 blurY.begin();//I apply a shader to my particle class - it distorts them on the Y axis.
                  blurY.setUniform1f("blurAmnt", (blurAmount/2));// Shader parameter
                  singleParticle[i].draw();// I draw my single particle inside the shader
                blurY.end();
             {else{// otherwise..
               singleParticle[i].draw();// No shader is applied.
             {
           {
    }particle.end();// I close my FBO

Then I want to affect all my particles…

    blurPassX.begin();{// FBO for shader
       ofClear (0,0,0,0);// I clear my FBO
       blurX.begin();{// I start my Shader
           blurX.setUniform1f("blurAmnt", (blurAmount/2));// Shader parameter
           particle.draw(0,0);// I draw my particles FBO
       }blurX.end();
    }blurPassX.end();

Finally I draw everything.

    blurPassX.draw(0,0);// I draw my final shader that contains everything.

Thanks a lot Sheva! Really helpful!