Fix T93360: 'Iteractive Light Track' do not work over empty background

Bug introduced in {rBaa0ac0035a0d}.

The invalid depth fallback was changed to `FLT_MAX` in order to match the
annotation and gpencil operations.

This broke the `Interactive Light Track` operator which invalidates the
operation if the depth value is `1.0f`.

The chosen solution was to change the value tested in the annotation and
gpencil operations.
This commit is contained in:
Germano Cavalcante 2021-11-25 10:17:31 -03:00
parent 447378753d
commit bc4c20d414
Notes: blender-bot 2023-02-14 01:35:49 +01:00
Referenced by issue #93360, Regresion: Shift+t aiming with light source do not work over empty background
7 changed files with 33 additions and 20 deletions

View File

@ -78,6 +78,8 @@
/* ******************************************* */
/* 'Globals' and Defines */
#define DEPTH_INVALID 1.0f
/* values for tGPsdata->status */
typedef enum eGPencil_PaintStatus {
GP_STATUS_IDLING = 0, /* stroke isn't in progress yet */
@ -324,6 +326,9 @@ static void annotation_stroke_convertcoords(tGPsdata *p,
float *depth)
{
bGPdata *gpd = p->gpd;
if (depth && (*depth == DEPTH_INVALID)) {
depth = NULL;
}
/* in 3d-space - pt->x/y/z are 3 side-by-side floats */
if (gpd->runtime.sbuffer_sflag & GP_STROKE_3DSPACE) {
@ -1003,14 +1008,14 @@ static void annotation_stroke_newfrombuffer(tGPsdata *p)
int last_valid = 0;
for (i = 0; i < gpd->runtime.sbuffer_used; i++) {
if (depth_arr[i] != FLT_MAX) {
if (depth_arr[i] != DEPTH_INVALID) {
break;
}
}
first_valid = i;
for (i = gpd->runtime.sbuffer_used - 1; i >= 0; i--) {
if (depth_arr[i] != FLT_MAX) {
if (depth_arr[i] != DEPTH_INVALID) {
break;
}
}
@ -1018,14 +1023,14 @@ static void annotation_stroke_newfrombuffer(tGPsdata *p)
/* invalidate non-endpoints, so only blend between first and last */
for (i = first_valid + 1; i < last_valid; i++) {
depth_arr[i] = FLT_MAX;
depth_arr[i] = DEPTH_INVALID;
}
interp_depth = true;
}
if (interp_depth) {
interp_sparse_array(depth_arr, gpd->runtime.sbuffer_used, FLT_MAX);
interp_sparse_array(depth_arr, gpd->runtime.sbuffer_used, DEPTH_INVALID);
}
}
}

View File

@ -1415,7 +1415,7 @@ static void gpencil_get_depth_array(tGPDfill *tgpf)
}
else {
if (interp_depth) {
interp_sparse_array(tgpf->depth_arr, totpoints, FLT_MAX);
interp_sparse_array(tgpf->depth_arr, totpoints, DEPTH_INVALID);
}
}
}

View File

@ -27,6 +27,8 @@
#include "ED_numinput.h"
#define DEPTH_INVALID 1.0f
/* internal exports only */
struct Material;
struct bGPDspoint;

View File

@ -429,6 +429,9 @@ static void gpencil_stroke_convertcoords(tGPsdata *p,
float *depth)
{
bGPdata *gpd = p->gpd;
if (depth && (*depth == DEPTH_INVALID)) {
depth = NULL;
}
/* in 3d-space - pt->x/y/z are 3 side-by-side floats */
if (gpd->runtime.sbuffer_sflag & GP_STROKE_3DSPACE) {
@ -1126,7 +1129,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p)
/* find first valid contact point */
for (i = 0; i < gpd->runtime.sbuffer_used; i++) {
if (depth_arr[i] != FLT_MAX) {
if (depth_arr[i] != DEPTH_INVALID) {
break;
}
}
@ -1138,7 +1141,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p)
}
else {
for (i = gpd->runtime.sbuffer_used - 1; i >= 0; i--) {
if (depth_arr[i] != FLT_MAX) {
if (depth_arr[i] != DEPTH_INVALID) {
break;
}
}
@ -1148,14 +1151,14 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p)
* first and last contact in an imaginary line between them */
for (i = 0; i < gpd->runtime.sbuffer_used; i++) {
if (!ELEM(i, first_valid, last_valid)) {
depth_arr[i] = FLT_MAX;
depth_arr[i] = DEPTH_INVALID;
}
}
interp_depth = true;
}
if (interp_depth) {
interp_sparse_array(depth_arr, gpd->runtime.sbuffer_used, FLT_MAX);
interp_sparse_array(depth_arr, gpd->runtime.sbuffer_used, DEPTH_INVALID);
}
}
}

View File

@ -841,7 +841,7 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
/* find first valid contact point */
int i;
for (i = 0; i < gps->totpoints; i++) {
if (depth_arr[i] != FLT_MAX) {
if (depth_arr[i] != DEPTH_INVALID) {
break;
}
}
@ -853,7 +853,7 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
}
else {
for (i = gps->totpoints - 1; i >= 0; i--) {
if (depth_arr[i] != FLT_MAX) {
if (depth_arr[i] != DEPTH_INVALID) {
break;
}
}
@ -864,14 +864,14 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
* first and last contact in an imaginary line between them */
for (i = 0; i < gps->totpoints; i++) {
if (!ELEM(i, first_valid, last_valid)) {
depth_arr[i] = FLT_MAX;
depth_arr[i] = DEPTH_INVALID;
}
}
interp_depth = true;
}
if (interp_depth) {
interp_sparse_array(depth_arr, gps->totpoints, FLT_MAX);
interp_sparse_array(depth_arr, gps->totpoints, DEPTH_INVALID);
}
}
}
@ -1041,7 +1041,7 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, false);
/* add small offset to keep stroke over the surface */
if ((depth_arr) && (gpd->zdepth_offset > 0.0f)) {
if ((depth_arr) && (gpd->zdepth_offset > 0.0f) && (depth_arr[i] != DEPTH_INVALID)) {
depth_arr[i] *= (1.0f - (gpd->zdepth_offset / 1000.0f));
}

View File

@ -991,6 +991,10 @@ void gpencil_stroke_convertcoords_tpoint(Scene *scene,
{
ToolSettings *ts = scene->toolsettings;
if (depth && (*depth == DEPTH_INVALID)) {
depth = NULL;
}
int mval_i[2];
round_v2i_v2fl(mval_i, &point2D->x);

View File

@ -1127,7 +1127,7 @@ bool ED_view3d_depth_read_cached_seg(
data.vd = vd;
data.margin = margin;
data.depth = FLT_MAX;
data.depth = 1.0f;
copy_v2_v2_int(p1, mval_sta);
copy_v2_v2_int(p2, mval_end);
@ -1136,7 +1136,7 @@ bool ED_view3d_depth_read_cached_seg(
*depth = data.depth;
return (*depth != FLT_MAX);
return (*depth != 1.0f);
}
/** \} */
@ -1647,6 +1647,9 @@ bool ED_view3d_depth_read_cached(const ViewDepths *vd,
int margin,
float *r_depth)
{
BLI_assert(1.0 <= vd->depth_range[1]);
*r_depth = 1.0f;
if (!vd || !vd->depths) {
return false;
}
@ -1676,15 +1679,11 @@ bool ED_view3d_depth_read_cached(const ViewDepths *vd,
depth = vd->depths[y * vd->w + x];
}
BLI_assert(1.0 <= vd->depth_range[1]);
if (depth != 1.0f) {
*r_depth = depth;
return true;
}
/* Grease-pencil and annotations also need the returned depth value to be high
* so the caller can detect it's invalid. */
*r_depth = FLT_MAX;
return false;
}