[Bf-blender-cvs] [554af9c6895] master: Cleanup: DRW: Make clipped shader use UBO clip planes

Clément Foucault noreply at git.blender.org
Mon May 27 12:58:27 CEST 2019


Commit: 554af9c6895f772ce5fdeb4aa4172c43b997b669
Author: Clément Foucault
Date:   Sun May 26 21:32:48 2019 +0200
Branches: master
https://developer.blender.org/rB554af9c6895f772ce5fdeb4aa4172c43b997b669

Cleanup: DRW: Make clipped shader use UBO clip planes

===================================================================

M	source/blender/draw/intern/draw_manager_data.c
M	source/blender/draw/modes/shaders/common_view_lib.glsl
M	source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl

===================================================================

diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index 9b131e68ae0..c3b905323cc 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -874,11 +874,9 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader)
     drw_shgroup_builtin_uniform(shgroup, GPU_UNIFORM_VIEWPROJECTION_INV, storage->persinv, 16, 1);
     drw_shgroup_builtin_uniform(shgroup, GPU_UNIFORM_PROJECTION, storage->winmat, 16, 1);
     drw_shgroup_builtin_uniform(shgroup, GPU_UNIFORM_PROJECTION_INV, storage->wininv, 16, 1);
+    drw_shgroup_builtin_uniform(shgroup, GPU_UNIFORM_CLIPPLANES, storage->clipplanes, 4, 6);
   }
 
-  drw_shgroup_builtin_uniform(
-      shgroup, GPU_UNIFORM_CLIPPLANES, DST.view_storage_cpy.clipplanes, 4, 6);
-
   /* Not supported. */
   BLI_assert(GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MODELVIEW_INV) == -1);
   BLI_assert(GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MODELVIEW) == -1);
diff --git a/source/blender/draw/modes/shaders/common_view_lib.glsl b/source/blender/draw/modes/shaders/common_view_lib.glsl
index 845c615c75c..20a54947db7 100644
--- a/source/blender/draw/modes/shaders/common_view_lib.glsl
+++ b/source/blender/draw/modes/shaders/common_view_lib.glsl
@@ -1,3 +1,5 @@
+#define COMMON_VIEW_LIB
+
 /* keep in sync with DRWManager.view_data */
 layout(std140) uniform viewBlock
 {
@@ -15,6 +17,12 @@ layout(std140) uniform viewBlock
   vec4 CameraTexCoFactors;
 };
 
+#ifdef world_clip_planes_calc_clip_distance
+#  undef world_clip_planes_calc_clip_distance
+#  define world_clip_planes_calc_clip_distance(p) \
+    _world_clip_planes_calc_clip_distance(p, clipPlanes)
+#endif
+
 uniform mat4 ModelMatrix;
 uniform mat4 ModelMatrixInverse;
 
diff --git a/source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl b/source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl
index e34b86ac1ce..46cf2fe09a2 100644
--- a/source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl
@@ -1,15 +1,24 @@
 #ifdef USE_WORLD_CLIP_PLANES
 #  if defined(GPU_VERTEX_SHADER) || defined(GPU_GEOMETRY_SHADER)
+
 uniform vec4 WorldClipPlanes[6];
-void world_clip_planes_calc_clip_distance(vec3 wpos)
-{
-  gl_ClipDistance[0] = dot(WorldClipPlanes[0].xyz, wpos) + WorldClipPlanes[0].w;
-  gl_ClipDistance[1] = dot(WorldClipPlanes[1].xyz, wpos) + WorldClipPlanes[1].w;
-  gl_ClipDistance[2] = dot(WorldClipPlanes[2].xyz, wpos) + WorldClipPlanes[2].w;
-  gl_ClipDistance[3] = dot(WorldClipPlanes[3].xyz, wpos) + WorldClipPlanes[3].w;
-  gl_ClipDistance[4] = dot(WorldClipPlanes[4].xyz, wpos) + WorldClipPlanes[4].w;
-  gl_ClipDistance[5] = dot(WorldClipPlanes[5].xyz, wpos) + WorldClipPlanes[5].w;
-}
+
+#    define _world_clip_planes_calc_clip_distance(wpos, _clipplanes) \
+      { \
+        vec4 pos = vec4(wpos, 1.0); \
+        gl_ClipDistance[0] = dot(_clipplanes[0], pos); \
+        gl_ClipDistance[1] = dot(_clipplanes[1], pos); \
+        gl_ClipDistance[2] = dot(_clipplanes[2], pos); \
+        gl_ClipDistance[3] = dot(_clipplanes[3], pos); \
+        gl_ClipDistance[4] = dot(_clipplanes[4], pos); \
+        gl_ClipDistance[5] = dot(_clipplanes[5], pos); \
+      }
+
+/* HACK Dirty hack to be able to override the definition in common_view_lib.glsl.
+ * Not doing this would require changing the include order in every shaders. */
+#    define world_clip_planes_calc_clip_distance(wpos) \
+      _world_clip_planes_calc_clip_distance(wpos, WorldClipPlanes)
+
 #  endif
 
 #  define world_clip_planes_set_clip_distance(c) \



More information about the Bf-blender-cvs mailing list