//uniform sampler2D noiseMap;

uniform float texW;
uniform float texH;

uniform vec4 trans;
uniform vec4 scale;

uniform vec4 camPos;

//
varying vec2 tc;

//varying float vertex_height;

varying vec3 worldpos_vert;

varying vec4 eyedir;

varying vec4 shadow_tex_coord;

void main() 
{

  //
  tc = gl_Vertex.xz;



  vec4 transformed_vertex = (gl_Vertex+trans)*scale;

       //shallow water => 0.75 scale
transformed_vertex.y *= 0.75;


  //  vertex_height = (gl_Vertex.y+trans.y)*scale.y;
  //  vertex_height = transformed_vertex.y;
  worldpos_vert.y = transformed_vertex.y;
  worldpos_vert.xz = transformed_vertex.xz;

  //  vec4 sm_tc_prep = gl_ModelViewMatrixInverse * gl_TextureMatrix[2] * transformed_vertex;
  //  vec4 sm_tc_prep = gl_TextureMatrix[2] * transformed_vertex;

  /*
  //COLUMN MAJOR!!!  
  mat4 bias_mat = mat4(0.5, 0.0, 0.0, 0.0,
		       0.0, 0.5, 0.0, 0.0,
		       0.0, 0.0, 0.5, 0.0,
		       0.5, 0.5, 0.5, 1.0);
  
  vec4 sm_tc_prep = bias_mat * gl_TextureMatrix[2] * gl_Vertex; //ORIG
  */
  //  vec4 sm_tc_prep = gl_TextureMatrix[2] * gl_Vertex; //ORIG
  //  vec4 sm_tc_prep = gl_TextureMatrix[2] * vec4(gl_Vertex.x, gl_Vertex.y*0.75, gl_Vertex.zw); //MOD
  vec4 sm_tc_prep = gl_TextureMatrix[2] * transformed_vertex;

  /*
  vec4 nv = gl_Vertex;
  //  vec4 nv = transformed_vertex;
  //  vec4 nv = vec4(gl_Vertex.x, gl_Vertex.y*.75, gl_Vertex.z, 1.0);
  vec4 sm_tc_prep = bias_mat * gl_TextureMatrix[2] * nv;
  //  vec4 sm_tc_prep = bias_mat * gl_TextureMatrix[2] * transformed_vertex;
  */

  //  vec4 sm_tc_prep = gl_TextureMatrix[2] * gl_Vertex;
  
  //  shadow_tex_coord = sm_tc_prep / sm_tc_prep.w; //ORIGINAL
  shadow_tex_coord = sm_tc_prep; //WORKS JUST AS WELL

  //  eyedir = gl_ModelViewMatrix * transformed_vertex;

  //  eyedir = camPos - transformed_vertex;
  ///  

    /*
       //shallow water => 0.75 scale
transformed_vertex.y *= 0.75;
    */
eyedir = -camPos + transformed_vertex;

    /**
       //shallow water => 0.75 scale
    eyedir = -camPos + vec4(transformed_vertex.x, transformed_vertex.y*0.75, transformed_vertex.z, 0.0);
    **/
  /*
  vec4 tmp_vert = vec4(gl_Vertex.xyz*vec3(1.0, 0.75, 1.0), 1.0);
eyedir = -camPos + (tmp_vert+trans)*scale;
  */
  /*
  vec4 tmp_vert = vec4(gl_Vertex.xyz/vec3(1.0, 0.75, 1.0), 1.0);
eyedir = -camPos + (tmp_vert+trans)*scale;
  */

  //  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

  //  gl_Position = gl_ModelViewProjectionMatrix * ((gl_Vertex+vec4(-0.5*texW/4.0, -10.0, -0.5*texH/4.0, 0.0))*vec4(30.0, 3.5, 30.0, 1.0));

  //  gl_Position = gl_ModelViewProjectionMatrix * ((gl_Vertex+vec4(-0.5*texW/4.0, -22.0, -0.5*texH/4.0, 0.0))*vec4(40.0, 3.5, 40.0, 1.0));
  //  gl_Position = gl_ModelViewProjectionMatrix * ((gl_Vertex+trans)*scale);

       //shallow water => 0.75 scale
//  transformed_vertex.y *= 0.75;

  gl_Position = gl_ModelViewProjectionMatrix * transformed_vertex;
  gl_ClipVertex = gl_ModelViewMatrix * transformed_vertex;

  //  gl_Position += (-.5+texture2D(noiseMap, tc.xy*vec2(16.0/texW, 16.0/texH)))*vec4(.5, .5, .5, 1.0);
  //  gl_Position = ftransform();
}
