[Bf-blender-cvs] [9f52862a1ba] temp-lineart-contained: LineArt: Temp solution for not including lines that are outside selected source.
YimingWu
noreply at git.blender.org
Thu Mar 18 03:01:34 CET 2021
Commit: 9f52862a1baa0355c73c63fa4f4a5c4e6d3b2158
Author: YimingWu
Date: Thu Mar 18 10:01:18 2021 +0800
Branches: temp-lineart-contained
https://developer.blender.org/rB9f52862a1baa0355c73c63fa4f4a5c4e6d3b2158
LineArt: Temp solution for not including lines that are outside selected source.
===================================================================
M source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
M source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
===================================================================
diff --git a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
index 83f9ffeb11c..899d64724ce 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
+++ b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
@@ -193,7 +193,7 @@ typedef struct LineartChainRegisterEntry {
LineartLineChainItem *rlci;
char picked;
- /** left/right mark.
+ /* left/right mark.
* Because we revert list in chaining so we need the flag. */
char is_left;
} LineartChainRegisterEntry;
@@ -220,7 +220,7 @@ typedef struct LineartRenderBuffer {
ListBase triangle_adjacent_pointers;
ListBase intersecting_vertex_buffer;
- /** Use the one comes with Line Art. */
+ /* Use the one comes with Line Art. */
LineartStaticMemPool render_data_pool;
ListBase wasted_cuts;
SpinLock lock_cuts;
@@ -258,7 +258,7 @@ typedef struct LineartRenderBuffer {
ListBase chains;
- /** For managing calculation tasks for multiple threads. */
+ /* For managing calculation tasks for multiple threads. */
SpinLock lock_task;
/* settings */
@@ -281,7 +281,7 @@ typedef struct LineartRenderBuffer {
bool allow_overlapping_edges;
bool remove_doubles;
- /** Keep an copy of these data so when line art is running it's self-contained. */
+ /* Keep an copy of these data so when line art is running it's self-contained. */
bool cam_is_persp;
float cam_obmat[4][4];
double camera_pos[3];
@@ -291,6 +291,15 @@ typedef struct LineartRenderBuffer {
float chaining_image_threshold;
float chaining_geometry_threshold;
float angle_splitting_threshold;
+
+ /* FIXME: (Yiming) Temporary solution for speeding up calculation by not including lines that
+ * are not in the selected source. This will not be needed after we have a proper scene-wise
+ * cache running because multiple modifiers can then select results from that without further
+ * calculation. */
+ int _source_type;
+ struct Collection *_source_collection;
+ struct Object *_source_object;
+
} LineartRenderBuffer;
#define DBL_TRIANGLE_LIM 1e-8
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index a07b1dd81e3..40dc85501e2 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -1719,18 +1719,37 @@ static void lineart_geometry_object_load(Depsgraph *dg,
#undef LRT_MESH_FINISH
}
+static bool _lineart_object_not_in_source(LineartRenderBuffer *rb, Object *ob)
+{
+ if (rb->_source_type == LRT_SOURCE_SCENE) {
+ return false;
+ }
+ else if (rb->_source_type == LRT_SOURCE_OBJECT) {
+ return (ob != rb->_source_object);
+ }
+ else if (rb->_source_type == LRT_SOURCE_COLLECTION) {
+ if (!BKE_collection_has_object((Collection *)rb->_source_collection->id.orig_id,
+ (Object *)(ob->id.orig_id))) {
+ return true;
+ }
+ }
+ return false;
+}
+
/* See if this object in such collection is used for generating line art,
- * Disabling a collection for line art will diable all objects inside. */
-static int lineart_usage_check(Collection *c, Object *ob)
+ * Disabling a collection for line art will diable all objects inside.
+ * "_rb" is used to provide source selection info. See the definition of rb->_source_type for
+ * details. */
+static int lineart_usage_check(Collection *c, Object *ob, LineartRenderBuffer *_rb)
{
if (!c) {
return OBJECT_LRT_INHERENT;
}
- int object_is_used = (ob->lineart.usage != OBJECT_LRT_INHERENT);
+ int object_has_special_usage = (ob->lineart.usage != OBJECT_LRT_INHERENT);
- if (object_is_used) {
+ if (object_has_special_usage) {
return ob->lineart.usage;
}
@@ -1755,12 +1774,18 @@ static int lineart_usage_check(Collection *c, Object *ob)
}
LISTBASE_FOREACH (CollectionChild *, cc, &c->children) {
- int result = lineart_usage_check(cc->collection, ob);
+ int result = lineart_usage_check(cc->collection, ob, _rb);
if (result > OBJECT_LRT_INHERENT) {
return result;
}
}
+ /* Temp solution to speed up calculation in the modifier without cache. See the definition of
+ * rb->_source_type for details. */
+ if (_lineart_object_not_in_source(_rb, ob)) {
+ return OBJECT_LRT_OCCLUSION_ONLY;
+ }
+
return OBJECT_LRT_INHERENT;
}
@@ -1813,7 +1838,7 @@ static void lineart_main_load_geometries(
int global_i = 0;
DEG_OBJECT_ITER_BEGIN (depsgraph, ob, flags) {
- int usage = lineart_usage_check(scene->master_collection, ob);
+ int usage = lineart_usage_check(scene->master_collection, ob, rb);
lineart_geometry_object_load(depsgraph, ob, view, proj, rb, usage, &global_i);
}
@@ -2228,8 +2253,10 @@ static void lineart_vert_set_intersection_2v(LineartVert *rv, LineartVert *v1, L
irv->isec2 = v2->index;
}
-/* This tests a triangle against a virtual line represented by v1---v2. The vertices returned after
- * repeated calls to this function is then used to create a triangle/triangle intersection line. */
+/* This tests a triangle against a virtual line represented by v1---v2. The vertices returned
+ * after
+ * repeated calls to this function is then used to create a triangle/triangle intersection line.
+ */
static LineartVert *lineart_triangle_2v_intersection_test(LineartRenderBuffer *rb,
LineartVert *v1,
LineartVert *v2,
@@ -2268,7 +2295,8 @@ static LineartVert *lineart_triangle_2v_intersection_test(LineartRenderBuffer *r
interp_v3_v3v3_db(gloc, l->gloc, r->gloc, dot_l / (dot_l + dot_r));
- /* Due to precision issue, we might end up with the same point as the one we already detected. */
+ /* Due to precision issue, we might end up with the same point as the one we already detected.
+ */
if (last && LRT_DOUBLE_CLOSE_ENOUGH(last->gloc[0], gloc[0]) &&
LRT_DOUBLE_CLOSE_ENOUGH(last->gloc[1], gloc[1]) &&
LRT_DOUBLE_CLOSE_ENOUGH(last->gloc[2], gloc[2])) {
@@ -2401,8 +2429,8 @@ static LineartEdge *lineart_triangle_intersect(LineartRenderBuffer *rb,
}
}
- /* The intersection line has been generated only in geometry space, so we need to transform them
- * as well. */
+ /* The intersection line has been generated only in geometry space, so we need to transform
+ * them as well. */
mul_v4_m4v3_db(v1->fbcoord, rb->view_projection, v1->gloc);
mul_v4_m4v3_db(v2->fbcoord, rb->view_projection, v2->gloc);
mul_v3db_db(v1->fbcoord, (1 / v1->fbcoord[3]));
@@ -3581,6 +3609,11 @@ int MOD_lineart_compute_feature_lines(Depsgraph *depsgraph, LineartGpencilModifi
* occlusion levels will get ignored. */
rb->max_occlusion_level = MAX2(lmd->level_start, lmd->level_end);
+ /* FIXME: (Yiming) See definition of int LineartRenderBuffer::_source_type for detailes. */
+ rb->_source_type = lmd->source_type;
+ rb->_source_collection = lmd->source_collection;
+ rb->_source_object = lmd->source_object;
+
/* Get view vector before loading geometries, because we detect feature lines there. */
lineart_main_get_view_vector(rb);
lineart_main_load_geometries(
@@ -3608,13 +3641,13 @@ int MOD_lineart_compute_feature_lines(Depsgraph *depsgraph, LineartGpencilModifi
lineart_main_perspective_division(rb);
/* Triangle intersections are done here during sequential adding of them. Only after this,
- * triangles and lines are all linked with acceleration structure, and the 2D occlusion stage can
- * do its job. */
+ * triangles and lines are all linked with acceleration structure, and the 2D occlusion stage
+ * can do its job. */
lineart_main_add_triangles(rb);
- /* Link lines to acceleration structure, this can only be done after perspective division, if we
- * do it after triangles being added, the acceleration structure has already been subdivided,
- * this way we do less list manipulations. */
+ /* Link lines to acceleration structure, this can only be done after perspective division, if
+ * we do it after triangles being added, the acceleration structure has already been
+ * subdivided, this way we do less list manipulations. */
lineart_main_link_lines(rb);
/* "intersection_only" is preserved for being called in a standalone fashion.
@@ -3627,12 +3660,12 @@ int MOD_lineart_compute_feature_lines(Depsgraph *depsgraph, LineartGpencilModifi
lineart_main_occlusion_begin(rb);
/* Chaining is all single threaded. See lineart_chain.c
- * In this particular call, only lines that are geometrically connected (share the _exact_ same
- * end point) will be chained together. */
+ * In this particular call, only lines that are geometrically connected (share the _exact_
+ * same end point) will be chained together. */
MOD_lineart_chain_feature_lines(rb);
- /* We are unable to take care of occlusion if we only connect end points, so here we do a spit,
- * where the splitting point could be any cut in e->segments. */
+ /* We are unable to take care of occlusion if we only connect end points, so here we do a
+ * spit, where the splitting point could be any cut in e->segments. */
MOD_lineart_chain_split_for_fixed_occlusion(rb);
/* Then we connect chains based on the _proximity_ of their end points in geometry or image
More information about the Bf-blender-cvs
mailing list