    #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 ScaleDown;
uniform float ttime;
uniform float randomize;


varying vec4 projection_position;

varying vec4 ShadowPosZ;
varying vec4 Color;
uniform sampler2D texture2d_1;
varying vec2 UVcoordinates;

varying vec4 projection_from_camera;
varying vec4 TheGoodPosition;

void main()
{
mat4 Billboard;


TheGoodPosition=gl_Vertex.xyzz;
vec4 glVertex= gl_Vertex;
vec2 TheUV;





//glVertex.z*=1110.3;
// Object transf
glVertex= gl_TextureMatrix[0] * glVertex;




float fd=length (glVertex.xz)*0.2;
//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)
if (fd>1.0) { 
fd=abs (glVertex.z);
//fd=1.0;
fd=cos(fd*0.003);
//fd*=ScaleDown*2.0;
//float factscale=0.001*abs (glVertex.z);
//factscale=sin(factscale);
//fd=1.0-clamp (0.01*ScaleDown+factscale,0.0,1.0)*fd*8.0;
float verty=glVertex.y;
verty=clamp (verty,-15.0,10000.0);
fd=fd+ScaleDown-0.15*verty;


fd=clamp (fd,0.185,1.0);


	glVertex.x*=fd;

}




{

float fd=length (glVertex.xz)*0.11-2.0;
float fe=0.0;
if (ttime>3.0)
{
	fe=(ttime-3.0-1.0*length (glVertex.xz))*0.35;
	fe=1-fe;
	fe=clamp (fe,0.0,1.0);
}
float fe2=1.0-clamp ((ttime-4.0)*0.8,0.0,1.0);

fe*=fe*fe2;


if (length(glVertex.xz)>4.76)
glVertex.y*=1.0+fe*0.23*sin(-ttime*5.0+fd);

}


///}


// 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;






	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*=0.5;
	//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;
}











