#include "GLSL.hpp" //GLSL vectors, matrices, operators and functions
//Function breaks an edge onto two by inserting an extra point inbetween the
//specified corner points
void TessellateEdge(const vec3& Va, const vec3& Na,
const vec3& Vb, const vec3& Nb,
vec3* Vm, vec3* Nm){
//Calculate tangents
vec3 Ta = Vb-Va-Na*dot((Vb-Va),Na),
Tb = Va-Vb-Nb*dot((Va-Vb),Nb),
Tm = 0.5*(Vb-Va)+0.25*(Tb-Ta);
//Calculate coordinates of the middle point
*Vm = 0.5*(Va+Vb) + 0.375*(Ta+Tb);
//Calculate normal at the middle point
vec3 perp = cross((Vb-Va),(Na+Nb));
*Nm = normalize(cross(perp,Tm));
}