
    #version 120 

    #extension GL_EXT_bindable_uniform : enable 

    #extension GL_EXT_gpu_shader4 : enable 
#define tex2D texture2D



varying vec3 normal;
varying vec3 normalB;
varying vec2 texture_coordinate_1; 
//varying vec3 vertex_to_light_vector;
varying vec4 position;
				uniform float PosY;
				uniform float ttime;
varying vec4 projection_position;

uniform mat4 ProjectionMatrix;

varying vec4 ShadowPosZ;
varying vec4 Color;
				uniform sampler2D texture2d_1;
				uniform sampler2D texture2d_2;
				uniform sampler1D textureDSP;
uniform float particlesize;
uniform float magnifier;
uniform float realttime;
varying float rnd;

varying vec2 TheUV;

void main()
{
rnd=1.0;
vec4 glVertex= gl_Vertex;
vec4 glVertexTemp=gl_Vertex;

float Displacement;


Displacement=0.0+texture2D (texture2d_1,glVertex.xy+vec2 (realttime*0.01,0.0)).x*0.5;
Displacement*=pow(texture2D (texture2d_1,glVertex.xy*0.02+vec2 (realttime*0.004,0.0)).x,6.0)*6.4;



Displacement+=0.08*sin(length (glVertex.xy*14.0)+realttime*2.0);
//*10.2*pow(clamp (1.001*sin(4.0*0.01+4.7*0.2+(1.0/2.5)*ttime*2.0*3.1416),0.0,1.0),18.0);





Displacement=texture2D (texture2d_2,glVertex.xy*1.0).x*10.0;

float T1=5.0-5.0*clamp ((ttime-144.2)*0.03,0.0,1.0);
glVertex.z+=20.0*pow(pow(T1*texture2D (texture2d_1,glVertex.xy*0.05+vec2 (realttime*0.0,0.0)).x,30.0)+1.85*length (glVertexTemp.xy-vec2 (0.5)),10.0);


float thel=length (glVertexTemp.xy-vec2 (0.5));
float T2=5.0*clamp ((ttime-151.2-thel*5.0)*0.03,0.0,1.0);
if (ttime>170.5)
 T2=5.0*clamp ((ttime-153.2-thel*5.0)*0.024,0.0,1.0);

//glVertex.z+=20.0*pow(T2*(1.0-length (glVertexTemp.xy-vec2 (0.5))),10.0);
//theb*0.1;


bool Add=false;
if (Displacement>0.01) Add=true;
//Add=false;
//Displacement=0.0;
//Displacement+=texture2D (texture2d_2,glVertex.xy*0.6+vec2 (ttime*0.05,0.0)).x*1.4;

//Displacement*=1.0+particlesize*10.0*texture1D(textureDSP,1.0/512.0).x;

Color=vec4 (0.0+texture2D (texture2d_1,glVertex.xy+vec2 (ttime*0.1)).y);


float Cll=texture2D (texture2d_1,glVertex.xy*1.7+vec2 (realttime*0.008,0.0)).x;
Cll=pow(1.8*Cll,6.0)*1.3+1.3;



float theb=5.0*pow(pow(T2*texture2D (texture2d_1,glVertex.xy*0.02+vec2 (realttime*0.0,0.0)).x,10.0)+0.0*length (glVertexTemp.xy-vec2 (0.5)),10.0);
glVertex.z+=theb;

glVertex.z+=5.0*pow(pow(T2*texture2D (texture2d_1,glVertex.xy*1.02+vec2 (realttime*0.0,0.0)).x,25.0)+0.0*length (glVertexTemp.xy-vec2 (0.5)),10.0);
if (theb>0.02)
if (theb<0.5){
//Color=vec4 (1.0,0.4,0.2,1.0);
Cll*=1.5;
}

//Cll*=1.0+clamp (theb*0.08,0.0,10.0);
glVertex.z=clamp (glVertex.z,-1000.0,1000.0);

Color*=vec4 (0.5,0.7,1.0,1.0)*(0.2+Cll);


rnd=1000.0;

//Color+=vec4 (0.05);
//if (Displacement<0.0001) Displacement=10000000.0;
//Color=vec4 (1.0);

//glVertex.z=Displacement*4.0*magnifier;
Cll*=0.5;
//Add=false;
//if (abs(glVertex.z)<30.0)
if (Add)
{
Cll*=1.0;


float fup=0.0+clamp ((ttime-162.8)*1.15,0.0,10000.0);
if (ttime>170.5)
 fup=0.0+clamp ((ttime-171.8)*1.15,0.0,10000.0);

fup*=fup;

float fup2=clamp (fup*3.0,0.0,1.0);
float fup3=clamp (fup*0.5,0.0,1.0);
//Color+=(vec4 (2.0,0.7,0.4,1.0)*Color-Color)*fup3;
Cll*=1.0+fup3*1.0;
float fangle=-0.9*fup2+fup2*0.4*sin(40.0*ttime);
fup*=0.1*fup;
glVertex.z+=fup;
if (glVertexTemp.x<0.55) { 
	if (glVertexTemp.y<0.49) {
	//	Color=vec4 (1.0,0.0,0.0,0.0);
		float x=glVertexTemp.y-0.49;
		float y=0.0;
		float f=fangle;
		float xt=x*cos (f)-y*sin(f);
		float yt=y*cos (f)+x*sin(f)*20.0;
		xt+=0.49;
		yt+=0.01+fup;
		//+5*sin(ttime);
//		glVertexTemp.z=vec2 (xt,yt);
		glVertex.yz=vec2(xt,yt);

	}
	if (glVertexTemp.y>0.51) {
	//	Color=vec4 (1.0,0.0,0.0,0.0);
		float x=glVertexTemp.y-0.51;
		float y=0.0;
		float f=-fangle;
		float xt=x*cos (f)-y*sin(f);
		float yt=y*cos (f)+x*sin(f)*20.0;
		xt+=0.51;
		yt+=0.01+fup;
		//+5*sin(ttime);
//		glVertexTemp.z=vec2 (xt,yt);
		glVertex.yz=vec2(xt,yt);
	}
		
		//if (glVertexTemp.y>0.51) Color=vec4 (1.0,0.0,0.0,0.0);
}
glVertex.x+=fup*0.055;
//glVertex.z+=10.0*0.01;
}





//Color=vec4 (1.0);
//Cll=1.0;


//glVertex.y+=ttime*0.1;
glVertex.y=mod(glVertex.y,1.0);
glVertex.xy*=40.0; glVertex.xy-=vec2 (20.0);
{
float sff=pow (1.1*texture2D (texture2d_1,vec2(glVertexTemp.xy*1.2)+vec2 (ttime*0.001)).x,1.0)*2.5;
	glVertex.x+=sff;
}

glVertex.z+=0.0*10.0;
//sin(20.0*ttime);
rnd=10000000.0;
// sphere out


{	
	vec4 glVertex2=glVertexTemp;
float dist=sin(glVertexTemp.y*3.141593)*1.0+
0.0*pow (1.1*texture2D (texture2d_1,vec2(glVertexTemp.y*0.6,glVertexTemp.x)+vec2 (ttime*0.001)).x,3.0)*2.5;
//dist=1.0;
glVertex2.x=sin(ttime+glVertexTemp.x*2.0*3.141593)*1.0*dist;
glVertex2.y=cos(ttime+glVertexTemp.x*2.0*3.141593)*1.0*dist;
glVertex2.z=(glVertexTemp.y-0.5)*2.0;
glVertex2.xyz/=length (glVertex2.xyz);
glVertex2.xyz*=20.0;

float sff=pow (1.1*texture2D (texture2d_1,vec2(glVertexTemp.y*0.2,glVertexTemp.x*0.2)+vec2 (ttime*0.001)).x,3.0)*2.5;
float PPosY=1.0-3.0*clamp ((ttime-160.8)*0.05,0.0,1.0);
PPosY=-2.0+PosY*0.4;
//PPosY=PosY;
PPosY=0.0;
if (ttime>170.5){

	float rw=clamp ((ttime-170.5)*0.5,0.0,1.0);
PPosY=rw*0.055*sin(ttime+20.0*texture2D( texture2d_1,glVertexTemp.xy*0.55+vec2 (0.0*ttime)).x);
	rw=clamp ((ttime-176.5)*0.1,0.0,1.0);
//PPosY+=rw*0.655*sin(ttime+20.0*texture2D( texture2d_1,glVertexTemp.xy*0.35+vec2 (0.0*ttime)).x);
}
else
{

	float rw=clamp ((ttime-167.5)*0.75,0.0,1.0);
PPosY=rw*0.055*sin(ttime+20.0*texture2D( texture2d_1,glVertexTemp.xy*0.55+vec2 (0.0*ttime)).x);

}

float _PosY=clamp (PPosY*1.0+sff*0.0,-1.0,1.0);
//glVertex=vec4 (0.0);
if (abs(glVertex.z)>900.0) _PosY=0.0;
glVertex+=(glVertex2-glVertex)*_PosY;


//glVertex=glVertex2;
//x' = x cos f - y sin f
//y' = y cos f + x sin f	
	
	//Displacement*1.0*sin(ttime*4.0)*pow((1.0-_PosY),8.0);

}
//Cll*=5.0;

//if (Add) glVertex.z+=1000.0;







//glVertex.z+=PosY*100.0;
glVertex= gl_TextureMatrix[0] * glVertex;

gl_Position =  glVertex;

TheUV=gl_MultiTexCoord0.st;
//vec2 TheUV1=gl_Vertex.xy*0.03;
//TheUV1=gl_MultiTexCoord0.st*3.0;
//Color=vec4 (1.0);
gl_Position = gl_ModelViewProjectionMatrix * gl_Position;
//rnd=gl_Color.r;
position=gl_Position;

//	if (length (glVertexTemp.xy-vec2 (0.5))>0.3) Color*=vec4 (3.0,0.9,0.3,1.0);

if (texture2D (texture2d_1,vec2(glVertexTemp.xy*0.6+vec2 (ttime*0.05))).x>0.5)
Color*=vec4 (2.0,0.9,0.3,1.0);


//float ff=Color.x;Color.x=Color.z;Color.z=ff;
//swap (Color.x,Color.z);
//Cll=2.0;
//	gl_PointSize =1-7.0/gl_Position.w;
	gl_PointSize =Cll*particlesize*125.0/gl_Position.w;
	//gl_PointSize =particlesize*125.0/gl_Position.w;
	///gl_Position.w;

}











