Fix #120778: depth navigation ignores camera & light objects

Restore overlay depth drawing which was removed in [0].
For viewport navigation this is useful. Disable overlays
for other operations such as painting & object placement.

Also disable color drawing in the overlay_next engine drawing
when drawing depth, since it caused the viewport to show a
checkered backdrop.

Details:

A boolean argument has been added to ED_view3d_depth_override instead
of new enums in eV3DDepthOverrideMode since mixing object-filtering
and draw-type in the one enum gets verbose & awkward, where most
existing enums would have needed to include NO_OVERLAY in their name.

V3D_DEPTH_NO_OVERLAYS has been renamed to V3D_DEPTH_ALL,
the caller must pass in use_overlay as false.

[0]: 5fea1eda36
This commit is contained in:
Campbell Barton
2024-12-02 22:01:14 +11:00
parent d0eff5f665
commit ababc2e01b
16 changed files with 64 additions and 29 deletions

View File

@@ -564,7 +564,8 @@ void Instance::draw_v3d(Manager &manager, View &view)
origins.draw_color_only(resources.overlay_color_only_fb, manager, view);
}
{
if (state.is_depth_only_drawing == false) {
/* Output pass. */
GPU_framebuffer_bind(resources.overlay_output_fb);
GPU_framebuffer_clear_color(resources.overlay_output_fb, clear_color);

View File

@@ -1108,13 +1108,18 @@ static int curve_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event)
/* needed or else the draw matrix can be incorrect */
view3d_operator_needs_opengl(C);
eV3DDepthOverrideMode depth_mode = V3D_DEPTH_NO_OVERLAYS;
eV3DDepthOverrideMode depth_mode = V3D_DEPTH_ALL;
if (cps->flag & CURVE_PAINT_FLAG_DEPTH_ONLY_SELECTED) {
depth_mode = V3D_DEPTH_SELECTED_ONLY;
}
ED_view3d_depth_override(
cdd->vc.depsgraph, cdd->vc.region, cdd->vc.v3d, nullptr, depth_mode, &cdd->depths);
ED_view3d_depth_override(cdd->vc.depsgraph,
cdd->vc.region,
cdd->vc.v3d,
nullptr,
depth_mode,
false,
&cdd->depths);
if (cdd->depths != nullptr) {
cdd->project.use_depth = true;

View File

@@ -1091,13 +1091,18 @@ static int curves_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event)
/* needed or else the draw matrix can be incorrect */
view3d_operator_needs_opengl(C);
eV3DDepthOverrideMode depth_mode = V3D_DEPTH_NO_OVERLAYS;
eV3DDepthOverrideMode depth_mode = V3D_DEPTH_ALL;
if (cps->flag & CURVE_PAINT_FLAG_DEPTH_ONLY_SELECTED) {
depth_mode = V3D_DEPTH_SELECTED_ONLY;
}
ED_view3d_depth_override(
cdd->vc.depsgraph, cdd->vc.region, cdd->vc.v3d, nullptr, depth_mode, &cdd->depths);
ED_view3d_depth_override(cdd->vc.depsgraph,
cdd->vc.region,
cdd->vc.v3d,
nullptr,
depth_mode,
false,
&cdd->depths);
if (cdd->depths != nullptr) {
cdd->project.use_depth = true;

View File

@@ -658,12 +658,12 @@ static short annotation_stroke_addpoint(tGPsdata *p,
mode = V3D_DEPTH_SELECTED_ONLY;
}
else {
mode = V3D_DEPTH_NO_OVERLAYS;
mode = V3D_DEPTH_ALL;
}
}
view3d_region_operator_needs_opengl(p->win, p->region);
ED_view3d_depth_override(p->depsgraph, p->region, v3d, nullptr, mode, nullptr);
ED_view3d_depth_override(p->depsgraph, p->region, v3d, nullptr, mode, false, nullptr);
}
/* convert screen-coordinates to appropriate coordinates (and store them) */
@@ -1226,7 +1226,7 @@ static void annotation_stroke_doeraser(tGPsdata *p)
View3D *v3d = static_cast<View3D *>(p->area->spacedata.first);
view3d_region_operator_needs_opengl(p->win, p->region);
ED_view3d_depth_override(
p->depsgraph, p->region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, &p->depths);
p->depsgraph, p->region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, false, &p->depths);
}
}
@@ -1690,13 +1690,13 @@ static void annotation_paint_strokeend(tGPsdata *p)
mode = V3D_DEPTH_SELECTED_ONLY;
}
else {
mode = V3D_DEPTH_NO_OVERLAYS;
mode = V3D_DEPTH_ALL;
}
}
/* need to restore the original projection settings before packing up */
view3d_region_operator_needs_opengl(p->win, p->region);
ED_view3d_depth_override(
p->depsgraph, p->region, v3d, nullptr, mode, is_eraser ? nullptr : &p->depths);
p->depsgraph, p->region, v3d, nullptr, mode, false, is_eraser ? nullptr : &p->depths);
}
/* check if doing eraser or not */

