

    #version 120 

    #extension GL_EXT_bindable_uniform : enable 

    #extension GL_EXT_gpu_shader4 : enable 
#define tex2D texture2D

uniform float Screensize;

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 Random;
varying vec4 projection_position;

uniform mat4 ProjectionMatrix;

varying vec4 ShadowPosZ;
				uniform sampler2D texture2d_1;
	uniform sampler2D texture2d_depth;
	uniform sampler2D texture2d_3;
	uniform sampler2D texture2d_random;
uniform float particlesize;
varying float rnd;
uniform float ttime;
uniform float Dust;
uniform float Wash;
uniform float TheFlash;
uniform int ParticleMode;

varying vec4 Color;

void main()
{

vec4 glVertex= gl_Vertex;

glVertex= gl_TextureMatrix[0] * glVertex;
gl_Position =  glVertex;
position=gl_Vertex;


vec2 Displacement=1.0*texture2D (texture2d_random,0.5*position.xy+vec2 (ttime*Random)*0.1+vec2(Random)*0.25).xy*0.011;

//position.xy+=-Displacement*PosY;
gl_Position.xy+=Displacement;




//gl_Position.z-=texture2D (texture2d_depth,position.xy).x*0.05;
//gl_Position.z-=texture2D (texture2d_depth,position.xy).x*5.7-5.0;
gl_Position.z-=0.75;

float thedepth=texture2D (texture2d_depth,position.xy).x;

float fuzz=texture2D (texture2d_1,position.xy).w*4.0+0.0;


float ThePosY=PosY;
ThePosY=clamp (ThePosY,0.0,1000.0);
//ThePosY=0.3;
float thealpha=ThePosY*50.0*texture2D(texture2d_1,position.xy).z*sin(ttime+position.x*2.0)*pow(thedepth*1.1,10.0);
//thealpha+=10.0*ThePosY;
//thealpha=0.0;
//thealpha=0.2;
//thealpha=clamp (thealpha,0.2,1000.0);
//if (thealpha<0.0) thealpha=0.2;
//thealpha=0.2;

vec2 displacement; 

displacement.x=(thealpha)*sin(texture2D (texture2d_random,0.015*position.xy).z*5.0+Random*0.7+(ttime)*0.44)*0.01;
 displacement.x+=thealpha*sin(texture2D (texture2d_random,0.035*position.xy).z*5.0+Random*0.8+(ttime)*0.7)*0.01;

displacement.y=thealpha*sin(texture2D (texture2d_random,0.014*position.xy).z*5.0+Random*0.75+(ttime)*0.33)*0.01;
 displacement.y+=thealpha*sin(texture2D (texture2d_random,0.024*position.xy).z*5.0+Random*0.9+(ttime)*0.56)*0.01;

// displacement.x+=0.3*TheFlash*texture2D (texture2d_random,ttime*0.2+0.011*position.xy).z;

 //displacement.x+=ThePosY*texture2D (texture2d_random,0.012*position.xy).z*0.12;
 //healpha*0.1;
 //sin(texture2D (texture2d_random,0.035*position.xy).z*5.0+Random*0.8+(ttime)*0.7)*0.01;

{ 

 //gl_Position.x+=thealpha*sin(texture2D (texture2d_random,0.15*position.xy+vec2 (ttime)*0.003+vec2(Random)*0.5).x)*0.011;
//gl_Position.y+=thealpha*cos(texture2D (texture2d_random,0.15*position.xy+vec2 (ttime)*0.003+vec2(Random)*0.5).y)*0.011;

//gl_Position.x+=thealpha*sin(texture2D (texture2d_random,0.015*position.xy+vec2 (ttime)*0.1+vec2(Random)*0.1).x)*0.04;
//gl_Position.x+=thealpha*sin(texture2D (texture2d_random,0.015*position.xy*0.0+vec2 (ttime)*0.001).x)*0.01;
//displacement*=clamp (1.0-1.0*texture2D(texture2d_1,position.xy).x,0.0,1.0);
//displacement.xy-=2.0*vec2(clamp (ThePosY-2.0,0.0,1.0))*(texture2D (texture2d_random,0.025*position.xy).x*0.1-0.0);

	gl_Position.xy+=displacement;


//gl_Position.xy+=-PosY*0.04*(texture2D (texture2d_1,position.xy).xy*1.0)-vec2 (0.0);



	//gl_Position.zthealpha*ThePosY*(1.0+Random*0.3+texture2D (texture2d_random,0.01*position.xy).x)*0.05;

//gl_Position.y+=thealpha*cos(texture2D (texture2d_random,0.015*position.xy+vec2 (ttime)*0.0014+vec2(Random)*0.1).y)*0.04;

//gl_Position.z+=0.2*thealpha*cos(texture2D (texture2d_random,0.015*position.xy+vec2 (ttime)*0.0004+vec2(Random)*0.1).y)*0.04;
}


//gl_Position.xy+=PosY*thedepth*sin(position.x*343.0)*sin(position.y*232.0);
//(texture2D (texture2d_random,0.03*position.xy+vec2 (ttime)*2.1+vec2(Random)*0.5).xy-0.5)*0.035;
//gl_Position.x+=(texture2D (texture2d_random,position.xy).x)*0.035*PosY;
//gl_Position.x+=(texture2D (texture2d_random,position.xy*0.1+vec2 (0.0,ttime)).x)*0.035*PosY;


//gl_Position.y+=PosY*pow ((texture2D (texture2d_depth,position.xy).x)*1.01,100.0);
//gl_Position.xyz+=PosY*(texture2D (texture2d_random,0.01*position.xy).xyz-vec3(0.5));
//gl_Position.y+=PosY;
//gl_Position.y=clamp (gl_Position.y,-100.0,1000.0);
rnd=1.0;





//if (Dust>0.5)gl_Position.y+=PosY*tex2D (texture2d_1,position.xy).x*5.0;



float ff=texture2D (texture2d_random,position.xy*0.01+0.5*vec2 (thedepth)).x*texture2D (texture2d_random,vec2 (ttime*0.0003+Random)+position.xy*0.013).x;

float fss=2.8*PosY+3.0*position.x+Random*0.05+0.615*thedepth+0.0*position.y+5.0*tex2D (texture2d_1,position.xy).x;
fss*=-1;
//if (texture2D (texture2d_1,position.xy).x<0.4)
Color=vec4 (0.0);
if (Dust>0.5)
if (ff<fss)
{
//gl_Position.z+=1.0*pow(fss-ff,2.0);
float fff=4.0*pow(fss-ff,2.0);
//	gl_Position.x+=fff;
}



fss=+2.8*PosY-5.0+2.0*position.x+Random*0.03+0.315*thedepth+0.0*position.y;
//fss=-0.8*ttime-5.0+0.2*position.x+Random*0.03+0.315*thedepth+0.0*position.y;
fss*=-1;
//if (texture2D (texture2d_1,position.xy).x<0.4)
Color=vec4 (1.0);

//if (Dust<0.5)
if (ff<fss)
{
//gl_Position.z+=1.0*pow(fss-ff,2.0);
//float fff=1.0*pow(fss-ff,2.0);
float fff=0.05*sin(1.0*(fss-ff));
//	gl_Position.z+=fff*(texture2D (texture2d_1,position.xy).w)*3.0;
//	Color-=1.0*vec4 (fff*Random);
}





//Color=vec4 (0.0)+(0.0+length (displacement)*0.2)*0.0;
Color=vec4 (0.0)+(0.0+length (displacement)*0.2)*0.3*Wash;
//if (Dust<0.5)

//Color=vec4 (1.0);

//if (Dust<0.5)
if (texture2D (texture2d_1,position.xy).w>0.02)

{
//float fss=2.8*PosY+0.3*position.z+Random*0.2;

	vec3 fss=0.4*PosY*(vec3(1.0)+texture2D (texture2d_random,vec2 (ttime*0.1000)+position.xy*0.1).xyz);
//if (fss.x>0.1) fss.y=100.0; else fss.y=0.0;

	//gl_Position.y+=fss.y*texture2D (texture2d_1,position.xy).w;
	


}






gl_Position = gl_ModelViewProjectionMatrix * gl_Position;




float ff2=1.0+0.1*texture2D (texture2d_random,position.xy*0.01+0.5*vec2 (thedepth)).x*texture2D (texture2d_random,vec2 (ttime*0.003+Random)+position.xy*0.053).x;
//ff2=pow(ff2,35.0)*0.1;
//if (Dust<0.5) ff2=1.0;
ff2*=1.0-length (displacement)*2.0;
ff2=clamp (ff2,0.3,3.0);
//ff2=1.0;
//Color=gl_Color;
//rnd=gl_Color.r;
	gl_PointSize =particlesize*11.0/texture2D (texture2d_depth,position.xy).x;

	gl_PointSize*=gl_PointSize;
gl_PointSize*=gl_PointSize;
//ff2=0.1;gl_PointSize=0.01;
gl_PointSize*=gl_PointSize*0.00065*ff2*0.5*3.0*1.0;
gl_PointSize=clamp (gl_PointSize,0.001,16.5);




if (ParticleMode==1) 
{ 

if (ff>0.2)
if (ff<0.4) 
{
//Color+=vec4 (1.0)*(1.0+0.2*sin(position.x+5.0*ttime));
Color+=3.0*texture2D(texture2d_1,position.xy)*(0.2+0.15*sin(gl_Vertex.x*22.0+2.0*ttime));

}
	if (ff>0.59)
	if (ff<0.60)
	{
gl_PointSize*=1.0;
Color=+vec4 (1.5);

	}
	if (ff>0.61)
{

gl_PointSize*=3.5;
Color+=texture2D(texture2d_1,position.xy);

}

}




gl_PointSize*=1.0*Screensize;
//+TheFlash;
//gl_PointSize=3.42;
}











