/*
 * render_mode
 * 0: ArrowPlot 1: StreamLine 2: ColorCoding
 */
uniform int render_mode;

uniform float arrow_min_size;
uniform float arrow_max_size;
uniform float arrow_scale_factor;

uniform float scale_factor_x;
uniform float scale_factor_y;

uniform sampler2D tex_channel0;
uniform sampler2D tex_channel1;
uniform sampler2D tex_channel2;

uniform float channel0_min;
uniform float channel0_max;
uniform float channel1_min;
uniform float channel1_max;
uniform float channel2_min;
uniform float channel2_max;

void main() {

	if (render_mode == 0 || render_mode == 1) {
		// Vertices are on a quad (-1.1) (1,1) (1,-1) (-1,-1)
		vec2 vPoint = vec2( (gl_Vertex.x / scale_factor_x + 1.0) / 2.0, (gl_Vertex.y / scale_factor_y + 1.0) / 2.0 );
		
		// calcualte point size depending on the magnitude
		float magnitude = texture2D(tex_channel2, vPoint.xy).x;
		float arrow_range = arrow_max_size - arrow_min_size;
		
		if (magnitude > 0.001)
			gl_PointSize = (magnitude * arrow_range + arrow_min_size) * arrow_scale_factor;
		else 
			gl_PointSize = 0.0;
		
		gl_TexCoord[1] = vec4(vPoint.x, vPoint.y, 0.0, 0.0);
	}
	
	gl_TexCoord[0] = gl_MultiTexCoord0;
	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