View File

@@ -2835,7 +2835,8 @@ static int grease_pencil_reproject_exec(bContext *C, wmOperator *op)
ViewDepths *view_depths = nullptr;
if (mode == ReprojectMode::Surface) {
ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, &view_depths);
ED_view3d_depth_override(
depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, false, &view_depths);
}
const bke::AttrDomain selection_domain = ED_grease_pencil_edit_selection_domain_get(

View File

@@ -288,7 +288,7 @@ void DrawingPlacement::cache_viewport_depths(Depsgraph *depsgraph, ARegion *regi
mode = V3D_DEPTH_NO_GPENCIL;
}
}
ED_view3d_depth_override(depsgraph, region, view3d, nullptr, mode, &this->depth_cache_);
ED_view3d_depth_override(depsgraph, region, view3d, nullptr, mode, false, &this->depth_cache_);
}
void DrawingPlacement::set_origin_to_nearest_stroke(const float2 co)

View File

@@ -182,8 +182,8 @@ void ED_view3d_lastview_store(RegionView3D *rv3d);
/* Depth buffer */
enum eV3DDepthOverrideMode {
/** Redraw viewport without overlays. */
V3D_DEPTH_NO_OVERLAYS = 0,
/** Redraw viewport with all objects. */
V3D_DEPTH_ALL = 0,
/** Redraw viewport without Grease Pencil. */
V3D_DEPTH_NO_GPENCIL,
/** Redraw viewport with Grease Pencil only. */
@@ -198,12 +198,21 @@ enum eV3DDepthOverrideMode {
* Redraw the viewport depth buffer.
* Call #ED_view3d_has_depth_buffer_updated if you want to check if the viewport already has depth
* buffer updated.
*
* \param use_overlay: When enabled and the `v3d` has overlays enabled, show overlays.
* A rule of thumb for this value is:
* - For viewport navigation the value should be true.
* Since the user may want to inspect non-geometry contents of their scene.
* - For painting and other tools, the value should be false.
* Since it's not typically desirable to paint onto the cameras frame or spot-light,
* nor use these depths for object placement.
*/
void ED_view3d_depth_override(Depsgraph *depsgraph,
ARegion *region,
View3D *v3d,
Object *obact,
eV3DDepthOverrideMode mode,
bool use_overlay,
ViewDepths **r_depths);
void ED_view3d_depths_free(ViewDepths *depths);
bool ED_view3d_depth_read_cached(const ViewDepths *vd,

View File

@@ -268,7 +268,8 @@ static void depthdropper_depth_sample_pt(bContext *C,
view3d_operator_needs_opengl(C);
/* Ensure the depth buffer is updated for #ED_view3d_autodist. */
ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, nullptr);
ED_view3d_depth_override(
depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, false, nullptr);
if (ED_view3d_autodist(region, v3d, mval, co, nullptr)) {
const float mval_center_fl[2] = {float(region->winx) / 2, float(region->winy) / 2};

View File

@@ -2089,7 +2089,7 @@ static int object_transform_axis_target_invoke(bContext *C, wmOperator *op, cons
ViewDepths *depths = nullptr;
ED_view3d_depth_override(
vc.depsgraph, vc.region, vc.v3d, nullptr, V3D_DEPTH_NO_GPENCIL, &depths);
vc.depsgraph, vc.region, vc.v3d, nullptr, V3D_DEPTH_NO_GPENCIL, false, &depths);
#ifdef USE_RENDER_OVERRIDE
vc.v3d->flag2 = flag2_prev;

View File

@@ -524,6 +524,7 @@ static void PE_set_view3d_data(bContext *C, PEData *data)
data->vc.v3d,
data->vc.obact,
V3D_DEPTH_OBJECT_ONLY,
false,
&data->depths);
}
}

View File

@@ -5813,7 +5813,8 @@ void paint_proj_stroke(const bContext *C,
view3d_operator_needs_opengl(C);
/* Ensure the depth buffer is updated for #ED_view3d_autodist. */
ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, nullptr);
ED_view3d_depth_override(
depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, false, nullptr);
if (!ED_view3d_autodist(region, v3d, mval_i, cursor, nullptr)) {
return;

View File

@@ -2378,6 +2378,7 @@ void ED_view3d_depth_override(Depsgraph *depsgraph,
View3D *v3d,
Object *obact,
eV3DDepthOverrideMode mode,
bool use_overlay,
ViewDepths **r_depths)
{
if (v3d->runtime.flag & V3D_RUNTIME_DEPTHBUF_OVERRIDDEN) {
@@ -2395,6 +2396,10 @@ void ED_view3d_depth_override(Depsgraph *depsgraph,
/* Setting these temporarily is not nice */
v3d->flag &= ~V3D_SELECT_OUTLINE;
if (v3d->flag2 & V3D_HIDE_OVERLAYS) {
use_overlay = false;
}
/* Tools may request depth outside of regular drawing code. */
UI_Theme_Store(&theme_state);
UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW);
@@ -2421,21 +2426,21 @@ void ED_view3d_depth_override(Depsgraph *depsgraph,
* yet available. */
if (viewport != nullptr) {
switch (mode) {
case V3D_DEPTH_NO_OVERLAYS:
DRW_draw_depth_loop(depsgraph, region, v3d, viewport, true, true, false, false);
case V3D_DEPTH_ALL:
DRW_draw_depth_loop(depsgraph, region, v3d, viewport, true, true, use_overlay, false);
break;
case V3D_DEPTH_NO_GPENCIL:
DRW_draw_depth_loop(depsgraph, region, v3d, viewport, false, true, false, false);
DRW_draw_depth_loop(depsgraph, region, v3d, viewport, false, true, use_overlay, false);
break;
case V3D_DEPTH_GPENCIL_ONLY:
DRW_draw_depth_loop(depsgraph, region, v3d, viewport, true, false, false, false);
DRW_draw_depth_loop(depsgraph, region, v3d, viewport, true, false, use_overlay, false);
break;
case V3D_DEPTH_OBJECT_ONLY:
DRW_draw_depth_object(
scene, region, v3d, viewport, DEG_get_evaluated_object(depsgraph, obact));
break;
case V3D_DEPTH_SELECTED_ONLY:
DRW_draw_depth_loop(depsgraph, region, v3d, viewport, false, true, false, true);
DRW_draw_depth_loop(depsgraph, region, v3d, viewport, false, true, use_overlay, true);
break;
}

View File

@@ -854,7 +854,7 @@ void ED_view3d_cursor3d_position(bContext *C,
view3d_operator_needs_opengl(C);
/* Ensure the depth buffer is updated for #ED_view3d_autodist. */
ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_OVERLAYS, nullptr);
ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_ALL, false, nullptr);
if (ED_view3d_autodist(region, v3d, mval, r_cursor_co, nullptr)) {
depth_used = true;

View File

@@ -207,7 +207,8 @@ static eViewOpsFlag navigate_pivot_get(bContext *C,
negate_v3_v3(fallback_depth_pt, static_cast<RegionView3D *>(region->regiondata)->ofs);
if (!ED_view3d_has_depth_buffer_updated(depsgraph, v3d)) {
ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, nullptr);
ED_view3d_depth_override(
depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, true, nullptr);
}
const bool is_set = ED_view3d_autodist(region, v3d, event->mval, r_pivot, fallback_depth_pt);

View File

@@ -38,7 +38,7 @@ static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *ev
view3d_operator_needs_opengl(C);
/* Ensure the depth buffer is updated for #ED_view3d_autodist. */
ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, nullptr);
ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, true, nullptr);
if (ED_view3d_autodist(region, v3d, event->mval, new_ofs, nullptr)) {
/* pass */

View File

@@ -58,8 +58,13 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
ED_view3d_dist_range_get(v3d, dist_range);
ED_view3d_depth_override(
CTX_data_ensure_evaluated_depsgraph(C), region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, nullptr);
ED_view3d_depth_override(CTX_data_ensure_evaluated_depsgraph(C),
region,
v3d,
nullptr,
V3D_DEPTH_NO_GPENCIL,
true,
nullptr);
{
/* avoid allocating the whole depth buffer */
ViewDepths depth_temp = {0};