[Bf-blender-cvs] [f21f35b68dc] tmp-overlay-engine: Overlay Engine: Edit Mode: Change Normal overlays

Clément Foucault noreply at git.blender.org
Wed Nov 20 20:54:13 CET 2019


Commit: f21f35b68dc449e8ded0a3609402ca4b1e7d3581
Author: Clément Foucault
Date:   Wed Nov 20 00:55:59 2019 +0100
Branches: tmp-overlay-engine
https://developer.blender.org/rBf21f35b68dc449e8ded0a3609402ca4b1e7d3581

Overlay Engine: Edit Mode: Change Normal overlays

This gets rid of the geometry shader for normal display.
(note: happens to be twice as fast)
This also remove the unecessary shader variations.

Another goal was to get the do_zbufclip behavior back.
We occlude the base vertex which can occasion some flickers bu

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

M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/overlay/overlay_edit_mesh.c
M	source/blender/draw/engines/overlay/overlay_private.h
M	source/blender/draw/engines/overlay/overlay_shader.c
D	source/blender/draw/engines/overlay/shaders/edit_mesh_normal_geom.glsl
M	source/blender/draw/engines/overlay/shaders/edit_mesh_normal_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 10a21f6aea6..bf11fe2ce2e 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -399,7 +399,6 @@ data_to_c_simple(engines/overlay/shaders/edit_mesh_facefill_vert.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/edit_mesh_frag.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/edit_mesh_geom.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/edit_mesh_normal_vert.glsl SRC)
-data_to_c_simple(engines/overlay/shaders/edit_mesh_normal_geom.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/edit_mesh_analysis_frag.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/edit_mesh_analysis_vert.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/edit_mesh_skin_root_vert.glsl SRC)
diff --git a/source/blender/draw/engines/overlay/overlay_edit_mesh.c b/source/blender/draw/engines/overlay/overlay_edit_mesh.c
index 48ff5764c9c..dbc3dcbbe3d 100644
--- a/source/blender/draw/engines/overlay/overlay_edit_mesh.c
+++ b/source/blender/draw/engines/overlay/overlay_edit_mesh.c
@@ -123,7 +123,6 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
   }
 
   float backwire_opacity = (pd->edit_mesh.do_zbufclip) ? v3d->overlay.backwire_opacity : 1.0f;
-  float size_normal = v3d->overlay.normals_length;
   float face_alpha = (do_occlude_wire || !pd->edit_mesh.do_faces) ? 0.0f : 1.0f;
   GPUTexture **depth_tex = (pd->edit_mesh.do_zbufclip) ? &dtxl->depth : &txl->dummy_depth_tx;
 
@@ -156,23 +155,16 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
   }
   {
     /* Normals */
-    state = DRW_STATE_WRITE_DEPTH | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL;
+    state = DRW_STATE_WRITE_DEPTH | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL |
+            (pd->edit_mesh.do_zbufclip ? DRW_STATE_BLEND_ALPHA : 0);
     DRW_PASS_CREATE(psl->edit_mesh_normals_ps, state | pd->clipping_state);
 
-    sh = OVERLAY_shader_edit_mesh_normal_face();
-    pd->edit_mesh_fnormals_grp = grp = DRW_shgroup_create(sh, psl->edit_mesh_normals_ps);
-    DRW_shgroup_uniform_float_copy(grp, "normalSize", size_normal);
-    DRW_shgroup_uniform_vec4_copy(grp, "color", G_draw.block.colorNormal);
-
-    sh = OVERLAY_shader_edit_mesh_normal_vert();
-    pd->edit_mesh_vnormals_grp = grp = DRW_shgroup_create(sh, psl->edit_mesh_normals_ps);
-    DRW_shgroup_uniform_float_copy(grp, "normalSize", size_normal);
-    DRW_shgroup_uniform_vec4_copy(grp, "color", G_draw.block.colorVNormal);
-
-    sh = OVERLAY_shader_edit_mesh_normal_loop();
-    pd->edit_mesh_lnormals_grp = grp = DRW_shgroup_create(sh, psl->edit_mesh_normals_ps);
-    DRW_shgroup_uniform_float_copy(grp, "normalSize", size_normal);
-    DRW_shgroup_uniform_vec4_copy(grp, "color", G_draw.block.colorLNormal);
+    sh = OVERLAY_shader_edit_mesh_normal();
+    pd->edit_mesh_normals_grp = grp = DRW_shgroup_create(sh, psl->edit_mesh_normals_ps);
+    DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
+    DRW_shgroup_uniform_float_copy(grp, "normalSize", v3d->overlay.normals_length);
+    DRW_shgroup_uniform_float_copy(grp, "alpha", backwire_opacity);
+    DRW_shgroup_uniform_texture_ref(grp, "depthTex", depth_tex);
   }
   {
     /* Mesh Analysis Pass */
@@ -335,17 +327,20 @@ void OVERLAY_edit_mesh_cache_populate(OVERLAY_Data *vedata, Object *ob)
     DRW_shgroup_call_no_cull(pd->edit_mesh_depth_grp[do_in_front], geom, ob);
   }
 
