Fun with Particles; Yet Another Shader Editor

During my previous experiment, with particles on a Perlin Forcefield, I came across Yet Another Shader Editor / http://yase.chnk.us/, really fun site (to me) where you can enter some OpenCL code to control a particle and a lot of particles will be rendered which follow the code. The site was created by Ryan Alexander.

On this page I intend to collect my YOSE experiments;

Particles on perlin force field:http://yase.chnk.us/#zz

image

Phlegm fountain: http://yase.chnk.us/#z7t

image

 

#define sim_res 1700
#define pixel_scale 2

const float timeVariation=0.03; const float worldSize = 10.;
const float speed=0.0055; const float spawnSize = 0.1;
const float maxAge=600.; const float outwardsForce = .2;
const float aging=0.002;

vec3 perlinForceField(vec4 pos, float variedTime){ 
  /* A time-warying Simplex force field */
  return
    vec3( 
      noise(pos.x, pos.y, pos.z + variedTime), 
      noise(pos.x+400. + variedTime, pos.y, pos.z),
      noise(pos.x+500., pos.y + variedTime, pos.z));
}

vec3 heartbeat(
  vec4 pos, float time){
	vec3 push= normalize(vec3(pos))*0.007;
  push.z=abs(push.z)*3.;
  float beat=sin(time*5.5);
  if(beat<0.)
  {
    beat*=.3;
  }
  return push*beat;
}

void stepPos(in float i, in vec4 prevPos, 
             in vec4 pos, out vec4 nextPos) {
  float variedTime = time*timeVariation;
  vec3 delta = perlinForceField(pos, variedTime);
  delta = normalize(delta)*speed;
	delta = delta + heartbeat(pos, time);
	nextPos.x = pos.x + delta.x;
	nextPos.y = pos.y + delta.y;
	nextPos.z = pos.z + delta.z;
  nextPos.w = pos.w+aging;  

  if(abs(nextPos.x)>worldSize||abs(nextPos.y)>worldSize||
     abs(nextPos.z)>worldSize||nextPos.z<-10.0||
     nextPos.w>maxAge*aging||time<=0.01)
  {
    float range=worldSize*spawnSize;
    nextPos.x = noise(pos.x, pos.y, i*3.+time)*range;
    nextPos.y = noise(pos.x, pos.y, i*3.+time*3.)*range;
    nextPos.z = -2.+noise(pos.x, pos.y, i*3.+time*5.)*range;
    nextPos.w = noise(pos.x, pos.y, i*3.+time*5.)*maxAge*aging;
  }    
}

 

Turbulent star: http://yase.chnk.us/#2r

image

#define sim_res 1500
#define pixel_scale 1

const float timeVariation=0.07; const float worldSize = 10.;
const float speed=0.0075; const float spawnSize = 0.1;
const float outwardsForce = .2;
const float radius=3.;

vec3 perlinForceField(vec4 pos, float variedTime){ 
  /* A time-warying Simplex force field */
  vec3 force=
    vec3( 
      noise(pos.x, pos.y, pos.z + variedTime), 
      noise(pos.x+400. + variedTime, pos.y, pos.z),
      noise(pos.x+500., pos.y + variedTime, pos.z));

  force = normalize(force);  

  return force;
}

vec3 sphereForce(vec3 pos){
  float len=length(pos);
	if(len<radius)
  {
		return normalize(pos)*(radius-len);
  }

	return -normalize(vec3(pos))*0.004;
}

void stepPos(in float i, in vec4 prevPos, 
             in vec4 pos, out vec4 nextPos) {
  float variedTime = time*timeVariation;
  vec3 delta = perlinForceField(pos, variedTime)*speed; 
	delta = delta + sphereForce(pos.xyz);
	nextPos.x = pos.x + delta.x;
	nextPos.y = pos.y + delta.y;
	nextPos.z = pos.z + delta.z;

	bool dead=noise(i+frame, i-frame, i+frame)<-0.99;
  if(abs(nextPos.x)>worldSize||abs(nextPos.y)>worldSize||
     abs(nextPos.z)>worldSize||nextPos.z<-10.0||
     dead||time<=0.01)
  {
    vec3 spherePos=
      normalize(
        vec3(
          noise(pos.x, pos.y, i*1.+time),
          noise(pos.x, pos.y, i*2.+time*3.),
          noise(pos.x, pos.y, i*3.+time*5.)))*radius;    

    nextPos.xyz = spherePos.xyz;
  } 

  nextPos.w = 0.1+min(1.,(length(nextPos.xyz)-radius)/(1.1));
}

 

Hairball: http://yase.chnk.us/#1n

image

Based on one of Ryan Alexanders originals, but using perlin force fields to perturb the particles.

#define sim_res 312

vec3 spring(in vec3 a, in vec3 b, in float len, in float power) {
  vec3 o = b - a;
  float m = length(o) + 0.00001;
  return (o / m) * power * (m - len);
}

void stepPos(in float i, in vec4 prevPos, in vec4 pos, out vec4 nextPos) {
	float	n = 500.;
  float t = i / count, noc = n / count;
  float g = floor(t * n), gt = fract(t * n), omgt = 1. - gt;

	int ci = int(count), ii = int(i);

  // Step
  vec3 np = pos.xyz + (pos.xyz - prevPos.xyz) * 0.9;

	// Spring
  float jf, pwr = .01, len = 1. / (count / n);
  vec3 p;
  for(int j = 1; j < 16; ++j) {
    jf = float(j);
    if(ii - j > 0 && floor((i - jf) * noc) == g) {
      p = getPos(i - jf).xyz;
    	np += spring(pos.xyz, p, len * jf, pwr);
    }
    if(ii + j < ci - 1 && floor((i + jf) * noc) == g) {
      p = getPos(i + jf).xyz;
    	np += spring(pos.xyz, p, len * jf, pwr);
    }
  }

  // Turbulence

  //nextPos.xyz = mix(rand3(g + floor(frame / 500.)) * omgt, np, 1. - gt * gt * 0.05);


  vec3 turbulence = 
    (0.5+sin(time*2.))*
    vec3(
      noise(pos.x*2.+ frame*0.005, pos.y, pos.y )*0.001,
      noise(pos.x*2., pos.y+ frame*0.005, pos.z+100.)*0.001,
      noise(pos.x*2., pos.y, pos.z+200.+ frame*0.005)*0.001);

  nextPos.xyz = mix(rand3(g) * omgt, np, 1. - gt * gt * 0.05)+turbulence;
  nextPos.w = omgt * omgt;
}

Experimental

Particles bouncing of sphere and plane: http://yase.chnk.us/#lx

About mfagerlund
Writes code in my sleep - and sometimes it even compiles!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: