[Bf-blender-cvs] [5e78be3ff80] temp-lineart-contained: LineArt: Light contour type.

YimingWu noreply at git.blender.org
Thu Jun 10 16:36:53 CEST 2021


Commit: 5e78be3ff8045518ab3b8f5ce7b3aea1d200f7c0
Author: YimingWu
Date:   Thu Jun 10 22:36:39 2021 +0800
Branches: temp-lineart-contained
https://developer.blender.org/rB5e78be3ff8045518ab3b8f5ce7b3aea1d200f7c0

LineArt: Light contour type.

===================================================================

M	source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
M	source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
M	source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
M	source/blender/gpencil_modifiers/intern/lineart/lineart_intern.h
M	source/blender/makesdna/DNA_gpencil_modifier_types.h
M	source/blender/makesrna/intern/rna_gpencil_modifier.c

===================================================================

diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
index 7b36fcd18c0..b68246474af 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
@@ -275,6 +275,7 @@ static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk,
 
   walk(userData, ob, (ID **)&lmd->source_object, IDWALK_CB_NOP);
   walk(userData, ob, (ID **)&lmd->source_camera, IDWALK_CB_NOP);
+  walk(userData, ob, (ID **)&lmd->light_contour_object, IDWALK_CB_NOP);
 }
 
 static void panel_draw(const bContext *UNUSED(C), Panel *panel)
@@ -318,13 +319,21 @@ static void panel_draw(const bContext *UNUSED(C), Panel *panel)
   uiItemR(col, ptr, "use_intersection", 0, IFACE_("Intersections"), ICON_NONE);
   uiItemR(col, ptr, "use_crease", 0, IFACE_("Crease"), ICON_NONE);
 
-  uiLayout *sub = uiLayoutRow(col, true);
+  uiLayout *sub = uiLayoutRow(col, false);
   uiLayoutSetActive(sub,
                     (RNA_boolean_get(ptr, "use_crease") && !use_cache) ||
                         BKE_gpencil_lineart_is_first_run(ob_ptr.data, ptr->data));
   uiLayoutSetPropSep(sub, true);
   uiItemR(sub, ptr, "crease_threshold", UI_ITEM_R_SLIDER, " ", ICON_NONE);
 
