[Bf-blender-cvs] [a170716208e] temp-lineart-contained: LineArt: Bound box visibility check when loading
YimingWu
noreply at git.blender.org
Wed Jun 9 08:38:46 CEST 2021
Commit: a170716208e6572ec0f0a89058b1acef55f9cd7d
Author: YimingWu
Date: Wed Jun 9 14:38:30 2021 +0800
Branches: temp-lineart-contained
https://developer.blender.org/rBa170716208e6572ec0f0a89058b1acef55f9cd7d
LineArt: Bound box visibility check when loading
===================================================================
M release/datafiles/locale
M source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
===================================================================
diff --git a/release/datafiles/locale b/release/datafiles/locale
index 5ab29b1331d..2cef4877edc 160000
--- a/release/datafiles/locale
+++ b/release/datafiles/locale
@@ -1 +1 @@
-Subproject commit 5ab29b1331d2103dae634b987f121c4599459d7f
+Subproject commit 2cef4877edc40875978c4e95322bb5193f5815bf
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index d6fc6ee3d83..278b5dd90ba 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -2034,6 +2034,36 @@ static void lineart_geometry_load_assign_thread(LineartObjectLoadTaskInfo *olti_
use_olti->pending = obi;
}
+static bool lineart_geometry_check_visible(double (*model_view_proj)[4], Object *use_ob)
+{
+ BoundBox *bb = BKE_mesh_boundbox_get(use_ob);
+ double co[8][4];
+ double tmp[3];
+ for (int i = 0; i < 8; i++) {
+ copy_v3db_v3fl(co[i], bb->vec[i]);
+ copy_v3_v3_db(tmp, co[i]);
+ mul_v4_m4v3_db(co[i], model_view_proj, tmp);
+ }
+
+ bool cond[6] = {true, true, true, true, true, true};
+ /* Beause for a point to be inside clip space, it must satisfy -Wc <= XYCc <= Wc, here if all
+ * verts falls to the same side of the clip space border, we know it's outside view. */
+ for (int i = 0; i < 8; i++) {
+ cond[0] &= (co[i][0] < -co[i][3]);
+ cond[1] &= (co[i][0] > co[i][3]);
+ cond[2] &= (co[i][1] < -co[i][3]);
+ cond[3] &= (co[i][1] > co[i][3]);
+ cond[4] &= (co[i][2] < -co[i][3]);
+ cond[5] &= (co[i][2] > co[i][3]);
+ }
+ for (int i = 0; i < 6; i++) {
+ if (cond[i]) {
+ return false;
+ }
+ }
+ return true;
+}
+
static void lineart_main_load_geometries(
Depsgraph *depsgraph,
Scene *scene,
@@ -2049,6 +2079,8 @@ static void lineart_main_load_geometries(
int fit = BKE_camera_sensor_fit(cam->sensor_fit, rb->w, rb->h);
double asp = ((double)rb->w / (double)rb->h);
+ int bound_box_discard_count = 0;
+
if (cam->type == CAM_PERSP) {
if (fit == CAMERA_SENSOR_FIT_VERT && asp > 1) {
sensor *= asp;
@@ -2108,14 +2140,26 @@ static void lineart_main_load_geometries(
continue;
}
+ /* Prepare the matrix used for transforming this specific object (instance). This has to be
+ * done before mesh boundbox check because the function needs that. */
+ mul_m4db_m4db_m4fl_uniq(obi->model_view_proj, rb->view_projection, ob->obmat);
+ mul_m4db_m4db_m4fl_uniq(obi->model_view, rb->view, ob->obmat);
+
if (!(use_ob->type == OB_MESH || use_ob->type == OB_MBALL || use_ob->type == OB_CURVE ||
use_ob->type == OB_SURF || use_ob->type == OB_FONT)) {
continue;
}
if (use_ob->type == OB_MESH) {
+ if (!lineart_geometry_check_visible(obi->model_view_proj, use_ob)) {
+ if (G.debug_value == 4000) {
+ bound_box_discard_count++;
+ }
+ continue;
+ }
use_mesh = use_ob->data;
}
else {
+ /* Do not have curve boundbox api at the moment? */
use_mesh = BKE_mesh_new_from_object(depsgraph, use_ob, true, true);
}
@@ -2128,9 +2172,7 @@ static void lineart_main_load_geometries(
obi->free_use_mesh = true;
}
- /* Prepare the matrix used for transforming this specific object (instance). */
- mul_m4db_m4db_m4fl_uniq(obi->model_view_proj, rb->view_projection, ob->obmat);
- mul_m4db_m4db_m4fl_uniq(obi->model_view, rb->view, ob->obmat);
+ /* Make normal matrix. */
float imat[4][4];
invert_m4_m4(imat, ob->obmat);
transpose_m4(imat);
@@ -2174,6 +2216,7 @@ static void lineart_main_load_geometries(
if (G.debug_value == 4000) {
double t_elapsed = PIL_check_seconds_timer() - t_start;
printf("Line art loading time: %lf\n", t_elapsed);
+ printf("Discarded %d object from bound box check\n", bound_box_discard_count);
}
}
More information about the Bf-blender-cvs
mailing list