[Bf-blender-cvs] [7878adf49cf] master: DrawManager: Disable Clipping in material/rendered mode

Jeroen Bakker noreply at git.blender.org
Wed Dec 11 16:58:44 CET 2019


Commit: 7878adf49cfff6ccbb18203f21c6355a518b34db
Author: Jeroen Bakker
Date:   Tue Dec 10 15:18:16 2019 +0100
Branches: master
https://developer.blender.org/rB7878adf49cfff6ccbb18203f21c6355a518b34db

DrawManager: Disable Clipping in material/rendered mode

Viewport: Disable Clipping For EEVEE and External Renderers

Currently it is possible that, when using viewport clipping, the display and tools communicate
different information to the user then the renderer does. The reason is
that the renderer does not support viewport clipping. Both EEVEE and
Cycles do not support it.

This patch will disable the clipping in all the tools and drawing code
when the viewport drawing mode is `Material Preview` or `Rendered`.

This patch introduces a `RV3D_CLIPPING_ENABLED` util that checks if
clipping is enabled for the given `rv3d` and `v3d`. Also in places where
it was needed we added the `ViewContext` as a carrier for the `View3D`
and `RegionView3D`.

There are a few areas in the tooling (select, projection painting) that
still needs to be tackled after this patch.

Reviewed By: fclem

Differential Revision: https://developer.blender.org/D6047

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

M	source/blender/blenkernel/BKE_paint.h
M	source/blender/draw/DRW_engine.h
M	source/blender/draw/engines/overlay/overlay_engine.c
M	source/blender/draw/engines/workbench/workbench_data.c
M	source/blender/draw/engines/workbench/workbench_deferred.c
M	source/blender/draw/engines/workbench/workbench_forward.c
M	source/blender/draw/intern/draw_manager.c
M	source/blender/draw/intern/draw_manager_text.c
M	source/blender/draw/intern/draw_manager_text.h
M	source/blender/editors/mesh/editmesh_knife.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/editors/space_view3d/view3d_draw_legacy.c
M	source/blender/editors/space_view3d/view3d_view.c
M	source/blender/makesdna/DNA_view3d_types.h

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

diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 536268c067e..fdd3bd7cd86 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -265,7 +265,10 @@ typedef struct SculptSession {
   float cursor_location[3];
   float cursor_normal[3];
   float cursor_view_normal[3];
+
+  /* TODO(jbakker): Replace rv3d adn v3d with ViewContext */
   struct RegionView3D *rv3d;
+  struct View3D *v3d;
 
   /* Dynamic mesh preview */
   int *preview_vert_index_list;
diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h
index 5edfadd7f41..b9e7908b3ef 100644
--- a/source/blender/draw/DRW_engine.h
+++ b/source/blender/draw/DRW_engine.h
@@ -134,6 +134,7 @@ void DRW_draw_depth_loop_gpencil(struct Depsgraph *depsgraph,
                                  struct View3D *v3d,
                                  struct GPUViewport *viewport);
 void DRW_draw_depth_object(struct ARegion *ar,
+                           struct View3D *v3d,
                            struct GPUViewport *viewport,
                            struct Object *object);
 void DRW_draw_select_id(struct Depsgraph *depsgraph,
diff --git a/source/blender/draw/engines/overlay/overlay_engine.c b/source/blender/draw/engines/overlay/overlay_engine.c
index 41d099772ee..06044ff92b3 100644
--- a/source/blender/draw/engines/overlay/overlay_engine.c
+++ b/source/blender/draw/engines/overlay/overlay_engine.c
@@ -74,7 +74,7 @@ static void OVERLAY_engine_init(void *vedata)
   }
 
   pd->wireframe_mode = (v3d->shading.type == OB_WIRE);
-  pd->clipping_state = (rv3d->rflag & RV3D_CLIPPING) ? DRW_STATE_CLIP_PLANES : 0;
+  pd->clipping_state = RV3D_CLIPPING_ENABLED(v3d, rv3d) ? DRW_STATE_CLIP_PLANES : 0;
   pd->xray_enabled = XRAY_ACTIVE(v3d);
   pd->xray_enabled_and_not_wire = pd->xray_enabled && v3d->shading.type > OB_WIRE;
   pd->clear_in_front = (v3d->shading.type != OB_SOLID);
diff --git a/source/blender/draw/engines/workbench/workbench_data.c b/source/blender/draw/engines/workbench/workbench_data.c
index 42375f29d4d..f07b21ebcc2 100644
--- a/source/blender/draw/engines/workbench/workbench_data.c
+++ b/source/blender/draw/engines/workbench/workbench_data.c
@@ -116,6 +116,8 @@ void workbench_private_data_init(WORKBENCH_PrivateData *wpd)
   wpd->preferences = &U;
 
   View3D *v3d = draw_ctx->v3d;
+  RegionView3D *rv3d = draw_ctx->rv3d;
+
   if (!v3d || (v3d->shading.type == OB_RENDER && BKE_scene_uses_blender_workbench(scene))) {
     wpd->shading = scene->display.shading;
     wpd->shading.xray_alpha = XRAY_ALPHA((&scene->display));
@@ -193,22 +195,19 @@ void workbench_private_data_init(WORKBENCH_PrivateData *wpd)
   wd->curvature_valley = 0.7f / max_ff(SQUARE(wpd->shading.curvature_valley_factor), 1e-4f);
 
   /* Will be NULL when rendering. */
-  if (draw_ctx->rv3d != NULL) {
-    RegionView3D *rv3d = draw_ctx->rv3d;
-    if (rv3d->rflag & RV3D_CLIPPING) {
-      wpd->world_clip_planes = rv3d->clip;
-      UI_GetThemeColor4fv(TH_V3D_CLIPPING_BORDER, wpd->world_clip_planes_color);
-      if (wpd->use_color_management) {
-        srgb_to_linearrgb_v3_v3(wpd->world_clip_planes_color, wpd->world_clip_planes_color);
-      }
-      else {
-        copy_v3_v3(wpd->world_clip_planes_color, wpd->world_clip_planes_color);
-      }
+  if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
+    wpd->world_clip_planes = rv3d->clip;
+    UI_GetThemeColor4fv(TH_V3D_CLIPPING_BORDER, wpd->world_clip_planes_color);
+    if (wpd->use_color_management) {
+      srgb_to_linearrgb_v3_v3(wpd->world_clip_planes_color, wpd->world_clip_planes_color);
     }
     else {
-      wpd->world_clip_planes = NULL;
+      copy_v3_v3(wpd->world_clip_planes_color, wpd->world_clip_planes_color);
     }
   }
+  else {
+    wpd->world_clip_planes = NULL;
+  }
 
   workbench_world_data_update_shadow_direction_vs(wpd);
   workbench_world_data_ubo_ensure(scene, wpd);
diff --git a/source/blender/draw/engines/workbench/workbench_deferred.c b/source/blender/draw/engines/workbench/workbench_deferred.c
index da5ab0c3122..8e61750da38 100644
--- a/source/blender/draw/engines/workbench/workbench_deferred.c
+++ b/source/blender/draw/engines/workbench/workbench_deferred.c
@@ -716,7 +716,7 @@ void workbench_deferred_cache_init(WORKBENCH_Data *vedata)
     }
     DRW_shgroup_call(grp, DRW_cache_fullscreen_quad_get(), NULL);
 
-    if (draw_ctx->rv3d && (draw_ctx->rv3d->rflag & RV3D_CLIPPING) && draw_ctx->rv3d->clipbb) {
+    if (RV3D_CLIPPING_ENABLED(draw_ctx->v3d, draw_ctx->rv3d)) {
       GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR_BACKGROUND);
       grp = DRW_shgroup_create(shader, psl->background_pass);
       wpd->world_clip_planes_batch = DRW_draw_background_clipping_batch_from_rv3d(draw_ctx->rv3d);
diff --git a/source/blender/draw/engines/workbench/workbench_forward.c b/source/blender/draw/engines/workbench/workbench_forward.c
index 87f3b28c665..dbd7ebfe0d1 100644
--- a/source/blender/draw/engines/workbench/workbench_forward.c
+++ b/source/blender/draw/engines/workbench/workbench_forward.c
@@ -421,7 +421,7 @@ void workbench_forward_engine_init(WORKBENCH_Data *vedata)
   /* TODO(campbell): displays but masks geometry,
    * only use with wire or solid-without-xray for now. */
   if ((wpd->shading.type != OB_WIRE && !XRAY_FLAG_ENABLED(wpd)) &&
-      (draw_ctx->rv3d && (draw_ctx->rv3d->rflag & RV3D_CLIPPING) && draw_ctx->rv3d->clipbb)) {
+      RV3D_CLIPPING_ENABLED(draw_ctx->v3d, draw_ctx->rv3d)) {
     psl->background_pass = DRW_pass_create("Background",
                                            DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL);
     GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR_BACKGROUND);
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 4bfae75848b..5832db31c4e 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -584,7 +584,7 @@ static void drw_context_state_init(void)
   }
 
   DST.draw_ctx.sh_cfg = GPU_SHADER_CFG_DEFAULT;
-  if (DST.draw_ctx.rv3d && DST.draw_ctx.rv3d->rflag & RV3D_CLIPPING) {
+  if (RV3D_CLIPPING_ENABLED(DST.draw_ctx.v3d, DST.draw_ctx.rv3d)) {
     DST.draw_ctx.sh_cfg = GPU_SHADER_CFG_CLIPPED;
   }
 }
@@ -1235,7 +1235,7 @@ static void drw_engines_draw_text(void)
     PROFILE_START(stime);
 
     if (data->text_draw_cache) {
-      DRW_text_cache_draw(data->text_draw_cache, DST.draw_ctx.ar);
+      DRW_text_cache_draw(data->text_draw_cache, DST.draw_ctx.ar, DST.draw_ctx.v3d);
     }
 
     PROFILE_END_UPDATE(data->render_time, stime);
@@ -2571,7 +2571,7 @@ static void draw_world_clip_planes_from_rv3d(GPUBatch *batch, const float world_
 /**
  * Clears the Depth Buffer and draws only the specified object.
  */
-void DRW_draw_depth_object(ARegion *ar, GPUViewport *viewport, Object *object)
+void DRW_draw_depth_object(ARegion *ar, View3D *v3d, GPUViewport *viewport, Object *object)
 {
   RegionView3D *rv3d = ar->regiondata;
 
@@ -2588,7 +2588,7 @@ void DRW_draw_depth_object(ARegion *ar, GPUViewport *viewport, Object *object)
   GPU_depth_test(true);
 
   const float(*world_clip_planes)[4] = NULL;
-  if (rv3d->rflag & RV3D_CLIPPING) {
+  if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
     ED_view3d_clipping_set(rv3d);
     ED_view3d_clipping_local(rv3d, object->obmat);
     world_clip_planes = rv3d->clip_local;
@@ -2625,7 +2625,7 @@ void DRW_draw_depth_object(ARegion *ar, GPUViewport *viewport, Object *object)
       break;
   }
 
-  if (rv3d->rflag & RV3D_CLIPPING) {
+  if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
     ED_view3d_clipping_disable();
   }
 
diff --git a/source/blender/draw/intern/draw_manager_text.c b/source/blender/draw/intern/draw_manager_text.c
index b6dab0b2077..9462a0d8072 100644
--- a/source/blender/draw/intern/draw_manager_text.c
+++ b/source/blender/draw/intern/draw_manager_text.c
@@ -119,7 +119,7 @@ void DRW_text_cache_add(DRWTextStore *dt,
   }
 }
 
-void DRW_text_cache_draw(DRWTextStore *dt, ARegion *ar)
+void DRW_text_cache_draw(DRWTextStore *dt, ARegion *ar, struct View3D *v3d)
 {
   RegionView3D *rv3d = ar->regiondata;
   ViewCachedString *vos;
@@ -147,7 +147,7 @@ void DRW_text_cache_draw(DRWTextStore *dt, ARegion *ar)
   if (tot) {
     int col_pack_prev = 0;
 
-    if (rv3d->rflag & RV3D_CLIPPING) {
+    if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
       ED_view3d_clipping_disable();
     }
 
@@ -185,7 +185,7 @@ void DRW_text_cache_draw(DRWTextStore *dt, ARegion *ar)
     GPU_matrix_pop();
     GPU_matrix_projection_set(original_proj);
 
-    if (rv3d->rflag & RV3D_CLIPPING) {
+    if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
       ED_view3d_clipping_enable();
     }
   }
diff --git a/source/blender/draw/intern/draw_manager_text.h b/source/blender/draw/intern/draw_manager_text.h
index 5e9692ff490..a8eb45ee8f5 100644
--- a/source/blender/draw/intern/draw_manager_text.h
+++ b/source/blender/draw/intern/draw_manager_text.h
@@ -41,7 +41,7 @@ void DRW_text_cache_add(struct DRWTextStore *dt,
                         short flag,
                         const uchar col[4]);
 
-void DRW_text_cache_draw(struct DRWTextStore *dt, struct ARegion *ar);
+void DRW_text_cache_draw(struct DRWTextStore *dt, struct ARegion *ar, struct View3D *v3d);
 
 void DRW_text_edit_mesh_measure_stats(struct ARegion *ar,
                                       struct View3D *v3d,
diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c
index 1adbbe30286..4c4aa4214b2 100644
--- a/source/blender/editors/mesh/editmesh_knife.c
+++ b/source/blender/editors/mesh/editmesh_knife.c
@@ -1460,7 +1460,8 @@ static bool point_is_visible(KnifeTool_OpData *kcd,
   BMFace *f_hit;
 
   /* If box clipping on, make sure p is not clipped */
-  if (kcd->vc.rv3d->rflag & RV3D_CLIPPING && ED_view3d_clipping_test(kcd->vc.rv3d, p, true)) {
+  if (RV3D_CLIPPING_ENABLED(kcd->vc.v3d, kcd->vc.rv3d) &&
+      ED_view3d_clipping_test(kcd->vc.rv3d, p, true)) {
     return false;
   }
 
@@ -1484,7 +1485,7 @@ static bool point_is_visible(KnifeTool_OpData *kcd,
       dist = kcd->vc.v3d->clip_end * 2.0f;
     }
 
-    if (kcd->vc.rv3d->rflag & RV3D_CLIPPING) {
+    i

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list