+  sub = uiLayoutRowWithHeading(col, false, IFACE_("Light Contour"));
+  uiItemR(sub, ptr, "use_light_contour", 0, "", ICON_NONE);
+  uiLayout *entry = uiLayoutRow(sub, false);
+  uiLayoutSetActive(entry,
+                    (RNA_boolean_get(ptr, "use_light_contour") && !use_cache) ||
+                        BKE_gpencil_lineart_is_first_run(ob_ptr.data, ptr->data));
+  uiItemR(entry, ptr, "light_contour_object", 0, "", ICON_NONE);
+
   uiItemPointerR(layout, ptr, "target_layer", &obj_data_ptr, "layers", NULL, ICON_GREASEPENCIL);
 
   /* Material has to be used by grease pencil object already, it was possible to assign materials
diff --git a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
index 8a8f379eedb..b242a82a593 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
+++ b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
@@ -271,6 +271,7 @@ typedef struct LineartRenderBuffer {
   ListBase material;
   ListBase edge_mark;
   ListBase floating;
+  ListBase light_contour;
 
   ListBase chains;
 
@@ -292,6 +293,7 @@ typedef struct LineartRenderBuffer {
   bool use_edge_marks;
   bool use_intersections;
   bool use_floating;
+  bool use_light_contour;
   bool fuzzy_intersections;
   bool fuzzy_everything;
   bool allow_boundaries;
@@ -318,6 +320,10 @@ typedef struct LineartRenderBuffer {
   float angle_splitting_threshold;
   float chain_smooth_tolerance;
 
+  /* Could be direction or position, depends on light_is_sun. */
+  double light_vector[3];
+  bool light_is_sun;
+
   /* 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
@@ -376,6 +382,7 @@ typedef struct LineartRenderTaskInfo {
   ListBase material;
   ListBase edge_mark;
   ListBase floating;
+  ListBase light_contour;
 
 } LineartRenderTaskInfo;
 
@@ -403,6 +410,7 @@ typedef struct LineartObjectInfo {
   ListBase material;
   ListBase edge_mark;
   ListBase floating;
+  ListBase light_contour;
 
 } LineartObjectInfo;
 
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index 0190f49f812..cee93b11d26 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -50,6 +50,7 @@
 #include "DNA_camera_types.h"
 #include "DNA_collection_types.h"
 #include "DNA_gpencil_types.h"
+#include "DNA_light_types.h"
 #include "DNA_material_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
@@ -433,6 +434,7 @@ static int lineart_occlusion_make_task_info(LineartRenderBuffer *rb, LineartRend
   LRT_ASSIGN_OCCLUSION_TASK(material);
   LRT_ASSIGN_OCCLUSION_TASK(edge_mark);
   LRT_ASSIGN_OCCLUSION_TASK(floating);
+  LRT_ASSIGN_OCCLUSION_TASK(light_contour);
 
 #undef LRT_ASSIGN_OCCLUSION_TASK
 
@@ -471,6 +473,10 @@ static void lineart_occlusion_worker(TaskPool *__restrict UNUSED(pool), LineartR
     for (eip = rti->floating.first; eip && eip != rti->floating.last; eip = eip->next) {
       lineart_occlusion_single_line(rb, eip, rti->thread_id);
     }
+
+    for (eip = rti->light_contour.first; eip && eip != rti->light_contour.last; eip = eip->next) {
+      lineart_occlusion_single_line(rb, eip, rti->thread_id);
+    }
   }
 }
 
@@ -494,6 +500,7 @@ static void lineart_main_occlusion_begin(LineartRenderBuffer *rb)
   rb->material.last = rb->material.first;
   rb->edge_mark.last = rb->edge_mark.first;
   rb->floating.last = rb->floating.first;
+  rb->light_contour.last = rb->light_contour.first;
 
   TaskPool *tp = BLI_task_pool_create(NULL, TASK_PRIORITY_HIGH, TASK_ISOLATION_OFF);
 
@@ -1534,6 +1541,21 @@ static uint16_t lineart_identify_feature_line(LineartRenderBuffer *rb,
     edge_flag_result |= LRT_EDGE_FLAG_CONTOUR;
   }
 
+  if (rb->light_is_sun) {
+    view_vector = rb->light_vector;
+  }
+  else {
+    view_vector = vv;
+    sub_v3_v3v3_db(view_vector, l->gloc, rb->light_vector);
+  }
+
+  dot_1 = dot_v3v3_db(view_vector, tri1->gn);
+  dot_2 = dot_v3v3_db(view_vector, tri2->gn);
+
+  if ((result = dot_1 * dot_2) <= 0 && (dot_1 + dot_2)) {
+    edge_flag_result |= LRT_EDGE_FLAG_LIGHT_CONTOUR;
+  }
+
   if (rb->use_crease && (dot_v3v3_db(tri1->gn, tri2->gn) < crease_threshold)) {
     if (!no_crease) {
       edge_flag_result |= LRT_EDGE_FLAG_CREASE;
@@ -1573,6 +1595,9 @@ static void lineart_add_edge_to_list(LineartRenderBuffer *rb, LineartEdge *e)
     case LRT_EDGE_FLAG_FLOATING:
       lineart_prepend_edge_direct(&rb->floating.first, e);
       break;
+    case LRT_EDGE_FLAG_LIGHT_CONTOUR:
+      lineart_prepend_edge_direct(&rb->light_contour.first, e);
+      break;
   }
 }
 
@@ -1603,6 +1628,9 @@ static void lineart_add_edge_to_list_thread(LineartObjectInfo *obi, LineartEdge
     case LRT_EDGE_FLAG_FLOATING:
       LRT_ASSIGN_EDGE(floating);
       break;
+    case LRT_EDGE_FLAG_LIGHT_CONTOUR:
+      LRT_ASSIGN_EDGE(light_contour);
+      break;
   }
 #undef LRT_ASSIGN_EDGE
 }
@@ -1620,6 +1648,7 @@ static void lineart_finalize_object_edge_list(LineartRenderBuffer *rb, LineartOb
   LRT_OBI_TO_RB(edge_mark);
   LRT_OBI_TO_RB(intersection);
   LRT_OBI_TO_RB(floating);
+  LRT_OBI_TO_RB(light_contour);
 #undef LRT_OBI_TO_RB
 }
 
@@ -2961,6 +2990,7 @@ static void lineart_destroy_render_data(LineartRenderBuffer *rb)
   memset(&rb->edge_mark, 0, sizeof(ListBase));
   memset(&rb->material, 0, sizeof(ListBase));
   memset(&rb->floating, 0, sizeof(ListBase));
+  memset(&rb->light_contour, 0, sizeof(ListBase));
 
   BLI_listbase_clear(&rb->chains);
   BLI_listbase_clear(&rb->wasted_cuts);
@@ -3059,6 +3089,19 @@ static LineartRenderBuffer *lineart_create_render_buffer(Scene *scene,
   rb->shift_x /= (1 + rb->overscan);
   rb->shift_y /= (1 + rb->overscan);
 
+  if (lmd->light_contour_object) {
+    Object *lo = lmd->light_contour_object;
+    if (lo->type == OB_LAMP && ((Light *)lo->data)->type == LA_SUN) {
+      rb->light_is_sun = true;
+      float vec[3] = {0.0f, 0.0f, 1.0f};
+      mul_mat3_m4_v3(lo->obmat, vec);
+      copy_v3db_v3fl(rb->light_vector, vec);
+    }
+    else {
+      copy_v3db_v3fl(rb->light_vector, lmd->light_contour_object->obmat[3]);
+    }
+  }
+
   rb->crease_threshold = cos(M_PI - lmd->crease_threshold);
   rb->chaining_image_threshold = lmd->chaining_image_threshold;
   rb->angle_splitting_threshold = lmd->angle_splitting_threshold;
@@ -3084,6 +3127,7 @@ static LineartRenderBuffer *lineart_create_render_buffer(Scene *scene,
   rb->use_edge_marks = (lmd->edge_types_override & LRT_EDGE_FLAG_EDGE_MARK) != 0;
   rb->use_intersections = (lmd->edge_types_override & LRT_EDGE_FLAG_INTERSECTION) != 0;
   rb->use_floating = (lmd->edge_types_override & LRT_EDGE_FLAG_FLOATING) != 0;
+  rb->use_light_contour = (lmd->edge_types_override & LRT_EDGE_FLAG_LIGHT_CONTOUR) != 0;
 
   rb->filter_face_mark_invert = (lmd->calculation_flags & LRT_FILTER_FACE_MARK_INVERT) != 0;
   rb->filter_face_mark = (lmd->calculation_flags & LRT_FILTER_FACE_MARK) != 0;
@@ -4226,6 +4270,7 @@ static int lineart_rb_edge_types(LineartRenderBuffer *rb)
   types |= rb->use_edge_marks ? LRT_EDGE_FLAG_EDGE_MARK : 0;
   types |= rb->use_intersections ? LRT_EDGE_FLAG_INTERSECTION : 0;
   types |= rb->use_floating ? LRT_EDGE_FLAG_FLOATING : 0;
+  types |= rb->use_light_contour ? LRT_EDGE_FLAG_LIGHT_CONTOUR : 0;
   return types;
 }
 
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_intern.h b/source/blender/gpencil_modifiers/intern/lineart/lineart_intern.h
index c862c488cf5..c25a5f90059 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_intern.h
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_intern.h
@@ -103,6 +103,9 @@ void lineart_count_and_print_render_buffer_memory(struct LineartRenderBuffer *rb
   if (!e) { \
     e = rb->floating.first; \
   } \
+  if (!e) { \
+    e = rb->light_contour.first; \
+  } \
   for (current_head = &rb->contour.first; e; e = next_e) { \
     next_e = e->next;
 
@@ -123,6 +126,9 @@ void lineart_count_and_print_render_buffer_memory(struct LineartRenderBuffer *rb
     else if (current_head == &rb->intersection.first) { \
       current_head = &rb->floating.first; \
     } \
+    else if (current_head == &rb->floating.first) { \
+      current_head = &rb->light_contour.first; \
+    } \
     else { \
       break; \
     } \
diff --git a/source/blender/makesdna/DNA_gpencil_modifier_types.h b/source/blender/makesdna/DNA_gpencil_modifier_types.h
index 87e4e07b1d9..1b266f1ec28 100644
--- a/source/blender/makesdna/DNA_gpencil_modifier_types.h
+++ b/source/blender/makesdna/DNA_gpencil_modifier_types.h
@@ -896,7 +896,7 @@ struct LineartCache;
 t

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list