// Vertex Shader for Worldpos Rendering

uniform mat4 mViewMatrix;
uniform mat4 mProjectionMatrix;
uniform vec3 mExtends;
uniform float mLayer;
uniform float mGlyphSize;
uniform float mDistance;
uniform float mOverallScaleFactor;
uniform float mScalingParam;
uniform float mMaxDataValue;
uniform float mMinDataValue;
uniform float mScaleProperty;

//uniform float mNumTriplets;

void main()
{
	vec4 vertex = gl_Vertex;
	//vertex.z = -mLayer/10.0;
	mat4 viewProjection =  mProjectionMatrix * mViewMatrix;
	gl_Position = viewProjection * vertex;

	gl_TexCoord[0] = gl_MultiTexCoord0;
	gl_TexCoord[1] = gl_MultiTexCoord1;
	
	float PI = radians( 180.0 );
	float angle =  atan(gl_MultiTexCoord0.y , gl_MultiTexCoord0.x);

	float xrot = cos(angle+PI/2.0);
	float yrot = sin(angle+PI/2.0);

	float signumx = ( gl_MultiTexCoord0.x < 0.0 ) ? 0.0 : 1.0;
	float signumy = ( gl_MultiTexCoord0.y < 0.0 ) ? 0.0 : 1.0;

	gl_TexCoord[2] = vec4(xrot, yrot, signumx, signumy);

	float multfactor = 1.0f;//sqrt(  min( mExtends.x, mExtends.y ) );
	//gl_PointSize = length(mExtends / 2.0) * length(gl_MultiTexCoord0);
	
	float scaleproperty = 
		( mScaleProperty > 1.0 ) 
		? 	( ( mScaleProperty > 2.0 )? gl_MultiTexCoord1.x : gl_MultiTexCoord0.y ) 
		:	length(gl_MultiTexCoord0);

	float difference = mMaxDataValue - mMinDataValue;
	difference = (difference < 1.0) ? 0.1 / difference : difference;
	float scalef = 0.7 + 1.3 * ( scaleproperty - mMinDataValue ) / ( difference ); 

	float isscaling = ( mScalingParam ) ? scalef : 1.0;
	gl_PointSize = (80.0 / ( mDistance * mOverallScaleFactor ) * mGlyphSize ) * isscaling;
}