uniform mat4 tmpMat; //cancels out the effect of the VIEW matrix (so only MODEL matrix remains active) ==> all in all transform the vertex to WORLDSPACE

uniform vec4 global_light_dir;

varying vec4 shadow_tex_coord;

varying vec3 normal, view, light;

float ComputeCameraDepth(vec4 worldSpacePos)
{
  vec4 viewPos = gl_ModelViewMatrix *  worldSpacePos;
  //
return viewPos.z;
  //return viewPos.w;
}


void main() 
{
  //  shadow_tex_coord = gl_TextureMatrix[2] * gl_Vertex;
  //  shadow_tex_coord = tmpMat * shadow_tex_coord;



  gl_FrontColor = gl_Color;
  //  gl_FrontColor = vec4(0.5, 0.5, 0.5, 1.0);

gl_TexCoord[0] = gl_MultiTexCoord0;

// Transformationen in das Kamerakoordinatensystem
vec3 eyeNormal = normalize(gl_NormalMatrix * gl_Normal);
vec4 eyeVertex = gl_ModelViewMatrix * gl_Vertex;
vec3 eyeView = -normalize(eyeVertex.xyz);

//  gl_TexCoord[4].q = ComputeCameraDepth(tmpMat * eyeVertex);
//  gl_TexCoord[4].q = ComputeCameraDepth(gl_Vertex);


 shadow_tex_coord = gl_TextureMatrix[2] * tmpMat * eyeVertex;

vec3 eyeLight =
  normalize(global_light_dir).xyz;
  //  gl_ModelViewMatrix * normalize(global_light_dir);
  //normalize(gl_LightSource[0].position.xyz - eyeVertex.xyz);
  ///  normalize(normalize((gl_ModelViewMatrix * global_light_dir).xyz) - eyeVertex.xyz);
  //normalize(normalize((gl_ModelViewMatrix * global_light_dir).xyz) - eyeView.xyz);
  //normalize(normalize((gl_ModelViewMatrix * global_light_dir).xyz) - eyeVertex.xyz);
  //  normalize(normalize(global_light_dir).xyz - (tmpMat * eyeVertex).xyz);
  //  normalize(-global_light_dir.xyz + normalize(gl_Vertex.xyz));

// eyeLight = gl_NormalMatrix * (-eyeLight);


//normal = eyeNormal;
  normal = normalize(tmpMat * vec4(normalize(gl_NormalMatrix * gl_Normal), 0.0)).xyz;
//view = eyeView;
  view = normalize(tmpMat * -normalize(gl_ModelViewMatrix * gl_Vertex)).xyz;
light = eyeLight;

  //
gl_Position = ftransform();
  //  gl_Position = gl_ModelViewProjectionMatrix * gl_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();

 gl_TexCoord[4].q = gl_Position.z;  
}
