diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-01-21 09:48:16 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-01-21 09:50:31 +0300 |
commit | a06b2b25adb2b0a1232ae78ba82e0ecef8cdf976 (patch) | |
tree | 38438ecdb7dc3d339ad665395144c9356b9c4bae /source/blender/draw/modes | |
parent | 1ab071bd5cc662be5088bc48c1bb605a727c3656 (diff) |
DRW: pass clipping to geom shader via 'gl_in'
Removes need to pass the worldspace location.
Diffstat (limited to 'source/blender/draw/modes')
5 files changed, 29 insertions, 47 deletions
diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl index adebb81ca1a..e8987b59c45 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl @@ -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 diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl index 61820fcbe22..3fcc3a7240f 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl @@ -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(); } diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl index d513c1302f1..d4d7c455b1b 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl @@ -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 diff --git a/source/blender/draw/modes/shaders/edit_normals_geom.glsl b/source/blender/draw/modes/shaders/edit_normals_geom.glsl index 323761abd1b..50214c75e6a 100644 --- a/source/blender/draw/modes/shaders/edit_normals_geom.glsl +++ b/source/blender/draw/modes/shaders/edit_normals_geom.glsl @@ -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(); diff --git a/source/blender/draw/modes/shaders/edit_normals_vert.glsl b/source/blender/draw/modes/shaders/edit_normals_vert.glsl index edca278fa8b..99741de63bb 100644 --- a/source/blender/draw/modes/shaders/edit_normals_vert.glsl +++ b/source/blender/draw/modes/shaders/edit_normals_vert.glsl @@ -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 } |