-  if (vnormals_do) {
-    geom = DRW_mesh_batch_cache_get_edit_vnors(ob->data);
-    DRW_shgroup_call_no_cull(pd->edit_mesh_vnormals_grp, geom, ob);
-  }
-  if (lnormals_do) {
-    geom = DRW_mesh_batch_cache_get_edit_lnors(ob->data);
-    DRW_shgroup_call_no_cull(pd->edit_mesh_lnormals_grp, geom, ob);
-  }
-  if (fnormals_do) {
-    geom = DRW_mesh_batch_cache_get_edit_facedots(ob->data);
-    DRW_shgroup_call_no_cull(pd->edit_mesh_fnormals_grp, geom, ob);
+  if (vnormals_do || lnormals_do || fnormals_do) {
+    struct GPUBatch *normal_geom = DRW_cache_normal_arrow_get();
+    if (vnormals_do) {
+      geom = DRW_mesh_batch_cache_get_edit_vnors(ob->data);
+      DRW_shgroup_call_instances_with_attribs(pd->edit_mesh_normals_grp, ob, normal_geom, geom);
+    }
+    if (lnormals_do) {
+      geom = DRW_mesh_batch_cache_get_edit_lnors(ob->data);
+      DRW_shgroup_call_instances_with_attribs(pd->edit_mesh_normals_grp, ob, normal_geom, geom);
+    }
+    if (fnormals_do) {
+      geom = DRW_mesh_batch_cache_get_edit_facedots(ob->data);
+      DRW_shgroup_call_instances_with_attribs(pd->edit_mesh_normals_grp, ob, normal_geom, geom);
+    }
   }
 
   if (pd->edit_mesh.do_zbufclip) {
@@ -407,7 +402,6 @@ void OVERLAY_edit_mesh_draw(OVERLAY_Data *vedata)
 
     DRW_view_set_active(NULL);
 
-    /* Render wires on a separate framebuffer */
     GPU_framebuffer_bind(fbl->edit_mesh_occlude_wire_fb);
     GPU_framebuffer_clear_depth(fbl->edit_mesh_occlude_wire_fb, 1.0f);
     DRW_draw_pass(psl->edit_mesh_normals_ps);
diff --git a/source/blender/draw/engines/overlay/overlay_private.h b/source/blender/draw/engines/overlay/overlay_private.h
index 476af933b23..182896ec2ba 100644
--- a/source/blender/draw/engines/overlay/overlay_private.h
+++ b/source/blender/draw/engines/overlay/overlay_private.h
@@ -207,9 +207,7 @@ typedef struct OVERLAY_PrivateData {
   DRWShadingGroup *edit_mesh_edges_grp[2];
   DRWShadingGroup *edit_mesh_facedots_grp[2];
   DRWShadingGroup *edit_mesh_skin_roots_grp[2];
-  DRWShadingGroup *edit_mesh_fnormals_grp;
-  DRWShadingGroup *edit_mesh_vnormals_grp;
-  DRWShadingGroup *edit_mesh_lnormals_grp;
+  DRWShadingGroup *edit_mesh_normals_grp;
   DRWShadingGroup *edit_mesh_analysis_grp;
   DRWShadingGroup *edit_mesh_weight_grp;
   DRWShadingGroup *edit_particle_strand_grp;
@@ -481,15 +479,13 @@ GPUShader *OVERLAY_shader_edit_curve_point(void);
 GPUShader *OVERLAY_shader_edit_curve_wire(void);
 GPUShader *OVERLAY_shader_edit_lattice_point(void);
 GPUShader *OVERLAY_shader_edit_lattice_wire(void);
-GPUShader *OVERLAY_shader_edit_mesh_vert(void);
+GPUShader *OVERLAY_shader_edit_mesh_analysis(void);
 GPUShader *OVERLAY_shader_edit_mesh_edge(bool use_flat_interp);
 GPUShader *OVERLAY_shader_edit_mesh_face(void);
 GPUShader *OVERLAY_shader_edit_mesh_facedot(void);
+GPUShader *OVERLAY_shader_edit_mesh_normal(void);
 GPUShader *OVERLAY_shader_edit_mesh_skin_root(void);
-GPUShader *OVERLAY_shader_edit_mesh_normal_face(void);
-GPUShader *OVERLAY_shader_edit_mesh_normal_vert(void);
-GPUShader *OVERLAY_shader_edit_mesh_normal_loop(void);
-GPUShader *OVERLAY_shader_edit_mesh_analysis(void);
+GPUShader *OVERLAY_shader_edit_mesh_vert(void);
 GPUShader *OVERLAY_shader_edit_particle_strand(void);
 GPUShader *OVERLAY_shader_edit_particle_point(void);
 GPUShader *OVERLAY_shader_extra(void);
diff --git a/source/blender/draw/engines/overlay/overlay_shader.c b/source/blender/draw/engines/overlay/overlay_shader.c
index 61938433ae5..a89ea107470 100644
--- a/source/blender/draw/engines/overlay/overlay_shader.c
+++ b/source/blender/draw/engines/overlay/overlay_shader.c
@@ -54,7 +54,6 @@ extern char datatoc_edit_mesh_common_lib_glsl[];
 extern char datatoc_edit_mesh_frag_glsl[];
 extern char datatoc_edit_mesh_geom_glsl[];
 extern char datatoc_edit_mesh_vert_glsl[];
-extern char datatoc_edit_mesh_normal_geom_glsl[];
 extern char datatoc_edit_mesh_normal_vert_glsl[];
 extern char datatoc_edit_mesh_skin_root_vert_glsl[];
 extern char datatoc_edit_mesh_analysis_vert_glsl[];
@@ -137,7 +136,7 @@ typedef struct OVERLAY_Shaders {
   GPUShader *edit_mesh_facedot;
   GPUShader *edit_mesh_skin_root;
   GPUShader *edit_mesh_vnormals;
-  GPUShader *edit_mesh_lnormals;
+  GPUShader *edit_mesh_normals;
   GPUShader *edit_mesh_fnormals;
   GPUShader *edit_mesh_analysis;
   GPUShader *edit_particle_strand;
@@ -560,71 +559,23 @@ GPUShader *OVERLAY_shader_edit_mesh_facedot(void)
   return sh_data->edit_mesh_facedot;
 }
 
-GPUShader *OVERLAY_shader_edit_mesh_normal_face(void)
+GPUShader *OVERLAY_shader_edit_mesh_normal(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->edit_mesh_fnormals) {
-    sh_data->edit_mesh_fnormals = GPU_shader_create_from_arrays({
-        .vert = (const char *[]){sh_cfg->lib,
-                                 datatoc_common_view_lib_glsl,
-                                 datatoc_edit_mesh_normal_vert_glsl,
-                                 NULL},
-        .geom = (const char *[]){sh_cfg->lib,
-                                 datatoc_common_view_lib_glsl,
-                                 datatoc_edit_mesh_normal_geom_glsl,
-                                 NULL},
-        .frag = (const char *[]){datatoc_gpu_shader_uniform_color_frag_glsl, NULL},
-        .defs = (const char *[]){sh_cfg->def, "#define FACE_NORMALS\n", NULL},
-    });
-  }
-  return sh_data->edit_mesh_fnormals;
-}
-
-GPUShader *OVERLAY_shader_edit_mesh_normal_vert(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->edit_mesh_vnormals) {
-    sh_data->edit_mesh_vnormals = GPU_shader_create_from_arrays({
-        .vert = (const char *[]){sh_cfg->lib,
-                                 datatoc_common_view_lib_glsl,
-                                 datatoc_edit_mesh_normal_vert_glsl,
-                                 NULL},
-        .geom = (const char *[]){sh_cfg->lib,
-                                 datatoc_common_view_lib_glsl,
-                                 datatoc_edit_mesh_normal_geom_glsl,
-                                 NULL},
-        .frag = (const char *[]){datatoc_gpu_shader_uniform_color_frag_glsl, NULL},
-        .defs = (const char *[]){sh_cfg->def, "#define VERT_NORMALS\n", NULL},
-    });
-  }
-  return sh_data->edit_mesh_vnormals;
-}
-
-GPUShader *OVERLAY_shader_edit_mesh_normal_loop(void)
-{
-  const DRWContextState *draw_ctx = DRW_context_state_get();
-  const GPUShaderConfigData *sh_cfg = &GPU_shader_cfg_data[draw_ctx->sh_cfg];

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list