Commit 81e35fd2 by Kai Westerkamp

corner watertight

parent 2698531f
#version 430
#define M_PI 3.1415926535897932384626433832795
layout(triangles, equal_spacing, cw) in;
in vec3 tcPosition[];
......@@ -10,6 +11,54 @@ uniform mat4x4 MV;
uniform mat4x4 MVP;
uniform int subdiv;
bool compare(vec3 a, vec3 b){
if(a.x < b.x)
return true;
if(a.x > b.x)
return false;
if(a.y < b.y)
return true;
if(a.y > b.y)
return false;
if(a.z < b.z)
return true;
if(a.z > b.z)
return false;
return false;
}
vec3 calcCorner(vec3 points[6], vec3 center){
for(int i = 0; i < 5; i++){
for(int j = 0; j < 5-i; j++){
if(compare(points[j],points[j+1])){
vec3 temp = points[j];
points[j] = points[j+1];
points[j+1] = temp;
}
}
}
float a = 5.0/8.0 - pow((3.0 / 8.0 + 2.0/8.0 * cos(2.0 * M_PI / 6)), 2.0);
float omega = 3.0 * 6 / (8.0 * a);
vec3 newPos = vec3(0.0);
for (int i = 0; i < 6; i++) {
newPos += points[i];
}
newPos *= 1.0 / (omega + 6);
newPos += omega / (omega + 6) * center;
return newPos;
}
void main()
{
float u = gl_TessCoord.x;
......@@ -55,13 +104,7 @@ void main()
vec3 newPos= a0*p0+a1*p1+a2*p2+a3*p3+a4*p4+a5*p5+a6*p6+a7*p7+a8*p8+a9*p9+a10*p10+a11*p11;
if(v == 0){
newPos = (a0*p0+a11*p11)
+(a1*p1+a10*p10)
+(a4*p4+a6*p6)
+(a2*p2+a8*p8)
+(a3*p3+a7*p7);
}
//Edge
if(u == 0){
newPos = (a2*p2+a11*p11)
+(a3*p3+a10*p10)
......@@ -69,6 +112,14 @@ void main()
+(a5*p5+a8*p8)
+(a6*p6+a7*p7);
}
if(v == 0){
newPos = (a0*p0+a11*p11)
+(a1*p1+a10*p10)
+(a4*p4+a6*p6)
+(a2*p2+a8*p8)
+(a3*p3+a7*p7);
}
if(w == 0){
newPos = (a0*p0+a10*p10)
+(a3*p3+a6*p6)
......@@ -77,17 +128,52 @@ void main()
+(a2*p2+a7*p7);
}
//Corner
if(u == 1){
vec3 points[6];
points[0] = p0;
points[1] = p1;
points[2] = p4;
points[3] = p7;
points[4] = p6;
points[5] = p2;
newPos= calcCorner(points, p3);
}
if (subdiv == 0) {
newPos = u * p3 + v * p6 + w * p7;
if(v == 1){
vec3 points[6];
points[0] = p2;
points[1] = p3;
points[2] = p7;
points[3] = p10;
points[4] = p9;
points[5] = p5;
newPos= calcCorner(points, p6);
}
vec4 pos = vec4(newPos, 1.0f);
if(w == 1){
vec3 points[6];
points[0] = p3;
points[1] = p4;
points[2] = p8;
points[3] = p11;
points[4] = p10;
points[5] = p6;
newPos= calcCorner(points, p7);
}
if (subdiv == 0) {
newPos = u * p3 + v * p6 + w * p7;
}
vec4 pos = vec4(newPos, 1.0f);
tePatchDistance = gl_TessCoord.xyz;
teCamPosition = vec4(MV*pos).xyz;
gl_Position = MVP * pos;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment