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


varying vec3 normal;
varying vec4 normal2;
uniform float PosY;
uniform float ttime;
uniform float UVMultiplier;
uniform int IsBird;
varying vec4 projection_position;

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

varying vec4 projection_from_camera;


void main()
{
mat4 Billboard;



vec4 glVertex= gl_Vertex;
vec2 TheUV;








if (IsBird==1)
{
vec3 TPos=glVertex.xyz;

float Ttheta=(abs(glVertex.x)+0.00)*0.06;
Ttheta=clamp (Ttheta,0.0,1.0);
//Ttheta*=Ttheta;
float mult=1.0;
if (glVertex.x<0.0) mult=-1.0;

float Rot=1.0*sin(ttime*1.0)-0.0;
Ttheta*=Rot*mult;

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


vec3 NTPos;
NTPos.x=Tth1*TPos.x+Tth2*TPos.y;
NTPos.y=Tth3*TPos.x+Tth4*TPos.y;

glVertex.x=NTPos.x;
glVertex.y=NTPos.y;

}







// Object transf
projection_position=glVertex;
glVertex= gl_TextureMatrix[0] * glVertex;
//glVertex= gl_TextureMatrix[0] * glVertex;
//glVertex=  glVertex;



// interpolant based on vertex
///float ffup=PosY-(gl_Vertex.y)*0.1;
///ffup=clamp (ffup,0.0,1.0);













// vertex transformations
///{ 
{
	vec2 TheUV1=gl_Vertex.xz*0.5;
	//+vec2 (PosY)*PosY*0.0001;
float cll=PosY-0.2*glVertex.x;
cll=clamp (cll,0.0,11.0);
float pw=(tex2D (texture2d_1,TheUV1.ss).x-0.21);

pw*=7.0;
//glVertex.xyz+=cll*abs(pw)*gl_Normal.xyz;
//glVertex.y+=cll*(pw*pw);
//*abs(gl_Normal.y);
//glVertex.z*=0.1;
}

///}


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





gl_Position =  glVertex;


// texture coordinates
UVcoordinates=gl_Position.xz*0.2+gl_Normal.xy;
///UVcoordinates = vec2(gl_MultiTexCoord0);

// discretize vertices
///{ 




	vec3 Tnormal=normalize (gl_Normal);
Tnormal=abs (Tnormal);
vec2 TheUV1=gl_Vertex.zy*0.1;

if ((Tnormal.x>Tnormal.y) && (Tnormal.x>Tnormal.z)) {
	TheUV1=gl_Vertex.zy*0.11;
}
	if ((Tnormal.y>Tnormal.z) && (Tnormal.y>Tnormal.x)) TheUV1=gl_Vertex.zx*0.11;
if ((Tnormal.z>Tnormal.x) && (Tnormal.z>Tnormal.y)) TheUV1=gl_Vertex.xy*0.11;

UVcoordinates=TheUV1*1.12*UVMultiplier+vec2(UVMultiplier);
//UVcoordinates=TheUV1*1.12;
//*UVMultiplier+UVMultiplier.xx;





float ffc=1.0;
//+gl_Position.x*PosY;
//if (gl_Position.x*0.3<PosY) ffc=100.0; else ffc=1.5;
//if (gl_Position.x*0.3>PosY) gl_Position.xyz*=1.1;

/*
ffc=0.7;
gl_Position.y=float (int (ffc*gl_Position.y))/ffc+gl_Position.y*0.01;
gl_Position.z=float (int (ffc*gl_Position.z))/ffc+gl_Position.z*0.01;
gl_Position.x=float (int (ffc*gl_Position.x))/ffc+gl_Position.x*0.01;
*/
//gl_Position.y*=0.07;





/*
float fff=PosY-length (gl_Position);
fff=clamp (fff,0.0,1.0);
fff=1.0;
gl_Position.xyz=vec3 (0.0)+(gl_Position.xyz-vec3 (0.0))*fff;

*/







/*

vec3 TPos=gl_Position.xyz;
vec3 TP=TPos.xyz; 

vec3 UpZ=vec3 (TP.x,0.0,0.0);
vec3 UpY=vec3 (0.0,TP.y,0.0);


float Ttheta=-clamp (PosY-TP.x*0.25,0.0,1113.0);
float Tth1=cos (Ttheta);
float Tth2=-sin (Ttheta);
float Tth3=sin (Ttheta);
float Tth4=cos (Ttheta);

vec3 NUpY;
NUpY.x=Tth1*TP.x+Tth2*TP.y;
NUpY.y=Tth3*TP.x+Tth4*TP.y;
*/

//vec3 NewPos=UpZ*ggPos*1.0+NUpY*ggPos*1.0;
//NewPos+=texture1D (texture1d_pos,gPos+movement).xyz*1.0;

//gl_Position.xy=NUpY.xy;
//gl_Position.z=0.0;



//gl_Position= (gl_TextureMatrixInverse[0]) * gl_Position;


// 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_Normal; 
//normal = gl_NormalMatrix *  gl_Normal; 
normal2= gl_ModelViewProjectionMatrix*gl_TextureMatrix[0]*gl_Normal.xyzz;


// color pass


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

Color=gl_Color;

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











