
out vec2 uv;

uniform int potato;

mat4 get_view(vec3 ro, vec3 rd){
	vec3 dir = normalize(-cam_dir);
	vec3 right = normalize(cross(vec3(0,1,0), dir));
	vec3 up = normalize(cross(dir, right));

	mat4 m = mat4(1);

	m = mat4(
		1,0,0,0,
		0,1,0,0,
		0,0,1,0,
		-cam_pos.x,-cam_pos.y,-cam_pos.z,1
	);
//	m = transpose(m);
//	m[0][3] = -cam_pos.x;
//	m[1][3] = -cam_pos.y;
//	m[2][3] = -cam_pos.z;
//	m[3][3] = 1;

//	m = transpose(mat4(
//		vec4(right,0),
//		vec4(up,0),
//		vec4(dir,0),
//		vec4(0,0,0,1)
//	)) * m;
	m = V * m;

	return m;
}

void main(){
	vec2 verts[] = vec2[6](
		vec2(-1, -1.), vec2(1, -1.),
		vec2(-1, 1.), 
		vec2(-1, 1.), 
		vec2(1, -1.), vec2(1, 1.)
	);

	uv = verts[gl_VertexID];

	vec4 pos = vec4(uv,0.02,1);

	float t = T * 0.;
	t = T;
	t = 0.5;
//	t = 0.5;
	pos.xz *= rot(0.8 + t);
//	pos.xz *= rot(pi/2.0);
//	pos.z *= 10.5;
//	pos.y *= 0.1;
	if(potato == 2){
		pos.yz *= rot(0.8 + t*1.5);
	}

	mat4 v = get_view(cam_pos, cam_dir);
//	pos *= 0.0;
//	pos = V * pos;
//	pos.xyz = v * pos.xyz;
//	pos.xyz -= cam_pos*vec3(1.,1,-1.);

//	pos.xyz -= cam_pos*vec3(1.,1,1.);
//	pos = V * pos;
//	pos.xyz += cam_pos * vec3(1,1,1);
	pos = V * pos;
	pos.w = 1.0;
//	pos = transpose(V) * pos;
	pos = P * pos;

	gl_Position = pos;
}
