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

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

  pos2.x = pos.x+sin(sin(pos.y*0.3127*freq+time*4.831+sin(pos.z*3.672*freq-time*4.812)*0.25))*voima*life;
  pos2.y = pos.y+sin(sin(pos.z*0.4824*freq-time*5.827+sin(pos.x*1.927*freq+time*4.172)*0.25))*voima*life;
  pos2.z = pos.z+sin(sin(pos.x*0.3761*freq+time*3.712+sin(pos.y*3.662*freq-time*5.278)*0.25))*voima*life;
  pos2 += vec3(sin(pos.y*0.01+time*3.42)*0.3, 1.0, sin(pos.x*0.01+time*4.826)*0.3)*voima*life;
  life=life+voima*0.0025;
  if (length(pos)>1024.0 || life>(1.0+sin(pos.x)*0.1)) {
    pos2 = texture2D(obutex, texcoord).rgb;
    pos2 += sin(life*123.53)*0.01;
    life=0.0;
  }
  
  gl_FragColor = vec4(pos2, life);
}
