Cleanup: Edit Mesh shader: Remove unecessary varying

This commit is contained in:
2018-10-15 10:43:49 +02:00
parent 38828309d3
commit 0c39453071
3 changed files with 37 additions and 49 deletions

View File

@@ -8,7 +8,6 @@ layout(triangle_strip, max_vertices=4) out;
uniform mat4 ProjectionMatrix;
uniform vec2 viewportSize;
in vec4 vPos[];
in vec4 pPos[];
in ivec4 vData[];
#ifdef VERTEX_FACING
@@ -77,10 +76,8 @@ void main()
/* Perspective */
if (ProjectionMatrix[3][3] == 0.0) {
/* vPos[i].z is negative and we don't want
* our fixvec to be flipped */
dirs1 *= -vPos[0].z;
dirs2 *= -vPos[1].z;
dirs1 *= pPos[0].w;
dirs2 *= pPos[1].w;
}
/* Edge / Vert data */

View File

@@ -14,7 +14,6 @@ layout(triangle_strip, max_vertices=12) out;
uniform mat4 ProjectionMatrix;
uniform vec2 viewportSize;
in vec4 vPos[];
in vec4 pPos[];
in ivec4 vData[];
#ifdef VERTEX_FACING
@@ -79,9 +78,7 @@ void doVertexOfs(int v, vec2 fixvec)
#ifdef VERTEX_FACING
facing = v_facing[v];
#endif
gl_Position = pPos[v];
gl_Position.xyz += vec3(fixvec, Z_OFFSET);
gl_Position = pPos[v] + vec4(fixvec, Z_OFFSET, 0.0);
EmitVertex();
}
@@ -98,6 +95,35 @@ void mask_edge_flag(int v, ivec3 eflag)
flag[v] &= ~EDGE_EXISTS;
}
vec2 compute_fixvec(int i)
{
int i1 = (i + 1) % 3;
int i2 = (i + 2) % 3;
/* This fix the case when 2 vertices are perfectly aligned
* and corner vectors have nowhere to go.
* ie: length(cornervec[i]) == 0 */
const float epsilon = 1e-2; /* in pixel so not that much */
const vec2 bias[3] = vec2[3](
vec2( epsilon, epsilon),
vec2(-epsilon, epsilon),
vec2( 0.0, -epsilon)
);
vec2 v1 = ssPos[i] + bias[i];
vec2 v2 = ssPos[i1] + bias[i1];
vec2 v3 = ssPos[i2] + bias[i2];
/* Edge normalized vector */
vec2 dir = normalize(v2 - v1);
vec2 dir2 = normalize(v3 - v1);
/* perpendicular to dir */
vec2 perp = vec2(-dir.y, dir.x);
/* Backface case */
if (dot(perp, dir2) > 0.0) {
perp = -perp;
}
/* Make it view independent */
return perp * sizeEdgeFix / viewportSize;;
}
void main()
{
/* Edge */
@@ -127,46 +153,12 @@ void main()
vec2 fixvec[3];
vec2 fixvecaf[3];
/* This fix the case when 2 vertices are perfectly aligned
* and corner vectors have nowhere to go.
* ie: length(cornervec[i]) == 0 */
const float epsilon = 1e-2; /* in pixel so not that much */
const vec2 bias[3] = vec2[3](
vec2( epsilon, epsilon),
vec2(-epsilon, epsilon),
vec2( 0.0, -epsilon)
);
for (int i = 0; i < 3; ++i) {
int i1 = (i + 1) % 3;
int i2 = (i + 2) % 3;
vec2 v1 = ssPos[i] + bias[i];
vec2 v2 = ssPos[i1] + bias[i1];
vec2 v3 = ssPos[i2] + bias[i2];
/* Edge normalized vector */
vec2 dir = normalize(v2 - v1);
vec2 dir2 = normalize(v3 - v1);
/* perpendicular to dir */
vec2 perp = vec2(-dir.y, dir.x);
/* Backface case */
if (dot(perp, dir2) > 0) {
perp = -perp;
}
/* Make it view independent */
perp *= sizeEdgeFix / viewportSize;
fixvec[i] = fixvecaf[i] = perp;
fixvec[i] = fixvecaf[i] = compute_fixvec(i);
/* Perspective */
if (ProjectionMatrix[3][3] == 0.0) {
/* vPos[i].z is negative and we don't want
* our fixvec to be flipped */
fixvec[i] *= -vPos[i].z;
fixvecaf[i] *= -vPos[i1].z;
fixvec[i] *= pPos[i].w;
fixvecaf[i] *= pPos[(i + 1) % 3].w;
}
}

View File

@@ -20,7 +20,6 @@ in vec3 vnor;
#ifdef EDGE_FIX
in ivec4 data;
out vec4 vPos;
out vec4 pPos;
out ivec4 vData;
# ifdef VERTEX_FACING
@@ -29,14 +28,14 @@ out float vFacing;
void main()
{
vPos = ModelViewMatrix * vec4(pos, 1.0);
pPos = ModelViewProjectionMatrix * vec4(pos, 1.0);
pPos.z -= ofs;
vData = data & dataMask;
# ifdef VERTEX_FACING
vec4 vpos = ModelViewMatrix * vec4(pos, 1.0);
vec3 view_normal = normalize(NormalMatrix * vnor);
vec3 view_vec = (ProjectionMatrix[3][3] == 0.0)
? normalize(vPos.xyz)
? normalize(vpos.xyz)
: vec3(0.0, 0.0, 1.0);
vFacing = dot(view_vec, view_normal);
# endif