//varying vec4 ViewPos;
varying vec3 normal;
varying vec3 tangent;
varying vec3 binormal;
varying vec3 WorldNormal;
varying float pos;

varying vec3 Nscreen;

void main()
{
  // world pos
  vec3 WorldPosition = 0.01 * gl_Vertex.xyz;
  WorldNormal = gl_Normal;

  Nscreen = abs( normalize(WorldNormal).xyz ); 
  Nscreen = ( Nscreen - .2 ) * 7.0;
  Nscreen = max( Nscreen, 0.0 );
  Nscreen = Nscreen / ( Nscreen.x + Nscreen.y + Nscreen.z );

  // position
  //ViewPos = gl_ModelViewMatrix * gl_Vertex;
  pos = length((gl_ModelViewMatrix * gl_Vertex).xyz);
//*
  // normal and tangent basis
  normal   = normalize(gl_NormalMatrix * gl_Normal);
  tangent  = normalize(gl_NormalMatrix * gl_MultiTexCoord1.xyz);
  binormal = normalize(gl_NormalMatrix * gl_MultiTexCoord2.xyz);
//*/
/*
  // normal
  normal = normalize( gl_NormalMatrix * gl_Normal );
  // calc t and b from n
	vec3 c1 = cross(gl_Normal, vec3(0.0, 0.0, 1.0)); 
	vec3 c2 = cross(gl_Normal, vec3(0.0, 1.0, 0.0)); 
	
	if(length(c1)>length(c2))
	{
		tangent = c1;	
	}
	else
	{
		tangent = c2;	
	}
	
	tangent = normalize(tangent);
	binormal = cross(gl_Normal, tangent); 
	binormal = normalize(binormal);

  tangent  = gl_NormalMatrix * tangent;
  binormal = gl_NormalMatrix * binormal;
  // end t and b calc
//*/
  // set texture coords
  gl_TexCoord[0].xyz = 1.91 * WorldPosition.yzx; gl_TexCoord[0].w = 1.0;
  gl_TexCoord[1].xyz = 1.91 * WorldPosition.xzy; gl_TexCoord[1].w = 1.0;
  gl_TexCoord[2].xyz = 1.91 * WorldPosition.yxz; gl_TexCoord[2].w = 1.0;
  
  // transform position
  gl_Position = ftransform();
}