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


varying vec4 normal;
varying vec4 normalB;
uniform float PosY;
uniform float ttime;

varying vec4 projection_position;

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

varying vec4 projection_from_camera;
varying float depth;
uniform float BigSea;
uniform float movement;
uniform sampler1D texture1d_pos;
varying float DiscFlag;


void main()
{
mat4 Billboard;



vec4 glVertex= gl_Vertex;
vec2 TheUV;


DiscFlag=0.0;


float gPos=(glVertex.x+12)/24.0;



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

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


if (gPos+movement>0.9) 
DiscFlag=1.0;


float ggPos=(gPos+movement)*10.0;
ggPos=clamp (ggPos,0.0,1.0);


float Ttheta=texture1D (texture1d_pos,gPos+movement).w;
float Tth1=cos (Ttheta);
float Tth2=-sin (Ttheta);
float Tth3=sin (Ttheta);
float Tth4=cos (Ttheta);

vec3 NUpY;
NUpY.x=Tth1*UpY.x+Tth2*UpY.y;
NUpY.y=Tth3*UpY.x+Tth4*UpY.y;
NUpY.z=0.0;

vec3 NUpZ;
NUpZ=UpZ;

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

glVertex.xyz=NewPos;










vec2 TheUV1=gl_Vertex.xy*0.53;




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



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


// vertex transformations
///{ 
//sin(PosY);
//2D (texture2d_1,TheUV1).x)*15.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);







	vec3 Tnormal=normalize (gl_Normal);
Tnormal=abs (Tnormal);




/*
float height=tex2D(texture2d_1,TheUV1).x;
height*=tex2D(texture2d_1,gl_Vertex.xz*0.0006+vec2 (-ttime*0.03,0.0)*0.06).x;
height*=tex2D(texture2d_1,gl_Vertex.xz*0.0007+vec2 (ttime*0.01,-ttime*0.02)*0.08).x;
height*=tex2D(texture2d_1,gl_Vertex.xz*0.001+vec2 (-ttime*0.02,ttime*0.01)*0.08).x;


if (glVertex.y<0.0)
glVertex.y+=height*13.0;
*/
vec3 glNormal;
glNormal=gl_Normal;
//glNormal.z+=height*10.0;
//glNormal=normalize (glNormal);



projection_position=glVertex;
gl_Position =  glVertex;


// texture coordinates
///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;
UVcoordinates=TheUV1;
projection_from_camera=gl_Position;

projection_from_camera/=gl_Position.w;

// 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 *  glNormal; 
//normal = gl_TextureMatrix[2]*




normal=   (gl_TextureMatrix[0]*gl_Normal.xyzz);
normal.xyz=   (gl_NormalMatrix*gl_Normal.xyz);
//normal=   (glgl_Normal.xyzz);
normalB = gl_Normal.xyzz;
// color pass
Color=gl_Color;


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


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











