#version 330

layout( location = 0 ) in vec3 InVertex;

out vec2 vTexCoords;

out vec3 vWorldPos;

uniform mat4 uViewMatrix;
uniform mat4 uProjectionMatrix;
uniform mat4 uModelMatrix;
uniform float uRadius;

void main()
{
	float domeHeight = max( 0.0, ( InVertex.y / uRadius ) );
	vec2 normalizedPos = ( InVertex.xz / uRadius ) / domeHeight / 2.0;
	//vec2 normalizedPos = ( InVertex.xz / uRadius ) * ( 1.0 - domeHeight + 0.5 );
	vTexCoords = ( ( normalizedPos * 0.5 + 0.5 ) );
	
	vWorldPos = vec3( ( uModelMatrix ) * vec4( InVertex, 1.0 ) );
	
	/*
	vec3 cameraPos = uCameraPosition;//-vec3( ( uViewMatrix * uModelMatrix ) * vec4( InVertex, 1.0 ) );
	float cameraDist = length( cameraPos ) / 100;
	vec3 sunDirection = normalize( uSunPosition - vertexPos );
	vec3 normal = normalize( -vertexPos );
	float theta = acos( dot( normalize( vertexPos - cameraPos ), sunDirection ) );
	
	vec3 expTerm = exp( -( uTotalRayleigh + uTotalMie ) * cameraDist );
	vExtinction = expTerm;
	
	float scatNum = Rayleigh( theta ) * 4.0 + Mie( theta, 0.75 ) * 0.053;
	vec3 scatDenom = uTotalRayleigh + uTotalMie;
	vInScattering = ( scatNum / scatDenom ) * cSun * ( 1.0 - expTerm );
	*/
	
	gl_Position = uProjectionMatrix * uViewMatrix * uModelMatrix * vec4( InVertex, 1.0 );
}