#include "inc/uniforms.glsl"
#include "inc/utils.glsl"
#line 3 1
uniform float p_luhistus;
uniform float p_luhistus_kirkkaus;
#ifdef VERTEX
#line 1 4
#include "inc/geometry_io.vs"



vec3 getPosition(float t){
	float t2=t*20.;
	t2+=(0.01*sin(p_time)+(p_time-225.)*3./4.)*0.2;//speed
	float dist=20.+sin(t2*1.3)*5.;
	return vec3(sin(t2+(1.-t)*2.+sin(t2*2.)*0.6)*dist,0.,cos(t2+(1.-t)*2.+sin(t2*2.)*0.7)*dist)//around
		+ vec3(0.,t2*2.+cos(t2)*18+cos(t2*3.5)*5,0.)//forward
		+ vec3(sin(t2*2.3),sin(t2*1.32),sin(t2*3.6754))*(1.-t)*p_luhistus*p_luhistus*10.//tail movement
	;
}

#line 10 1
void process() 
{
	ex_Position = (modelView)*in_Position;
	vec4 pos = in_Position;
	//pos.xyz += in_Normal.xyz*sqrt(p_luhistus)*.1*cos(6.0*(p_beat+in_Normal.x+in_Normal.y+in_Normal.z))*clamp(6.0-p_luhistus, .0, 1.0);
	//pos.y += in_Normal.y*clamp(p_luhistus-5.0, .0, 1.0);
	pos.xyz +=getPosition(in_Position.x*0.022)*0.1*max(0.,p_luhistus+in_Position.z*0.2-0.35  );
	gl_Position = (modelViewProject)*pos;
}

#define PROCESSING_FUNCTION process
#line 1 5
#include "inc/geometry.vs"

#endif


#ifdef FRAGMENT
#line 1 6
#include "inc/geometry_io.fs"
#line 1 7
#define pi (3.141592653589)
uniform vec4 diffuseColor;
uniform vec4 specularColor;
uniform float colorBoost;
uniform float roughness;
uniform float metallic;
void main()
{
	vec3 V = normalize(-ex_Position.xyz);
	vec3 N = ex_Normal.xyz; // viewspace normal
	#include "inc/cooktorrance.inc"
	
	if (sampld.a <= ALPHA_TEST_THRESHOLD) {
		discard;
	}
	
	out_Color = vec4((final.rgb*(1.+p_luhistus_kirkkaus)+0.1*p_luhistus_kirkkaus*p_luhistus_kirkkaus*(0.2+0.1*sin(length(ex_Position)+p_time))), 1.0);
}

#endif
