[Bf-blender-cvs] [3f651fb9791] tmp-overlay-engine: Overlay Engine: Separate GroundLine/Point to a separate buffer

Clément Foucault noreply at git.blender.org
Fri Nov 15 01:34:57 CET 2019


Commit: 3f651fb979119597369bc03e1fcd22b0ddd263ac
Author: Clément Foucault
Date:   Wed Nov 6 14:10:05 2019 +0100
Branches: tmp-overlay-engine
https://developer.blender.org/rB3f651fb979119597369bc03e1fcd22b0ddd263ac

Overlay Engine: Separate GroundLine/Point to a separate buffer

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

M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/overlay/overlay_extra.c
M	source/blender/draw/engines/overlay/overlay_private.h
M	source/blender/draw/engines/overlay/overlay_shader.c
A	source/blender/draw/engines/overlay/shaders/extra_groundline_vert.glsl
M	source/blender/draw/engines/overlay/shaders/extra_vert.glsl
M	source/blender/draw/intern/draw_cache.c
M	source/blender/draw/intern/draw_cache.h

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

diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index f96d63fdcd7..c07e76b3f98 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -396,6 +396,7 @@ data_to_c_simple(engines/overlay/shaders/edit_mesh_mix_occlude_frag.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/edit_mesh_skin_root_vert.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/edit_mesh_vert.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/extra_vert.glsl SRC)
+data_to_c_simple(engines/overlay/shaders/extra_groundline_vert.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/facing_frag.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/facing_vert.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/grid_frag.glsl SRC)
diff --git a/source/blender/draw/engines/overlay/overlay_extra.c b/source/blender/draw/engines/overlay/overlay_extra.c
index 6605ef9ca22..9d4f4d513fd 100644
--- a/source/blender/draw/engines/overlay/overlay_extra.c
+++ b/source/blender/draw/engines/overlay/overlay_extra.c
@@ -41,7 +41,6 @@ void OVERLAY_extra_cache_init(OVERLAY_Data *vedata)
     DRWShadingGroup *grp, *grp_sub;
     float pixelsize = *DRW_viewport_pixelsize_get() * U.pixelsize;
 
-    const GlobalsUboStorage *gb = &G_draw.block;
     OVERLAY_InstanceFormats *formats = OVERLAY_shader_instance_formats_get();
     OVERLAY_ExtraCallBuffers *cb = &pd->extra_call_buffers[i];
     DRWPass **p_extra_ps = &psl->extra_ps[i];
@@ -51,9 +50,6 @@ void OVERLAY_extra_cache_init(OVERLAY_Data *vedata)
 
     DRWPass *extra_ps = *p_extra_ps;
 
-    const DRWContextState *draw_ctx = DRW_context_state_get();
-    const eGPUShaderConfig sh_cfg = draw_ctx->sh_cfg;
-
 #if 0
     /* Empties */
     empties_callbuffers_create(cb->non_meshes, &cb->empties, draw_ctx->sh_cfg);
@@ -199,13 +195,16 @@ void OVERLAY_extra_cache_init(OVERLAY_Data *vedata)
           grp_sub, format, DRW_cache_light_spot_volume_get());
     }
     {
-      format = formats->pos;
-      sh = GPU_shader_get_builtin_shader_with_config(GPU_SHADER_3D_GROUNDLINE, sh_cfg);
+      format = formats->instance_pos;
+      sh = OVERLAY_shader_extra_grounline();
 
       grp = DRW_shgroup_create(sh, extra_ps);
-      DRW_shgroup_uniform_vec4(grp, "color", gb->colorLight, 1);
-      DRW_shgroup_state_enable(grp_sub, DRW_STATE_BLEND_ALPHA);
-      cb->light_groundline = BUF_POINT(grp, format);
+      DRW_shgroup_uniform_float_copy(grp, "pixel_size", pixelsize);
+      DRW_shgroup_uniform_vec3(grp, "screen_vecs[0]", DRW_viewport_screenvecs_get(), 2);
+      DRW_shgroup_uniform_block_persistent(grp, "globalsBlock", G_draw.block_ubo);
+      DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA);
+
+      cb->groundline = BUF_INSTANCE(grp, format, DRW_cache_groundline_get());
     }
 
 #if 0
@@ -305,7 +304,7 @@ static void DRW_shgroup_light(OVERLAY_ExtraCallBuffers *cb, Object *ob, ViewLaye
         float spot_blend;
       };
       float _pad02[3], clip_sta;
-      float _pad03[3], clip_end;
+      float pos[3], clip_end;
     };
   } instdata;
 
