[Bf-blender-cvs] [1111465d269] temp-lineart-contained: LineArt: Noise tolerant chaining.

YimingWu noreply at git.blender.org
Mon Jan 17 03:19:02 CET 2022


Commit: 1111465d269ede7eb3f0feb813a282396450059c
Author: YimingWu
Date:   Mon Jan 17 10:18:45 2022 +0800
Branches: temp-lineart-contained
https://developer.blender.org/rB1111465d269ede7eb3f0feb813a282396450059c

LineArt: Noise tolerant chaining.

Tolerant zig-zag lines by ignoring occlusion change for a short distance

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

M	source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c

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

diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c
index 342cfdb729a..3316a4921f3 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c
@@ -571,6 +571,45 @@ static void lineart_bounding_area_link_chain(LineartRenderBuffer *rb, LineartEdg
   }
 }
 
+static bool lineart_chain_try_skip_noise(LineartEdgeChainItem *last_matching_eci,
+                                         float distance_threshold,
+                                         LineartEdgeChainItem **r_next_eci)
+{
+  float dist_accum = 0;
+
+  int fixed_occ = last_matching_eci->occlusion;
+  unsigned char fixed_mask = last_matching_eci->material_mask_bits;
+
+  LineartEdgeChainItem *can_skip_to = NULL;
+  LineartEdgeChainItem *last_eci = last_matching_eci;
+  for (LineartEdgeChainItem *eci = last_matching_eci->next; eci; eci = eci->next) {
+    dist_accum += len_v2v2(last_eci->pos, eci->pos);
+    if (dist_accum > distance_threshold) {
+      break;
+    }
+    last_eci = eci;
+    /* The reason for this is because we don't want visible segments to be "skipped" into
+     * connecting with invisible segments. */
+    if (eci->occlusion < fixed_occ) {
+      break;
+    }
+    if (eci->material_mask_bits == fixed_mask && eci->occlusion == fixed_occ) {
+      can_skip_to = eci;
+    }
+  }
+  if (can_skip_to) {
+    /* Mark all in-between segments with the same occlusion and mask. */
+    for (LineartEdgeChainItem *eci = last_matching_eci->next; eci != can_skip_to;
+         eci = eci->next) {
+      eci->material_mask_bits = fixed_mask;
+      eci->occlusion = fixed_occ;
+    }
+    *r_next_eci = can_skip_to;
+    return true;
+  }
+  return false;
+}
+
 void MOD_lineart_chain_split_for_fixed_occlusion(LineartRenderBuffer *rb)
 {
   LineartEdgeChain *ec, *new_ec;
@@ -602,6 +641,9 @@ void MOD_lineart_chain_split_for_fixed_occlusion(LineartRenderBuffer *rb)
           if (lineart_point_overlapping(next_eci, eci->pos[0], eci->pos[1], 1e-5)) {
             continue;
           }
+          if (lineart_chain_try_skip_noise(eci->prev, rb->chaining_image_threshold, &next_eci)) {
+            continue;
+          }
         }
         else {
           /* Set the same occlusion level for the end vertex, so when further connection is needed



More information about the Bf-blender-cvs mailing list