uniform sampler2D tex;
uniform float voima;
uniform float freq;
uniform float time;
uniform vec3 lpos;

void main(void) {
	vec2 texcoord = gl_TexCoord[0].xy;
	vec4 pier = texture2D(tex, texcoord);
	vec3 pos = pier.rgb; 
	vec3 pos2;
	float life=pier.a;
	float dist=200.0+life*life*life*life*life*life*1024.0;

  pos2.x = pos.x+sin(sin(pos.y*0.3127*freq+time*0.831+sin(pos.z*3.672*freq-time*0.512)*0.1))*voima;
  pos2.y = pos.y+sin(sin(pos.z*0.4824*freq-time*0.827+sin(pos.x*1.927*freq+time*0.672)*0.1))*voima;
  pos2.z = pos.z+sin(sin(pos.x*0.3761*freq+time*0.712+sin(pos.y*3.662*freq-time*0.278)*0.1))*voima;
  pos2 = mix(pos2, normalize(pos2)*vec3(dist, dist, dist), voima);
  life=life+voima*0.005;
  if (life>(1.0+sin(pos.z)*0.1)) {
    pos2 += vec3(sin(pos.x*2.412+time*3.124), sin(pos.y*3.823+time*5.82143), sin(pos.z*6.421+time*2.8324));
    pos2 = normalize(pos2)*200.0;
    //pos2 *= sin(time*16.0)*4.0+10.0;
    //pos2 += lpos;
    life=0.0;
  }
  
  gl_FragColor = vec4(pos2, life);
}
