#version 150 compatibility

// vertex shader for map rendering

uniform int UndergroundMode;
uniform vec2 u_resolution;  // Canvas size (width,height)
uniform vec2 u_mouse;       // mouse position in screen pixels
uniform float u_time;       // Time in seconds since load

uniform mat4 view_matrix;
uniform mat4 model_matrix;
uniform vec3 PlayerPosition;
uniform vec3 CameraVector;

uniform mat4 uMVMat;
uniform mat4 uProjMat;
varying vec3 vPos;

in vec4 vVertex;
in vec3 vNormal;

attribute vec2 a_texcoord;
varying vec2 v_texcoord;
varying vec4 VertexColor;
varying vec3 vertexcoords; // needed
varying vec3 Playercheckcoords;
varying vec3 normcoords;

void main() {
	
	/*
	gl_Vertex	Position (vec4)
	gl_Normal	Normal (vec4)
	gl_Color	Primary color of vertex (vec4)
	
	gl_MultiTexCoord0	Texture coordinate of texture unit 0 (vec4)
	gl_MultiTexCoord1	Texture coordinate of texture unit 1 (vec4)
	gl_MultiTexCoord2	Texture coordinate of texture unit 2 (vec4)
	gl_MultiTexCoord3	Texture coordinate of texture unit 3 (vec4)
	gl_MultiTexCoord4	Texture coordinate of texture unit 4 (vec4)
	gl_MultiTexCoord5	Texture coordinate of texture unit 5 (vec4)
	gl_MultiTexCoord6	Texture coordinate of texture unit 6 (vec4)
	gl_MultiTexCoord7	Texture coordinate of texture unit 7 (vec4)
	
	gl_FogCoord	Fog Coord (float)
	
	// gl_ModelViewProjectionMatrix = modelview + projection matrix
	
	uniform mat4 gl_ModelViewMatrix;
	uniform mat4 gl_ProjectionMatrix;
	uniform mat4 gl_ModelViewProjectionMatrix;
	uniform mat4 gl_TextureMatrix[gl_MaxTextureCoords];
	uniform mat3 gl_NormalMatrix; // transpose of the inverse of the
	// upper left 3x3 matrix of gl_ModelViewMatrix
	uniform mat4 gl_ModelViewMatrixInverse;
	uniform mat4 gl_ProjectionMatrixInverse;
	uniform mat4 gl_ModelViewProjectionMatrixInverse;
	uniform mat4 gl_TextureMatrixInverse[gl_MaxTextureCoords];
	uniform mat4 gl_ModelViewMatrixTranspose;
	uniform mat4 gl_ProjectionMatrixTranspose;
	uniform mat4 gl_ModelViewProjectionMatrixTranspose;
	uniform mat4 gl_TextureMatrixTranspose[gl_MaxTextureCoords];
	uniform mat4 gl_ModelViewMatrixInverseTranspose;
	uniform mat4 gl_ProjectionMatrixInverseTranspose;
	uniform mat4 gl_ModelViewProjectionMatrixInverseTranspose;
	uniform mat4 gl_TextureMatrixInverseTranspose[gl_MaxTextureCoords];
	
	*/
	
	gl_TexCoord[0] = gl_MultiTexCoord0;
	
	// https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.1.10.pdf
	// 
	
	gl_Position = ftransform(); // equivalent to: gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex
	
	Playercheckcoords = PlayerPosition; // pass to fragment shader
	vertexcoords = gl_Vertex.xyz; // untransformed vertex in world space, so we can make proximity checks
	
	v_texcoord = a_texcoord;
	VertexColor = gl_Color;
	
}
