diff --git a/source/blender/editors/include/ED_view3d.hh b/source/blender/editors/include/ED_view3d.hh index bfc0a58b627..e501a4f5b68 100644 --- a/source/blender/editors/include/ED_view3d.hh +++ b/source/blender/editors/include/ED_view3d.hh @@ -188,6 +188,8 @@ enum eV3DDepthOverrideMode { }; /** * Redraw the viewport depth buffer. + * Call #view3d_has_depth_buffer_being_used if you want to check if the viewport already has depth + * buffer updated. */ void ED_view3d_depth_override(Depsgraph *depsgraph, ARegion *region, @@ -209,6 +211,8 @@ bool ED_view3d_depth_unproject_v3(const ARegion *region, double depth, float r_location_world[3]); +bool view3d_has_depth_buffer_being_used(const Depsgraph *depsgraph, const View3D *v3d); + /** * Utilities to perform navigation. * Call `ED_view3d_navigation_init` to create a context and `ED_view3d_navigation_do` to perform @@ -850,18 +854,16 @@ void ED_view3d_autodist_last_clear(wmWindow *win); /** * Get the world-space 3d location from a screen-space 2d point. - * TODO: Implement #alphaoverride. We don't want to zoom into billboards. + * It may be useful to call #ED_view3d_depth_override before. * * \param mval: Input screen-space pixel location. * \param mouse_worldloc: Output world-space location. * \param fallback_depth_pt: Use this points depth when no depth can be found. */ -bool ED_view3d_autodist(Depsgraph *depsgraph, - ARegion *region, +bool ED_view3d_autodist(ARegion *region, View3D *v3d, const int mval[2], float mouse_worldloc[3], - bool alphaoverride, const float fallback_depth_pt[3]); /** diff --git a/source/blender/editors/interface/eyedroppers/eyedropper_depth.cc b/source/blender/editors/interface/eyedroppers/eyedropper_depth.cc index 6c2f346a33e..653b9c43339 100644 --- a/source/blender/editors/interface/eyedroppers/eyedropper_depth.cc +++ b/source/blender/editors/interface/eyedroppers/eyedropper_depth.cc @@ -179,7 +179,10 @@ static void depthdropper_depth_sample_pt(bContext *C, view3d_operator_needs_opengl(C); - if (ED_view3d_autodist(depsgraph, region, v3d, mval, co, true, nullptr)) { + /* Ensure the depth buffer is updated for #ED_view3d_autodist. */ + ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, nullptr); + + if (ED_view3d_autodist(region, v3d, mval, co, nullptr)) { const float mval_center_fl[2] = {float(region->winx) / 2, float(region->winy) / 2}; float co_align[3]; diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.cc b/source/blender/editors/sculpt_paint/paint_image_proj.cc index 90212404e0d..01611d33c83 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.cc +++ b/source/blender/editors/sculpt_paint/paint_image_proj.cc @@ -5800,7 +5800,10 @@ void paint_proj_stroke(const bContext *C, view3d_operator_needs_opengl(C); - if (!ED_view3d_autodist(depsgraph, region, v3d, mval_i, cursor, false, nullptr)) { + /* Ensure the depth buffer is updated for #ED_view3d_autodist. */ + ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, nullptr); + + if (!ED_view3d_autodist(region, v3d, mval_i, cursor, nullptr)) { return; } diff --git a/source/blender/editors/space_view3d/view3d_draw.cc b/source/blender/editors/space_view3d/view3d_draw.cc index 2df66e2fd4d..5ff5a14de6b 100644 --- a/source/blender/editors/space_view3d/view3d_draw.cc +++ b/source/blender/editors/space_view3d/view3d_draw.cc @@ -2440,6 +2440,28 @@ void ED_view3d_depths_free(ViewDepths *depths) MEM_freeN(depths); } +bool ED_view3d_has_depth_buffer_being_used(const Depsgraph *depsgraph, const View3D *v3d) +{ + const char *engine_name = DEG_get_evaluated_scene(depsgraph)->r.engine; + RenderEngineType *engine_type = RE_engines_find(engine_name); + + bool is_viewport_wire_no_xray = v3d->shading.type < OB_SOLID && !XRAY_ENABLED(v3d); + bool is_viewport_preview_solid = v3d->shading.type == OB_SOLID; + bool is_viewport_preview_material = v3d->shading.type == OB_MATERIAL; + bool is_viewport_render_eevee = v3d->shading.type == OB_RENDER && + (STREQ(engine_name, RE_engine_id_BLENDER_EEVEE) || + STREQ(engine_name, RE_engine_id_BLENDER_EEVEE_NEXT)); + bool is_viewport_render_workbench = v3d->shading.type == OB_RENDER && + STREQ(engine_name, RE_engine_id_BLENDER_WORKBENCH); + bool is_viewport_render_external_with_overlay = v3d->shading.type == OB_RENDER && + !(engine_type->flag & RE_INTERNAL) && + !(v3d->flag2 & V3D_HIDE_OVERLAYS); + + return is_viewport_preview_solid || is_viewport_preview_material || is_viewport_wire_no_xray || + is_viewport_render_eevee || is_viewport_render_workbench || + is_viewport_render_external_with_overlay; +} + /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/editors/space_view3d/view3d_edit.cc b/source/blender/editors/space_view3d/view3d_edit.cc index e2769eff861..008e17e6d49 100644 --- a/source/blender/editors/space_view3d/view3d_edit.cc +++ b/source/blender/editors/space_view3d/view3d_edit.cc @@ -854,7 +854,11 @@ void ED_view3d_cursor3d_position(bContext *C, Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); view3d_operator_needs_opengl(C); - if (ED_view3d_autodist(depsgraph, region, v3d, mval, cursor_co, true, nullptr)) { + + /* Ensure the depth buffer is updated for #ED_view3d_autodist. */ + ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, nullptr); + + if (ED_view3d_autodist(region, v3d, mval, cursor_co, nullptr)) { depth_used = true; } } diff --git a/source/blender/editors/space_view3d/view3d_navigate.cc b/source/blender/editors/space_view3d/view3d_navigate.cc index b4e9e95cd82..1923a93ea02 100644 --- a/source/blender/editors/space_view3d/view3d_navigate.cc +++ b/source/blender/editors/space_view3d/view3d_navigate.cc @@ -8,19 +8,15 @@ #include "DNA_curve_types.h" -#include "MEM_guardedalloc.h" - #include "BLI_math_geom.h" #include "BLI_math_matrix.h" #include "BLI_math_rotation.h" -#include "BLI_math_vector.h" #include "BLI_math_vector.hh" #include "BLI_rect.h" #include "BKE_context.hh" #include "BKE_layer.hh" #include "BKE_object.hh" -#include "BKE_object_types.hh" #include "BKE_paint.hh" #include "BKE_vfont.hh" @@ -210,8 +206,11 @@ static eViewOpsFlag navigate_pivot_get(bContext *C, float fallback_depth_pt[3]; negate_v3_v3(fallback_depth_pt, static_cast(region->regiondata)->ofs); - const bool is_set = ED_view3d_autodist( - depsgraph, region, v3d, event->mval, r_pivot, true, fallback_depth_pt); + if (!ED_view3d_has_depth_buffer_being_used(depsgraph, v3d)) { + ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, nullptr); + } + + const bool is_set = ED_view3d_autodist(region, v3d, event->mval, r_pivot, fallback_depth_pt); ED_view3d_autodist_last_set(win, event, r_pivot, is_set); } diff --git a/source/blender/editors/space_view3d/view3d_navigate_view_center_pick.cc b/source/blender/editors/space_view3d/view3d_navigate_view_center_pick.cc index 91c5f994b10..d6b04633fef 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_view_center_pick.cc +++ b/source/blender/editors/space_view3d/view3d_navigate_view_center_pick.cc @@ -37,7 +37,10 @@ static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *ev view3d_operator_needs_opengl(C); - if (ED_view3d_autodist(depsgraph, region, v3d, event->mval, new_ofs, false, nullptr)) { + /* Ensure the depth buffer is updated for #ED_view3d_autodist. */ + ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, nullptr); + + if (ED_view3d_autodist(region, v3d, event->mval, new_ofs, nullptr)) { /* pass */ } else { diff --git a/source/blender/editors/space_view3d/view3d_utils.cc b/source/blender/editors/space_view3d/view3d_utils.cc index 742487dd290..521ef1f8c6c 100644 --- a/source/blender/editors/space_view3d/view3d_utils.cc +++ b/source/blender/editors/space_view3d/view3d_utils.cc @@ -1101,21 +1101,16 @@ static float view_autodist_depth_margin(ARegion *region, const int mval[2], int return depth_close; } -bool ED_view3d_autodist(Depsgraph *depsgraph, - ARegion *region, +bool ED_view3d_autodist(ARegion *region, View3D *v3d, const int mval[2], float mouse_worldloc[3], - const bool /*alphaoverride*/, const float fallback_depth_pt[3]) { float depth_close; int margin_arr[] = {0, 2, 4}; bool depth_ok = false; - /* Get Z Depths, needed for perspective, nice for ortho */ - ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, nullptr); - /* Attempt with low margin's first */ int i = 0; do {