 
 // geometry shader 
 
-layout (lines_adjacency) in;
+layout (points) in;
 layout (triangle_strip, max_vertices = 4) out;
 
 
+uniform mat4 mView;
+uniform mat4 mProj;
+
+in Vertex {
+  vec3 pos;
+} vertex[];
+
 void main() {
-	gl_Position = gl_in[0].gl_Position;
+
+	float size = 7;
+
+	vec3 right = vec3(mView[0][0], mView[1][0], mView[2][0]);
+	vec3 up = vec3(mView[0][1], mView[1][1], mView[2][1]);
+
+	vec3 center = gl_in[0].gl_Position.xyz;
+	
+	gl_Position = mProj * vec4((center + (right - up) * size).xyz, 1.0);
 	EmitVertex();
 
-	gl_Position = gl_in[1].gl_Position;
+	gl_Position = mProj * vec4((center + (right + up) * size).xyz, 1.0);
 	EmitVertex();
-	
-	gl_Position = gl_in[2].gl_Position;
+
+	gl_Position = mProj * vec4((center - (right - up) * size).xyz, 1.0);
 	EmitVertex();
-	
-	gl_Position = gl_in[3].gl_Position;
+
+	gl_Position = mProj * vec4((center - (right + up) * size).xyz, 1.0);
 	EmitVertex();
-	
+
 	EndPrimitive(); 
 }
 

out float vs_t;




void main() {
	// y is the curve parameter
	float t = vs_t = pos_tex_in.y; 
	float omt = 1 - t;
	
	// x is 1 for the top corner, 2 for the bottom corner
	// the sign of x indicates which side this vertex is for
	float hwidth = sign(pos_tex_in.x);
	float voffset = abs(pos_tex_in.x) > 1.5 ? -1.0 : 0.0; 
	
	const vec2 cp0 = cp02_in.xy;
	const vec2 cp1 = cp1_in;
	const vec2 cp2 = cp02_in.zw;
	
	// this is the actual vertex location
	vec4 spline = vec4(
		quad_bezier(cp0.x, cp1.x, cp2.x, t, omt),
		quad_bezier(cp0.y, cp1.y, cp2.y, t, omt),
		0, 1);
		
	// tangent vector of the curve
	vec2 sdt = normalize(vec2(
		quad_bezier_dt(cp0.x, cp1.x, cp2.x, t, omt),
		quad_bezier_dt(cp0.y, cp1.y, cp2.y, t, omt)));
	
	// normal vector from the curve
	sdt = sdt.yx;
	sdt.x *= -0.5;
	
	sdt.x *= hwidth * 2;
	sdt.y *= hwidth * 2;
	
	vec4 pos = (spline + vec4(sdt.xy, 0, 1));
	
	pos.z = texture(sHeightMap, vec3(pos.x/256, pos.y/256, 0) , 0).r + (voffset * 4) + 2;
	//pos.z = (voffset * 3) + 200;
	//spline.x += hwidth;

//	gl_Position = (mProj * mView * mModel) * vec4(pos_tex_in.xy, 0, 1);
	gl_Position = (mProj * mView * mModel) * pos;
	vs_norm =  normalize(vec4(1,1,1,0));
	vs_tex = pos_tex_in.zw;
	vs_cp0 = cp0;
	vs_cp1 = cp1;
	vs_cp2 = cp2;
}




#version 430 core



uniform mat4 mModel;
uniform mat4 mView;
