
#version 330

varying vec4 Normal;
varying vec4 Position;
uniform float ID;
uniform float ttime;
uniform float _dat_x;

varying vec4 Color;
varying float fc0;

vec2 hash(vec2 p) {
	p = vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)));
	return -1.0 + 2.0*fract(sin(p)*43758.5453123);
}

void main () 
{





	float fdot = dot(vec3(0, 1, 0), Normal.xyz);
	fdot = clamp(fdot, 0.0, 1.0);


	vec4 MyColor = Color.xyzw;

	float fc;
	fc = 1.0;
	fc = fdot;
	fc = 0.5 + 0.5*sin(float(gl_PrimitiveID));
	fc = (gl_PrimitiveID%2);

	float ftc = sin(1.0*ttime + float(gl_PrimitiveID)*0.0026);
	ftc = pow(1.1*ftc, 12.0);
	ftc = 0.5 + 12.0*clamp(ftc, 0.0, 1.0);
	ftc = 1.0;
	//MyColor = vec4(0.5, 0.2, 1.0, 1);
	if (gl_PrimitiveID % 5 == 0)		MyColor = vec4(1.0, 0.3, 0.3, 1.0);
	if (gl_PrimitiveID % 4 == 0)		MyColor = vec4(0.2, 0.6, 1.0, 1.0);
	if (gl_PrimitiveID % 3 == 0)		MyColor = vec4(1.0, 1.0, 0.0, 1.0);

	//if (ttime>16.0) if (gl_PrimitiveID % 3 == 0)		MyColor = vec4(1.0, 1.0, 0.0, 1.0)*0.0;
	
	//vec4(1.0, 0.0, 0.0, 1.0);
	//MyColor = vec4(1.0, 1.0, 0.0, 1.0);

	
	float ffc = sin(gl_PrimitiveID+-100.0*float(ttime*0.15+Position.y+ Position.x));
	//ffc = 10000.0;
	//ffc = sin(Position.x * 100 + 10.0*ttime)*cos(Position.z* 100 + ttime);
	//-250.0*float(ttime*0.15 + Position.x + Position.y));

	//if (hash(Position.xy).x < sin(Position.x*10.0)) discard;
	
	
	//ffc = sin(20.0*float(Position.x));
	//sin((Position.y + Position.x)*200.0);
	if (ffc < -0.8)
		ffc = 0.0; else ffc = 1.0;
//	if (ffc < 0.1) discard;
	//MyColor = vec4(1.0);
	fc = 1.0;
	fc *= ffc*1.0;
	//MyColor.xyz = vec3(1.0)*ffc;
//	fc = 1.0;
	//fc *= fc0*100.0;
	// RGB albeido
	//gl_FragData[0].xyzw = Normal.xyzz;
	//gl_FragData[0].xyzw = vec4 (1.0)*fdot;
	
	gl_FragData[0].xyzw = Color*fc*ftc*MyColor;
	//if (length(gl_FragData[0].xyz) < 0.1) discard;
	//gl_FragData[0].xyzw = Color.xyzz;
	//*vec4(0.0, 1, 0.0, 0.0);;
	//Color.xyzw;
	
	
	
	
	
	
	
	
	//*_dat_x;
	//vec4(0.0);

gl_FragData[1].xyzw = vec4(0, 0.5, 1, 1);


}
