[Bf-blender-cvs] [692891f69ea] master: Fix sculpt mode drawing with modifiers still being wrong in some cases

Brecht Van Lommel noreply at git.blender.org
Fri May 31 17:23:18 CEST 2019


Commit: 692891f69ea42af0ba890f5f92cbd1a3260442c9
Author: Brecht Van Lommel
Date:   Fri May 31 14:04:16 2019 +0200
Branches: master
https://developer.blender.org/rB692891f69ea42af0ba890f5f92cbd1a3260442c9

Fix sculpt mode drawing with modifiers still being wrong in some cases

Centralize logic for when to use the PBVH for drawing, fix missing tests in
mask drawing, fix missing tests for multiple windows, only do more expensive
update for all viewports at end of the stroke.

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

M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/intern/paint.c
M	source/blender/draw/engines/eevee/eevee_materials.c
M	source/blender/draw/engines/workbench/workbench_deferred.c
M	source/blender/draw/engines/workbench/workbench_forward.c
M	source/blender/draw/engines/workbench/workbench_materials.c
M	source/blender/draw/engines/workbench/workbench_private.h
M	source/blender/draw/intern/DRW_render.h
M	source/blender/draw/intern/draw_manager.c
M	source/blender/draw/modes/overlay_mode.c
M	source/blender/draw/modes/sculpt_mode.c
M	source/blender/editors/sculpt_paint/paint_vertex.c
M	source/blender/editors/sculpt_paint/sculpt.c

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

diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 56c92b731b7..b92ce8a001f 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -54,6 +54,7 @@ struct SubdivCCG;
 struct Tex;
 struct ToolSettings;
 struct UnifiedPaintSettings;
+struct View3D;
 struct ViewLayer;
 struct bContext;
 struct bToolRef;
