    #version 120 
    #extension GL_EXT_bindable_uniform : enable 
    #extension GL_EXT_gpu_shader4 : enable 
#define tex2D texture2D
uniform mat4 ProjectionMatrix;


varying vec3 normal;
uniform float PosY;
uniform float ttime;
uniform float randomize;
				
uniform sampler1D texture1d_pos;
varying vec4 projection_position;
uniform sampler2D texture2d_1;
varying vec4 ShadowPosZ;
varying vec4 Color;
varying vec2 UVcoordinates;

varying vec4 projection_from_camera;
varying vec4 TheGoodPosition;
	uniform float ReflectPass;
varying vec3 normalB;
uniform float isFace;
uniform float smallFaceY;
uniform float issmallFace;
void main()
{
mat4 Billboard;


TheGoodPosition=gl_Vertex.xyzz;



float sFaceY=0.0;
//smallFaceY;



if (issmallFace>0.5) { 
float height=tex2D(texture2d_1,gl_Vertex.xy*0.0110+vec2 (ttime*0.005)).x;
height*=height;
float f1=0.25-8.0*height;

sFaceY=f1+(0.0-f1)*smallFaceY;
}





vec4 glVertex= gl_Vertex+vec4(0.0,0.0,sFaceY,0.0);
vec2 TheUV;









//if (ttime<0.0) 
if (isFace<0.5)
{ 

float Ttheta=0.28-0.05*(glVertex.y-9.2+5.0);

if (glVertex.y<8.7) Ttheta+=0.7;
Ttheta=clamp (Ttheta,0.0,1.9);
float rrr=Ttheta;
//Ttheta=0.0;


float snn=sin(ttime*1.5);



if (snn<0.0)
snn=clamp (snn*0.7,-1.0,1.0);
else
snn=clamp (snn,-1.0,1.0);

snn*=snn;
float snn2=0.75+0.25*sin (ttime*1.1);

Ttheta*=(snn*0.5)*1.27*1.1*snn2;
//Ttheta*=Ttheta*PosY;



rrr=0.28-0.15*(glVertex.y-9.2+5.0+PosY);
 snn=sin(-ttime*3.0+glVertex.y*0.2+glVertex.x*0.5*clamp (glVertex.y*0.1,0.0,1.0)*1.2);
snn=clamp (snn,-1.0,1.0);
Ttheta+=(snn*0.5)*0.06*1.2;


vec3 TPos=glVertex.xyz;
vec3 TP=TPos.xyz; 

TP.y-=9.2;
vec3 UpZ=vec3 (0.0,TP.y,0.0);
vec3 UpY=vec3 (0.0,0.0,TP.z);
 


float Tth1=cos (Ttheta);
float Tth2=-sin (Ttheta);
float Tth3=sin (Ttheta);  
float Tth4=cos (Ttheta);

vec3 NUpY;

NUpY.y=Tth1*TP.y+Tth2*TP.z;
NUpY.z=Tth3*TP.y+Tth4*TP.z;
NUpY.x=TPos.x;

vec3 NewPos=NUpY;
//NewPos=TPos;

NewPos.y+=9.2;

glVertex.xyz=NewPos;
}


glVertex= gl_TextureMatrix[0] * glVertex;







//fd=0.0;
//fd=fd+8.0*sin(-PosY+fd*0.95);


/*
if (fd<17.0)
if (fd>1.0) { 
fd-=ScaleDown*2.0;
fd=clamp (fd,0.05,1.0);

glVertex.y*=fd*1.0;
//glVertex.y-=fd*11.8;
}
*/

//if (fd<17.0)
//if (glVertex.y>0.0)

///}


// scale / vectorize normals

///	vec3 normalB=normalize (gl_Normal);
///float nx=normalB.x; float ny=normalB.y; float nz=normalB.z;
///for (int r=0;r<4;r++) { 
///if (nx>0.0) nx=nx*nx; else nx=-nx*nx;
///if (ny>0.0) ny=ny*ny; else ny=-ny*ny;
///if (nz>0.0) nz=nz*nz; else nz=-nz*nz ;
///}
///normalB=vec3 (nx,ny,nz);





projection_position=glVertex;
gl_Position =  glVertex;


// texture coordinates
UVcoordinates=gl_Position.xz*0.2;



normalB=gl_Normal.xyz;

	vec3 Tnormal=normalize (gl_Normal);
Tnormal=abs (Tnormal);
UVcoordinates=gl_Vertex.zx*0.31;

if ((Tnormal.x>Tnormal.y) && (Tnormal.x>Tnormal.z)) {
	{
		UVcoordinates=gl_Vertex.zy*0.31;
	}

	
	
	}
	if ((Tnormal.y>Tnormal.z) && (Tnormal.y>Tnormal.x)) UVcoordinates=gl_Vertex.zx*0.31;
if ((Tnormal.z>Tnormal.x) && (Tnormal.z>Tnormal.y)) UVcoordinates=gl_Vertex.xy*0.31;


UVcoordinates*=5.5;


		//UVcoordinates=gl_Vertex.zy*1.31;

//UVcoordinates=gl_Position.xy*0.21;


///UVcoordinates = vec2(gl_MultiTexCoord0);

// discretize vertices
///{ 
//gl_Position.y=float (int (1.7*gl_Position.y))/1.7+gl_Position.y*0.001;
//gl_Position.z=float (int (1.7*gl_Position.z))/1.7+gl_Position.z*0.001;
//gl_Position.x=float (int (1.7*gl_Position.x))/1.7+gl_Position.x*0.001;
///}



// final projection
gl_Position = gl_ModelViewProjectionMatrix * gl_Position;
projection_from_camera=gl_Position;



// instancing
///gl_Position.y+=1.0*gl_InstanceID;

// vertex instancing
///if (gl_VertexID==244) gl_Position.y+=1.0;



// Transforming The Normal To ModelView-Space
normal = gl_NormalMatrix *  gl_Normal; 
//ormal.z*=-1.0;
// color pass
Color=gl_Color;


ShadowPosZ= ProjectionMatrix *glVertex;
ShadowPosZ=gl_TextureMatrix[2]*glVertex;

// point size
///gl_PointSize =120.0/gl_Position.w;
}











