// Vertex Shader for Worldpos Rendering

uniform mat4 mViewMatrix;
uniform mat4 mProjectionMatrix;
uniform mat4 mVertexToTexture;
uniform vec3 mExtends;

void main()
{
	mat4 viewProjection =  mProjectionMatrix * mViewMatrix;
	vec4 pos = gl_Vertex;
	//pos.z = -0.02;
	gl_Position = viewProjection * pos;
	//vec4 trans = viewProjection * gl_Vertex;
	//gl_Position = trans + vec4(0.0, 0.0, -0.2, 0.0);
	//gl_Position = gl_Vertex;
	
	vec2 lookuppos = (mVertexToTexture * (gl_Vertex)).xy;
	lookuppos = lookuppos * 0.5 + vec2(0.5, 0.5);
	//lookuppos.x = 1.0f - lookuppos.x;

	vec2 offset = gl_MultiTexCoord0.xy / mExtends.xy;

	gl_TexCoord[0] = vec4(lookuppos - offset, 0.0, 0.0);
	gl_TexCoord[1] = gl_MultiTexCoord1;
	gl_FrontColor = gl_Color;
}