varying float 	h;
varying vec3	vPOS;
varying	vec3	cnormal;
//attribute vec3 	normal;	
//varying float	depth;
uniform float 	sunpower;
varying vec4	curpos,
				prev;
uniform mat4	prevMVM;

varying vec2	cloudsTexcoords,
				cloudsTexcoords2,
				cloudsTexcoords3,
				cloudsTexcoords4,
				cloudsTexcoords5;
varying vec2	texcoords;
varying vec2	moonTexcoords;

uniform vec4	LTM0,
				LTM1,
				LTM3;
varying mat3	TBN;
attribute vec4	binormal; 
//varying float 	skydistance;
//varying vec2	depth;
varying vec3 	eyedir;
uniform vec2 	ofs;

uniform float 	skyDepth;

void main()
{
	/*vec4 vertex=gl_Vertex;
	vertex.xyz=normalize(gl_Vertex.xyz);//*vec3(skyDepth,skyDepth,skyDepth);//vec3(1000.0,1.0,1000.0) );
	//skydistance=length(vertex.xyz);
	//vertex.xyz*=500000.0;
	vertex.xyz*=vec3(1.0,0.0001,1.0);
	vec4 projPosition = gl_ModelViewProjectionMatrix*vertex;
	depth=projPosition.zw;
	*/
	gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;
	prev = gl_ProjectionMatrix*prevMVM*gl_Vertex;
	curpos = gl_Position;
	
	//skydistance=length(npos);
	vec3 npos=normalize( (gl_Vertex.xyz)*vec3(1.0,7.0,1.0) );
	
	h=clamp(1.1-npos.y,0.0,1.0);
	vPOS=gl_Vertex.xyz;
	cnormal.xyz=-gl_Vertex.xyz;
	texcoords=npos.xz * vec2(30.0,30.0);
	
	vec4 pos=gl_ModelViewMatrix*gl_Vertex;//vertex;
	vec4 XYproj;
	XYproj.x = dot(pos,LTM0);
	XYproj.y = dot(pos,LTM1);
	XYproj.w = dot(pos,LTM3);
	moonTexcoords.xy=(XYproj.xy/XYproj.w);
	
	cloudsTexcoords=gl_MultiTexCoord0.st+ofs;
	cloudsTexcoords2=(gl_MultiTexCoord0.st*vec2(2.0,2.0))+vec2(0.25,0.25);
	cloudsTexcoords3=(gl_MultiTexCoord0.st*vec2(0.5,0.5))+ofs+vec2(0.5,0.5);
	cloudsTexcoords4=gl_MultiTexCoord0.st+ofs*vec2(0.5);
	cloudsTexcoords5=(gl_MultiTexCoord0.st*vec2(0.5,0.5))+(ofs+vec2(0.5,0.5))*vec2(0.5);
	
	vec4 normal4      	= vec4( gl_Normal.xyz, 0.0 );
	vec4 binormal4      = vec4( binormal.xyz, 0.0 );
	vec4 tangent4      	= vec4(cross(binormal4.xyz,normal4.xyz),0.0);
	binormal4.xyz*=binormal.w;
	
	TBN[0]=tangent4.xyz;
	TBN[1]=binormal4.xyz;
	TBN[2]=normal4.xyz;
	
	eyedir=-pos.xyz;
	eyedir=normalize(eyedir);
}