@@ -250,9 +251,6 @@ typedef struct SculptSession {
   float (*deform_cos)[3];      /* coords of deformed mesh but without stroke displacement */
   float (*deform_imats)[3][3]; /* crazyspace deformation matrices */
 
-  /* Partial redraw */
-  bool partial_redraw;
-
   /* Used to cache the render of the active texture */
   unsigned int texcache_side, *texcache, texcache_actual;
   struct ImagePool *tex_pool;
@@ -308,6 +306,8 @@ struct PBVH *BKE_sculpt_object_pbvh_ensure(struct Depsgraph *depsgraph, struct O
 
 void BKE_sculpt_bvh_update_from_ccg(struct PBVH *pbvh, struct SubdivCCG *subdiv_ccg);
 
+bool BKE_sculptsession_use_pbvh_draw(const struct Object *ob, const struct View3D *v3d);
+
 enum {
   SCULPT_MASK_LAYER_CALC_VERT = (1 << 0),
   SCULPT_MASK_LAYER_CALC_LOOP = (1 << 1),
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 5849d691b03..4de425acfc0 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -1512,3 +1512,23 @@ void BKE_sculpt_bvh_update_from_ccg(PBVH *pbvh, SubdivCCG *subdiv_ccg)
                         subdiv_ccg->grid_flag_mats,
                         subdiv_ccg->grid_hidden);
 }
+
+/* Test if PBVH can be used directly for drawing, which is faster than
+ * drawing the mesh and all updates that come with it. */
+bool BKE_sculptsession_use_pbvh_draw(const Object *ob, const View3D *v3d)
+{
+  SculptSession *ss = ob->sculpt;
+  if (ss == NULL || ss->pbvh == NULL || ss->mode_type != OB_MODE_SCULPT) {
+    return false;
+  }
+
+  if (BKE_pbvh_type(ss->pbvh) == PBVH_FACES) {
+    /* Regular mesh only draws from PBVH without modifiers and shape keys. */
+    const bool full_shading = (v3d && (v3d->shading.type > OB_SOLID));
+    return !(ss->kb || ss->modifiers_active || full_shading);
+  }
+  else {
+    /* Multires and dyntopo always draw directly from the PBVH. */
+    return true;
+  }
+}
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c
index 3b78d8718ef..2b8673e2f53 100644
--- a/source/blender/draw/engines/eevee/eevee_materials.c
+++ b/source/blender/draw/engines/eevee/eevee_materials.c
@@ -28,9 +28,8 @@
 #include "BLI_rand.h"
 #include "BLI_string_utils.h"
 
-#include "BKE_particle.h"
 #include "BKE_paint.h"
-#include "BKE_pbvh.h"
+#include "BKE_particle.h"
 
 #include "DNA_world_types.h"
 #include "DNA_modifier_types.h"
@@ -1535,10 +1534,7 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata,
   Scene *scene = draw_ctx->scene;
   GHash *material_hash = stl->g_data->material_hash;
 
-  bool is_sculpt_mode = DRW_object_use_pbvh_drawing(ob);
-  /* For now just force fully shaded with eevee when supported. */
-  is_sculpt_mode = is_sculpt_mode &&
-                   !(ob->sculpt->pbvh && BKE_pbvh_type(ob->sculpt->pbvh) == PBVH_FACES);
+  bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->v3d);
 
   /* First get materials for this mesh. */
   if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL)) {
@@ -1606,7 +1602,7 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata,
       int auto_layer_count;
       struct GPUBatch **mat_geom = NULL;
 
-      if (!is_sculpt_mode) {
+      if (!use_sculpt_pbvh) {
         mat_geom = DRW_cache_object_surface_material_get(ob,
                                                          gpumat_array,
                                                          materials_len,
@@ -1615,7 +1611,7 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata,
                                                          &auto_layer_count);
       }
 
-      if (is_sculpt_mode) {
+      if (use_sculpt_pbvh) {
         /* Vcol is not supported in the modes that require PBVH drawing. */
         bool use_vcol = false;
         DRW_shgroup_call_sculpt_with_materials(shgrp_array, ob, use_vcol);
diff --git a/source/blender/draw/engines/workbench/workbench_deferred.c b/source/blender/draw/engines/workbench/workbench_deferred.c
index 516d4de897f..3dbdd1cce61 100644
--- a/source/blender/draw/engines/workbench/workbench_deferred.c
+++ b/source/blender/draw/engines/workbench/workbench_deferred.c
@@ -30,6 +30,7 @@
 
 #include "BKE_modifier.h"
 #include "BKE_object.h"
+#include "BKE_paint.h"
 #include "BKE_particle.h"
 
 #include "DNA_image_types.h"
@@ -965,13 +966,13 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
   WORKBENCH_MaterialData *material;
   if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL)) {
     const bool is_active = (ob == draw_ctx->obact);
-    const bool is_sculpt_mode = DRW_object_use_pbvh_drawing(ob);
+    const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->v3d);
     const bool use_hide = is_active && DRW_object_use_hide_faces(ob);
     const int materials_len = MAX2(1, ob->totcol);
     const Mesh *me = (ob->type == OB_MESH) ? ob->data : NULL;
     bool has_transp_mat = false;
 
-    if (!is_sculpt_mode && TEXTURE_DRAWING_ENABLED(wpd) && me && me->mloopuv) {
+    if (!use_sculpt_pbvh && TEXTURE_DRAWING_ENABLED(wpd) && me && me->mloopuv) {
       /* Draw textured */
       struct GPUBatch **geom_array = DRW_cache_mesh_surface_texpaint_get(ob);
       for (int i = 0; i < materials_len; i++) {
@@ -981,12 +982,13 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
           ImageUser *iuser;
           int interp;
           workbench_material_get_image_and_mat(ob, i + 1, &image, &iuser, &interp, &mat);
-          int color_type = workbench_material_determine_color_type(wpd, image, ob, is_sculpt_mode);
+          int color_type = workbench_material_determine_color_type(
+              wpd, image, ob, use_sculpt_pbvh);
           if (color_type == V3D_SHADING_MATERIAL_COLOR && mat && mat->a < 1.0) {
             /* Hack */
             wpd->shading.xray_alpha = mat->a;
             material = workbench_forward_get_or_create_material_data(
-                vedata, ob, mat, image, iuser, color_type, 0, is_sculpt_mode);
+                vedata, ob, mat, image, iuser, color_type, 0, use_sculpt_pbvh);
             has_transp_mat = true;
           }
           else {
@@ -1002,13 +1004,13 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
                   V3D_SHADING_OBJECT_COLOR,
                   V3D_SHADING_RANDOM_COLOR,
                   V3D_SHADING_VERTEX_COLOR)) {
-      int color_type = workbench_material_determine_color_type(wpd, NULL, ob, is_sculpt_mode);
+      int color_type = workbench_material_determine_color_type(wpd, NULL, ob, use_sculpt_pbvh);
 
       if ((ob->color[3] < 1.0f) && (color_type == V3D_SHADING_OBJECT_COLOR)) {
         /* Hack */
         wpd->shading.xray_alpha = ob->color[3];
         material = workbench_forward_get_or_create_material_data(
-            vedata, ob, NULL, NULL, NULL, color_type, 0, is_sculpt_mode);
+            vedata, ob, NULL, NULL, NULL, color_type, 0, use_sculpt_pbvh);
         has_transp_mat = true;
       }
       else {
@@ -1016,7 +1018,7 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
         material = get_or_create_material_data(vedata, ob, NULL, NULL, NULL, color_type, 0);
       }
 
-      if (is_sculpt_mode) {
+      if (use_sculpt_pbvh) {
         bool use_vcol = (color_type == V3D_SHADING_VERTEX_COLOR);
         DRW_shgroup_call_sculpt(material->shgrp, ob, false, false, use_vcol);
       }
@@ -1036,7 +1038,7 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
     }
     else {
       /* Draw material color */
-      if (is_sculpt_mode) {
+      if (use_sculpt_pbvh) {
         struct DRWShadingGroup **shgrps = BLI_array_alloca(shgrps, materials_len);
 
         for (int i = 0; i < materials_len; ++i) {
@@ -1045,7 +1047,7 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
             /* Hack */
             wpd->shading.xray_alpha = mat->a;
             material = workbench_forward_get_or_create_material_data(
-                vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0, is_sculpt_mode);
+                vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0, use_sculpt_pbvh);
             has_transp_mat = true;
           }
           else {
@@ -1070,7 +1072,7 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
               /* Hack */
               wpd->shading.xray_alpha = mat->a;
               material = workbench_forward_get_or_create_material_data(
-                  vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0, is_sculpt_mode);
+                  vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0, use_sculpt_pbvh);
               has_transp_mat = true;
             }
             else {
@@ -1087,7 +1089,7 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
       bool is_manifold;
       struct GPUBatch *geom_shadow = DRW_cache_object_edge_detection_get(ob, &is_manifold);
       if (geom_shadow) {
-        if (is_sculpt_mode || use_hide) {
+        if (use_sculpt_pbvh || use_hide) {
           /* Currently unsupported in sculpt mode. We could revert to the slow
            * method in this case but I'm not sure if it's a good idea given that
            * sculpted meshes are heavy to begin with. */
diff --git a/source/blender/draw/engines/workbench/workbench_forward.c b/source/blender/draw/engines/workbench/workbench_forward.c
index 26c4b920382..eccf2b1a0f0 100644
--- a/source/blender/draw/engines/workbench/workbench_forward.c
+++ b/source/blender/draw/engines/workbench/workbench_forward.c
@@ -29,9 +29,10 @@
 #include "BLI_string_utils.h"
 #include "BLI_utildefines.h"
 
-#include "BKE_particle.h"
 #inclu

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list