DRW: pass clipping to geom shader via 'gl_in'

Removes need to pass the worldspace location.
This commit is contained in:
Campbell Barton
2019-01-21 17:48:16 +11:00
parent 1ab071bd5c
commit a06b2b25ad
5 changed files with 29 additions and 47 deletions

View File

@@ -10,15 +10,10 @@ uniform mat4 ViewProjectionMatrixInverse;
uniform vec2 viewportSize;
#ifdef USE_WORLD_CLIP_PLANES
uniform vec4 WorldClipPlanes[6];
uniform int WorldClipPlanesLen;
#endif
in vec4 pPos[];
#ifdef USE_WORLD_CLIP_PLANES
/* Worldspace position. */
in vec3 wsPos[];
#endif
in ivec4 vData[];
#ifdef VERTEX_FACING
in float vFacing[];
@@ -68,11 +63,8 @@ void doVertex(int v, vec4 pos)
gl_Position = pos;
#ifdef USE_WORLD_CLIP_PLANES
{
vec3 worldPosition = wsPos[v];
for (int i = 0; i < WorldClipPlanesLen; i++) {
gl_ClipDistance[i] = dot(WorldClipPlanes[i].xyz, worldPosition) + WorldClipPlanes[i].w;
}
for (int i = 0; i < WorldClipPlanesLen; i++) {
gl_ClipDistance[i] = gl_in[v].gl_ClipDistance[i];
}
#endif

View File

@@ -16,7 +16,6 @@ uniform vec2 viewportSize;
uniform bool isXray = false;
#ifdef USE_WORLD_CLIP_PLANES
uniform vec4 WorldClipPlanes[6];
uniform int WorldClipPlanesLen;
#endif
@@ -78,13 +77,11 @@ void doVertex(int v)
gl_Position = pPos[v];
#ifdef USE_WORLD_CLIP_PLANES
{
vec3 worldPosition = wsPos[v];
for (int i = 0; i < WorldClipPlanesLen; i++) {
gl_ClipDistance[i] = dot(WorldClipPlanes[i].xyz, worldPosition) + WorldClipPlanes[i].w;
}
for (int i = 0; i < WorldClipPlanesLen; i++) {
gl_ClipDistance[i] = gl_in[v].gl_ClipDistance[i];
}
#endif
EmitVertex();
}
@@ -101,13 +98,11 @@ void doVertexOfs(int v, vec2 fixvec)
gl_Position = pPos[v] + vec4(fixvec * pPos[v].w, z_ofs, 0.0);
#ifdef USE_WORLD_CLIP_PLANES
{
vec3 worldPosition = wsPos[v];
for (int i = 0; i < WorldClipPlanesLen; i++) {
gl_ClipDistance[i] = dot(WorldClipPlanes[i].xyz, worldPosition) + WorldClipPlanes[i].w;
}
for (int i = 0; i < WorldClipPlanesLen; i++) {
gl_ClipDistance[i] = gl_in[v].gl_ClipDistance[i];
}
#endif
EmitVertex();
}

View File

@@ -24,9 +24,6 @@ in vec3 vnor;
in ivec4 data;
out vec4 pPos;
#ifdef USE_WORLD_CLIP_PLANES
out vec3 wsPos;
#endif
out ivec4 vData;
# ifdef VERTEX_FACING
out float vFacing;
@@ -45,9 +42,14 @@ void main()
vFacing = dot(view_vec, view_normal);
# endif
#ifdef USE_WORLD_CLIP_PLANES
wsPos = (ModelMatrix * vec4(pos, 1.0)).xyz;
#endif
# ifdef USE_WORLD_CLIP_PLANES
{
vec3 worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz;
for (int i = 0; i < WorldClipPlanesLen; i++) {
gl_ClipDistance[i] = dot(WorldClipPlanes[i].xyz, worldPosition) + WorldClipPlanes[i].w;
}
}
# endif
}
#else /* EDGE_FIX */
@@ -112,14 +114,14 @@ void main()
facing = dot(view_vec, view_normal);
# endif
#ifdef USE_WORLD_CLIP_PLANES
# ifdef USE_WORLD_CLIP_PLANES
{
vec3 worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz;
for (int i = 0; i < WorldClipPlanesLen; i++) {
gl_ClipDistance[i] = dot(WorldClipPlanes[i].xyz, worldPosition) + WorldClipPlanes[i].w;
}
}
#endif
# endif
}
#endif

View File

@@ -3,33 +3,19 @@ layout(points) in;
layout(line_strip, max_vertices=2) out;
#ifdef USE_WORLD_CLIP_PLANES
uniform vec4 WorldClipPlanes[6];
uniform int WorldClipPlanesLen;
#endif
flat in vec4 v1[1];
flat in vec4 v2[1];
#ifdef USE_WORLD_CLIP_PLANES
flat in vec3 wsPos[1];
#endif
void main()
{
#ifdef USE_WORLD_CLIP_PLANES
float clip_distance[6];
{
vec3 worldPosition = wsPos[0];
for (int i = 0; i < WorldClipPlanesLen; i++) {
clip_distance[i] = dot(WorldClipPlanes[i].xyz, worldPosition) + WorldClipPlanes[i].w;
}
}
#endif
for (int v = 0; v < 2; v++) {
gl_Position = (v == 0) ? v1[0] : v2[0];
#ifdef USE_WORLD_CLIP_PLANES
for (int i = 0; i < WorldClipPlanesLen; i++) {
gl_ClipDistance[i] = clip_distance[i];
gl_ClipDistance[i] = gl_in[0].gl_ClipDistance[i];
}
#endif
EmitVertex();

View File

@@ -5,11 +5,13 @@ uniform mat4 ProjectionMatrix;
uniform mat4 ModelMatrix;
uniform float normalSize;
in vec3 pos;
#ifdef USE_WORLD_CLIP_PLANES
flat out vec3 wsPos;
uniform vec4 WorldClipPlanes[6];
uniform int WorldClipPlanesLen;
#endif
in vec3 pos;
#ifdef LOOP_NORMALS
in vec3 lnor;
#define nor lnor
@@ -32,6 +34,11 @@ void main()
vec3 n = normalize(NormalMatrix * nor); /* viewspace */
v2 = v1 + ProjectionMatrix * vec4(n * normalSize, 0.0);
#ifdef USE_WORLD_CLIP_PLANES
wsPos = (ModelMatrix * vec4(pos, 1.0)).xyz;
{
vec3 worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz;
for (int i = 0; i < WorldClipPlanesLen; i++) {
gl_ClipDistance[i] = dot(WorldClipPlanes[i].xyz, worldPosition) + WorldClipPlanes[i].w;
}
}
#endif
}