[Bf-blender-cvs] [5db821da047] temp-lineart-contained: LineArt: Smoothing chains before angle splitting.
YimingWu
noreply at git.blender.org
Thu May 6 12:01:21 CEST 2021
Commit: 5db821da047c539327e4b0b5c970fc5a088ad111
Author: YimingWu
Date: Thu May 6 18:00:45 2021 +0800
Branches: temp-lineart-contained
https://developer.blender.org/rB5db821da047c539327e4b0b5c970fc5a088ad111
LineArt: Smoothing chains before angle splitting.
===================================================================
M source/blender/blenloader/intern/versioning_300.c
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_chain.c
M source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
M source/blender/makesdna/DNA_gpencil_modifier_defaults.h
M source/blender/makesdna/DNA_gpencil_modifier_types.h
M source/blender/makesrna/intern/rna_gpencil_modifier.c
===================================================================
diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c
index 8d916b48472..92e74be0cdb 100644
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@ -85,6 +85,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
if (md->type == eGpencilModifierType_Lineart) {
LineartGpencilModifierData *lmd = (LineartGpencilModifierData *)md;
lmd->flags |= LRT_GPENCIL_USE_CACHE;
+ lmd->chain_smooth_tolerance = 0.2f;
}
}
}
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
index 4c89518627a..18a3d680ef0 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
@@ -453,6 +453,7 @@ static void chaining_panel_draw(const bContext *UNUSED(C), Panel *panel)
uiItemR(layout, ptr, "chaining_image_threshold", 0, NULL, ICON_NONE);
+ uiItemR(layout, ptr, "smooth_tolerance", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
uiItemR(layout, ptr, "split_angle", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
}
diff --git a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
index 7a433c68d16..2c331846c2d 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
+++ b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
@@ -600,6 +600,7 @@ void MOD_lineart_chain_connect(LineartRenderBuffer *rb);
void MOD_lineart_chain_discard_short(LineartRenderBuffer *rb, const float threshold);
void MOD_lineart_chain_split_angle(LineartRenderBuffer *rb, float angle_threshold_rad);
void MOD_lineart_chain_offset_towards_camera(LineartRenderBuffer *rb, float dist);
+void MOD_lineart_smooth_chains(LineartRenderBuffer *rb, float tolerance);
int MOD_lineart_chain_count(const LineartLineChain *rlc);
void MOD_lineart_chain_clear_picked_flag(LineartCache *lc);
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c
index 9706dbf4196..9186966cbc2 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c
@@ -899,6 +899,35 @@ void MOD_lineart_chain_clear_picked_flag(LineartCache *lc)
}
}
+void MOD_lineart_smooth_chains(LineartRenderBuffer *rb, float tolerance)
+{
+ LISTBASE_FOREACH (LineartLineChain *, rlc, &rb->chains) {
+ LineartLineChainItem *next_rlci;
+ for (LineartLineChainItem *rlci = rlc->chain.first; rlci; rlci = next_rlci) {
+ next_rlci = rlci->next;
+ LineartLineChainItem *rlci2, *rlci3, *rlci4;
+
+ /* Not enough point to do simplify. */
+ if ((!(rlci2 = rlci->next)) || (!(rlci3 = rlci2->next))) {
+ continue;
+ }
+
+ /* No need to care for different line types/occlusion and so on, because at this stage they
+ * are all the same within a chain. */
+
+ /* If p3 is within the p1-p2 segment of a width of "tolerance" */
+ if (dist_to_line_segment_v2(rlci3->pos, rlci->pos, rlci2->pos) < tolerance) {
+ /* And if p4 is on the extension of p1-p2 , we remove p3. */
+ if ((rlci4 = rlci3->next) &&
+ (dist_to_line_v2(rlci4->pos, rlci->pos, rlci2->pos) < tolerance)) {
+ BLI_remlink(&rlc->chain, rlci3);
+ next_rlci = rlci;
+ }
+ }
+ }
+ }
+}
+
/**
* This should always be the last stage!, see the end of
* #MOD_lineart_chain_split_for_fixed_occlusion().
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index 1083c5a070f..dc063d5b1e9 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -2928,8 +2928,9 @@ static LineartRenderBuffer *lineart_create_render_buffer(Scene *scene,
rb->shift_y = (asp <= 1) ? c->shifty : c->shifty * asp;
rb->crease_threshold = cos(M_PI - lmd->crease_threshold);
- rb->angle_splitting_threshold = lmd->angle_splitting_threshold;
rb->chaining_image_threshold = lmd->chaining_image_threshold;
+ rb->angle_splitting_threshold = lmd->angle_splitting_threshold;
+ rb->chain_smooth_tolerance = lmd->chain_smooth_tolerance;
rb->fuzzy_intersections = (lmd->calculation_flags & LRT_INTERSECTION_AS_CONTOUR) != 0;
rb->fuzzy_everything = (lmd->calculation_flags & LRT_EVERYTHING_AS_CONTOUR) != 0;
@@ -4018,6 +4019,13 @@ bool MOD_lineart_compute_feature_lines(Depsgraph *depsgraph,
/* This configuration ensures there won't be accidental lost of short unchained segments. */
MOD_lineart_chain_discard_short(rb, MIN2(*t_image, 0.001f) - FLT_EPSILON);
+ if (rb->chain_smooth_tolerance > FLT_EPSILON) {
+ /* Keeping UI range of 0-1 for ease of read while scaling down the actual value for best
+ * effective range in image-space (Coordinate only goes from -1 to 1). This value is somewhat
+ * arbitrary, but works best for the moment. */
+ MOD_lineart_smooth_chains(rb, rb->chain_smooth_tolerance / 50);
+ }
+
if (rb->angle_splitting_threshold > FLT_EPSILON) {
MOD_lineart_chain_split_angle(rb, rb->angle_splitting_threshold);
}
diff --git a/source/blender/makesdna/DNA_gpencil_modifier_defaults.h b/source/blender/makesdna/DNA_gpencil_modifier_defaults.h
index f741023ca96..bf1ea5e98a7 100644
--- a/source/blender/makesdna/DNA_gpencil_modifier_defaults.h
+++ b/source/blender/makesdna/DNA_gpencil_modifier_defaults.h
@@ -298,6 +298,7 @@
.angle_splitting_threshold = DEG2RAD(60.0f), \
.chaining_image_threshold = 0.001f, \
.stroke_offset = 0.05,\
+ .chain_smooth_tolerance = 0.2f,\
}
/* clang-format off */
diff --git a/source/blender/makesdna/DNA_gpencil_modifier_types.h b/source/blender/makesdna/DNA_gpencil_modifier_types.h
index b04ccf91f59..b982c336a4f 100644
--- a/source/blender/makesdna/DNA_gpencil_modifier_types.h
+++ b/source/blender/makesdna/DNA_gpencil_modifier_types.h
@@ -891,6 +891,9 @@ typedef struct LineartGpencilModifierData {
/** `0..PI` angle, for splitting strokes at sharp points. */
float angle_splitting_threshold;
+ /** Strength for smoothing jagged chains */
+ float chain_smooth_tolerance;
+
/* CPU mode */
float chaining_image_threshold;
@@ -903,8 +906,6 @@ typedef struct LineartGpencilModifierData {
/* Move strokes towards camera to avoid clipping while preserve depth for the viewport. */
float stroke_offset;
- int _pad;
-
/* Runtime data. */
/* Because we only do calculation once per modifier stack, so we need global override values for
diff --git a/source/blender/makesrna/intern/rna_gpencil_modifier.c b/source/blender/makesrna/intern/rna_gpencil_modifier.c
index 59729863399..71ed5272e4c 100644
--- a/source/blender/makesrna/intern/rna_gpencil_modifier.c
+++ b/source/blender/makesrna/intern/rna_gpencil_modifier.c
@@ -2743,6 +2743,14 @@ static void rna_def_modifier_gpencillineart(BlenderRNA *brna)
RNA_def_property_range(prop, 0.0f, DEG2RAD(180.0f));
RNA_def_property_update(prop, NC_SCENE, "rna_GpencilModifier_update");
+ prop = RNA_def_property(srna, "smooth_tolerance", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "chain_smooth_tolerance");
+ RNA_def_property_ui_text(
+ prop, "Smooth Tolerance", "Strength of smoothing applied on jagged chains");
+ RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.05f, 4);
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_update(prop, NC_SCENE, "rna_GpencilModifier_update");
+
prop = RNA_def_property(srna, "use_remove_doubles", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "calculation_flags", LRT_REMOVE_DOUBLES);
RNA_def_property_ui_text(
More information about the Bf-blender-cvs
mailing list