    #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 isReflective;
	uniform float isHappiness;
uniform float isHappinessWhere;
	uniform float ReflectPass;
varying vec3 normalB;


uniform float isBigTree;
uniform float BigTreeMovement;

uniform float isLeaf;

varying float Leaf;

void main()
{
mat4 Billboard;


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

Leaf=1.0;



//glVertex.z*=1110.3;
// Object transf


if (isLeaf>0.5) { 

glVertex.y+=0.14*sin(1.2*ttime+glVertex.x*2.5);
glVertex.x+=0.14*sin(1.1*ttime+glVertex.y*1.5);

};


if (BigTreeMovement>0.5) 
if (BigTreeMovement<1.5) 
{ 
float PosY2=(ttime-79.1+1.6333+1.246-0.06)*0.4;
PosY2=clamp (PosY2,0.0,11.0);

float Poss=(ttime-79.7)*0.7;
Poss=clamp (Poss,0.0,1.0)*0.1;

float ff=length(gl_Vertex.zx);
	float ffup=(1.0*PosY2)-(gl_Vertex.y*0.15+ff*0.2);
//ffup=PosY;
ffup=clamp (ffup,0.0,1.0);
glVertex.y*=ffup;

 ffup=(1.0*PosY2-0.25)-(gl_Vertex.y*0.23+ff*0.2);
ffup=clamp (ffup,0.0,1.0);

glVertex.z*=ffup;
glVertex.x*=ffup;
glVertex.y+=-3.0*0.1;
glVertex.x+=0.09+0.28*0.1+2.0*0.02-3.5*0.02;
glVertex.z+=0.01*5.2-0.77*0.1;
glVertex.x+=0.7*Poss;
//glVertex.x
}

if (BigTreeMovement>1.5) 
{ 
float PosY2=(ttime-83.0+1.6333+1.446+0.8)*(0.28);
//-0.04*tex2D (texture2d_1,glVertex.xz*0.02).x);
PosY2=clamp (PosY2,0.0,11.0);
//Leaf=PosY2*0.2;
//clamp (Leaf,0.0,1.0);
Leaf=(ttime-83.2)*0.2;
Leaf=clamp (Leaf,0.0,1.0);
Leaf=-1.0+2.0*Leaf;
float ff=length(gl_Vertex.zx);
	float ffup=(1.0*PosY2)-(gl_Vertex.y*0.15+gl_Vertex.z*0.11+ff*0.03);
	
	//ffup=PosY;
ffup=clamp (ffup,0.0,1.0);
ffup=1.0-ffup;
ffup*=ffup;
ffup=1.0-ffup;

glVertex.y-=(1.0-ffup)*9.0;

 ffup=(1.0*PosY2-0.25)-(gl_Vertex.y*0.2+ff*0.2);
ffup=clamp (ffup,0.0,1.0);


glVertex.x+=0.09;
glVertex.z+=0.01*5.2;

glVertex.x+=0.2*sin(ttime*1.5+2.0*gl_Vertex.y+1.0*gl_Vertex.x)*(1.0-Leaf);
glVertex.z+=0.2*cos(ttime*1.3+1.0*gl_Vertex.y+1.0*gl_Vertex.z)*(1.0-Leaf);
}




glVertex= gl_TextureMatrix[0] * glVertex;







if (isReflective<0.5) { 
float ffup=(-1.3+4.0*PosY*1.0)+(gl_Vertex.z)*2.202;
ffup=clamp (ffup,0.0,1.0);
vec2 TheUV1=gl_Vertex.xz*0.016*vec2 (1.0,5.0)+0.001*vec2 (ttime);

//float displacement=clamp ((ffup*(tex2D (texture2d_1,TheUV1).x-0.44)*3.2),-1.0,1.0);
//displacement=displacement+(1.0-displacement)*ffup;

//glVertex.y-=0.051;
//glVertex.y*=displacement;


//glVertex.y+=0.051;
//glVertex.y-=(1.0-displacement)*0.05;

//if (glVertex.y<0.051) glVertex.y=+100.0;

/*
if (glVertex.y>-0.1)
if (ReflectPass>0.5)
glVertex.y=-100.0;
*/

float fd=length (glVertex.xz)*0.2;

//if (glVertex.y<0.1) glVertex.y=-1000.0;
}
//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;
}











