From c1cf66bff3c0753512a2d1f2f8c03430bdd1f045 Mon Sep 17 00:00:00 2001 From: YimingWu Date: Wed, 15 Sep 2021 14:03:18 +0800 Subject: LineArt: Automatic crease with flat/smooth faces. This allows crease lines to be automatically hidden on smooth surfaces, also provided options for: - Showing crease on marked sharp edges. - Force crease detection on smooth surfaces. Reviewed By: Antonio Vazquez (antoniov) Differential Revision: http://developer.blender.org/D12051 --- .../gpencil_modifiers/intern/MOD_gpencillineart.c | 2 ++ .../gpencil_modifiers/intern/lineart/MOD_lineart.h | 3 ++ .../gpencil_modifiers/intern/lineart/lineart_cpu.c | 42 +++++++++++++++------- 3 files changed, 35 insertions(+), 12 deletions(-) (limited to 'source/blender/gpencil_modifiers') diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c index 73ca4b9c529..01488a8b2de 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c @@ -390,6 +390,8 @@ static void options_panel_draw(const bContext *UNUSED(C), Panel *panel) uiItemR(col, ptr, "use_edge_overlap", 0, IFACE_("Overlapping Edges As Contour"), ICON_NONE); uiItemR(col, ptr, "use_object_instances", 0, NULL, ICON_NONE); uiItemR(col, ptr, "use_clip_plane_boundaries", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "use_crease_on_smooth", 0, IFACE_("Crease On Smooth"), ICON_NONE); + uiItemR(layout, ptr, "use_crease_on_sharp", 0, IFACE_("Crease On Sharp"), ICON_NONE); } static void style_panel_draw(const bContext *UNUSED(C), Panel *panel) diff --git a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h index 4b71011b99a..134d9707ade 100644 --- a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h +++ b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h @@ -304,6 +304,9 @@ typedef struct LineartRenderBuffer { bool filter_face_mark_invert; bool filter_face_mark_boundaries; + bool force_crease; + bool sharp_as_crease; + /* 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]; diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c index c71cde8ec43..725cc0741f0 100644 --- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c +++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c @@ -1453,7 +1453,7 @@ static uint16_t lineart_identify_feature_line(LineartRenderBuffer *rb, LineartTriangle *rt_array, LineartVert *rv_array, float crease_threshold, - bool no_crease, + bool use_auto_smooth, bool use_freestyle_edge, bool use_freestyle_face, BMesh *bm_if_freestyle) @@ -1533,10 +1533,20 @@ static uint16_t lineart_identify_feature_line(LineartRenderBuffer *rb, edge_flag_result |= LRT_EDGE_FLAG_CONTOUR; } - if (rb->use_crease && (dot_v3v3_db(tri1->gn, tri2->gn) < crease_threshold)) { - if (!no_crease) { + if (rb->use_crease) { + if (rb->sharp_as_crease && !BM_elem_flag_test(e, BM_ELEM_SMOOTH)) { edge_flag_result |= LRT_EDGE_FLAG_CREASE; } + else { + bool do_crease = true; + if (!rb->force_crease && !use_auto_smooth && + (BM_elem_flag_test(ll->f, BM_ELEM_SMOOTH) && BM_elem_flag_test(lr->f, BM_ELEM_SMOOTH))) { + do_crease = false; + } + if (do_crease && (dot_v3v3_db(tri1->gn, tri2->gn) < crease_threshold)) { + edge_flag_result |= LRT_EDGE_FLAG_CREASE; + } + } } if (rb->use_material && (ll->f->mat_nr != lr->f->mat_nr)) { edge_flag_result |= LRT_EDGE_FLAG_MATERIAL; @@ -1746,9 +1756,14 @@ static void lineart_geometry_object_load(LineartObjectInfo *obi, LineartRenderBu eln->object_ref = orig_ob; obi->v_eln = eln; + bool use_auto_smooth = false; if (orig_ob->lineart.flags & OBJECT_LRT_OWN_CREASE) { use_crease = cosf(M_PI - orig_ob->lineart.crease_threshold); } + if (obi->original_me->flag & ME_AUTOSMOOTH) { + use_crease = cosf(obi->original_me->smoothresh); + use_auto_smooth = true; + } else { use_crease = rb->crease_threshold; } @@ -1832,15 +1847,15 @@ static void lineart_geometry_object_load(LineartObjectInfo *obi, LineartRenderBu e = BM_edge_at_index(bm, i); /* Because e->head.hflag is char, so line type flags should not exceed positive 7 bits. */ - char eflag = lineart_identify_feature_line(rb, - e, - ort, - orv, - use_crease, - orig_ob->type == OB_FONT, - can_find_freestyle_edge, - can_find_freestyle_face, - bm); + uint16_t eflag = lineart_identify_feature_line(rb, + e, + ort, + orv, + use_crease, + use_auto_smooth, + can_find_freestyle_edge, + can_find_freestyle_face, + bm); if (eflag) { /* Only allocate for feature lines (instead of all lines) to save memory. * If allow duplicated edges, one edge gets added multiple times if it has multiple types. */ @@ -3057,6 +3072,9 @@ static LineartRenderBuffer *lineart_create_render_buffer(Scene *scene, rb->allow_duplicated_types = (lmd->calculation_flags & LRT_ALLOW_OVERLAP_EDGE_TYPES) != 0; + rb->force_crease = (lmd->calculation_flags & LRT_USE_CREASE_ON_SMOOTH_SURFACES) != 0; + rb->sharp_as_crease = (lmd->calculation_flags & LRT_USE_CREASE_ON_SHARP_EDGES) != 0; + int16_t edge_types = lmd->edge_types_override; rb->use_contour = (edge_types & LRT_EDGE_FLAG_CONTOUR) != 0; -- cgit v1.2.3