@@ -316,6 +315,8 @@ static void DRW_shgroup_light(OVERLAY_ExtraCallBuffers *cb, Object *ob, ViewLaye
   instdata.clip_end = la->clipend;
   instdata.clip_sta = la->clipsta;
 
+  DRW_buffer_add_entry(cb->groundline, instdata.pos);
+
   if (la->type == LA_LOCAL) {
     instdata.area_size_x = instdata.area_size_y = la->area_size;
     DRW_buffer_add_entry(cb->light_point, color, &instdata);
diff --git a/source/blender/draw/engines/overlay/overlay_private.h b/source/blender/draw/engines/overlay/overlay_private.h
index 28275216be0..22239101e28 100644
--- a/source/blender/draw/engines/overlay/overlay_private.h
+++ b/source/blender/draw/engines/overlay/overlay_private.h
@@ -85,8 +85,7 @@ typedef struct OVERLAY_ShadingData {
 } OVERLAY_ShadingData;
 
 typedef struct OVERLAY_ExtraCallBuffers {
-  DRWCallBuffer *light_groundpoint;
-  DRWCallBuffer *light_groundline;
+  DRWCallBuffer *groundline;
 
   DRWCallBuffer *light_point;
   DRWCallBuffer *light_sun;
@@ -196,6 +195,7 @@ typedef struct OVERLAY_InstanceFormats {
   struct GPUVertFormat *pos_color;
   struct GPUVertFormat *pos;
 
+  struct GPUVertFormat *instance_pos;
   struct GPUVertFormat *instance_extra;
 } OVERLAY_InstanceFormats;
 
@@ -248,6 +248,7 @@ GPUShader *OVERLAY_shader_edit_mesh_normal_loop(void);
 GPUShader *OVERLAY_shader_edit_mesh_mix_occlude(void);
 GPUShader *OVERLAY_shader_edit_mesh_analysis(void);
 GPUShader *OVERLAY_shader_extra(void);
+GPUShader *OVERLAY_shader_extra_grounline(void);
 GPUShader *OVERLAY_shader_facing(void);
 GPUShader *OVERLAY_shader_grid(void);
 GPUShader *OVERLAY_shader_outline_prepass(bool use_wire);
diff --git a/source/blender/draw/engines/overlay/overlay_shader.c b/source/blender/draw/engines/overlay/overlay_shader.c
index 124f3c4c89c..06bbfe7ce42 100644
--- a/source/blender/draw/engines/overlay/overlay_shader.c
+++ b/source/blender/draw/engines/overlay/overlay_shader.c
@@ -38,6 +38,7 @@ extern char datatoc_edit_mesh_skin_root_vert_glsl[];
 extern char datatoc_edit_mesh_analysis_vert_glsl[];
 extern char datatoc_edit_mesh_analysis_frag_glsl[];
 extern char datatoc_extra_vert_glsl[];
+extern char datatoc_extra_groundline_vert_glsl[];
 extern char datatoc_facing_frag_glsl[];
 extern char datatoc_facing_vert_glsl[];
 extern char datatoc_grid_frag_glsl[];
@@ -82,6 +83,7 @@ typedef struct OVERLAY_Shaders {
   GPUShader *edit_mesh_mix_occlude;
   GPUShader *edit_mesh_analysis;
   GPUShader *extra;
+  GPUShader *extra_groundline;
   GPUShader *outline_prepass;
   GPUShader *outline_prepass_wire;
   GPUShader *outline_prepass_lightprobe_grid;
@@ -359,6 +361,25 @@ GPUShader *OVERLAY_shader_extra(void)
   return sh_data->extra;
 }
 
+GPUShader *OVERLAY_shader_extra_grounline(void)
+{
+  const DRWContextState *draw_ctx = DRW_context_state_get();
+  const GPUShaderConfigData *sh_cfg = &GPU_shader_cfg_data[draw_ctx->sh_cfg];
+  OVERLAY_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
+  if (!sh_data->extra_groundline) {
+    sh_data->extra_groundline = GPU_shader_create_from_arrays({
+        .vert = (const char *[]){sh_cfg->lib,
+                                 datatoc_common_globals_lib_glsl,
+                                 datatoc_common_view_lib_glsl,
+                                 datatoc_extra_groundline_vert_glsl,
+                                 NULL},
+        .frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL},
+        .defs = (const char *[]){sh_cfg->def, NULL},
+    });
+  }
+  return sh_data->extra_groundline;
+}
+
 GPUShader *OVERLAY_shader_facing(void)
 {
   const DRWContextState *draw_ctx = DRW_context_state_get();
@@ -561,7 +582,7 @@ static OVERLAY_InstanceFormats g_formats = {NULL};
 
 OVERLAY_InstanceFormats *OVERLAY_shader_instance_formats_get(void)
 {
-  DRW_shgroup_instance_format(g_formats.pos, {{"pos", DRW_ATTR_FLOAT, 3}});
+  DRW_shgroup_instance_format(g_formats.instance_pos, {{"inst_pos", DRW_ATTR_FLOAT, 3}});
   DRW_shgroup_instance_format(g_formats.instance_extra,
                               {
                                   {"color", DRW_ATTR_FLOAT, 4},
diff --git a/source/blender/draw/engines/overlay/shaders/extra_groundline_vert.glsl b/source/blender/draw/engines/overlay/shaders/extra_groundline_vert.glsl
new file mode 100644
index 00000000000..dcbd915a15e
--- /dev/null
+++ b/source/blender/draw/engines/overlay/shaders/extra_groundline_vert.glsl
@@ -0,0 +1,30 @@
+
+uniform vec3 screen_vecs[2];
+uniform float pixel_size;
+
+in vec3 pos;
+
+/* Instance */
+in vec3 inst_pos;
+
+flat out vec4 finalColor;
+
+float mul_project_m4_v3_zfac(in vec3 co)
+{
+  return (ViewProjectionMatrix[0][3] * co.x) + (ViewProjectionMatrix[1][3] * co.y) +
+         (ViewProjectionMatrix[2][3] * co.z) + ViewProjectionMatrix[3][3];
+}
+
+void main()
+{
+  finalColor = colorLight;
+
+  /* Relative to DPI scalling. Have constant screen size. */
+  vec3 screen_pos = screen_vecs[0].xyz * pos.x + screen_vecs[1].xyz * pos.y;
+  vec3 p = inst_pos;
+  p.z *= (pos.z == 0.0) ? 0.0 : 1.0;
+  float screen_size = mul_project_m4_v3_zfac(p) * pixel_size;
+  vec3 world_pos = p + screen_pos * screen_size;
+
+  gl_Position = point_world_to_ndc(world_pos);
+}
\ No newline at end of file
diff --git a/source/blender/draw/engines/overlay/shaders/extra_vert.glsl b/source/blender/draw/engines/overlay/shaders/extra_vert.glsl
index 3e245280342..4cf58426760 100644
--- a/source/blender/draw/engines/overlay/shaders/extra_vert.glsl
+++ b/source/blender/draw/engines/overlay/shaders/extra_vert.glsl
@@ -24,7 +24,6 @@ in vec4 color;
 
 #define VCLASS_SCREENSPACE (1 << 8)
 #define VCLASS_SCREENALIGNED (1 << 9)
-#define VCLASS_GROUND_POINT (1 << 10)
 
 flat out vec4 finalColor;
 
@@ -81,11 +80,6 @@ void main()
     vec3 screen_pos = screen_vecs[0].xyz * vpos.x + screen_vecs[1].xyz * vpos.y;
     world_pos = (obmat * vec4(vofs, 1.0)).xyz + screen_pos;
   }
-  else if ((vclass & VCLASS_GROUND_POINT) != 0) {
-    /* Projected object center. */
-    world_pos = vec3(obmat[3].xy, 0.0);
-    finalColor = colorLight;
-  }
   else {
     world_pos = (obmat * vec4(vofs + vpos, 1.0)).xyz;
   }
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index 644795a6f27..a2cb64ca011 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -52,7 +52,6 @@
 
 #define VCLASS_SCREENSPACE (1 << 8)
 #define VCLASS_SCREENALIGNED (1 << 9)
-#define VCLASS_GROUND_POINT (1 << 10)
 
 /* Batch's only (free'd as an array) */
 static struct DRWShapeCache {
@@ -88,6 +87,7 @@ static struct DRWShapeCache {
   GPUBatch *drw_field_vortex;
   GPUBatch *drw_field_tube_limit;
   GPUBatch *drw_field_cone_limit;
+  GPUBatch *drw_ground_line;
   GPUBatch *drw_light_point_lines;
   GPUBatch *drw_light_sun_lines;
   GPUBatch *drw_light_spot_lines;
@@ -1493,6 +1493,29 @@ static void circle_dashed_verts(
   }
 }
 
+GPUBatch *DRW_cache_groundline_get(void)
+{
+  if (!SHC.drw_ground_line) {
+    GPUVertFormat format = {0};
+    GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+    GPU_vertformat_attr_add(&format, "vclass", GPU_COMP_I32, 1, GPU_FETCH_INT); /* Unused */
+
+    int v_len = 2 * (1 + DIAMOND

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list