diff options
author | YimingWu <xp8110@outlook.com> | 2022-02-22 07:51:49 +0300 |
---|---|---|
committer | YimingWu <xp8110@outlook.com> | 2022-02-22 07:51:49 +0300 |
commit | 0f2e0a25e13d2d67f3d08d068ba11e255794bb6b (patch) | |
tree | 543f100da9ef925fba35cc80042707ab194406cc /source | |
parent | 2fefdaae93ae982858f1664ce7176fd76ae325ed (diff) |
LineArt: Consistent backface culling behavior
1. Now will remove lines if both adjacent faces are back face.
2. Added a check to respect material back face culling setting.
3. Changed label in the modifier to "Force Backface Culling" (which reflect more accurately with what the checkbox does).
Reviewed By: Antonio Vazquez (antoniov), Aleš Jelovčan (frogstomp)
Ref D14041
Diffstat (limited to 'source')
4 files changed, 25 insertions, 5 deletions
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c index ea7a676b157..1058f861be3 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c @@ -393,7 +393,7 @@ static void options_panel_draw(const bContext *UNUSED(C), Panel *panel) 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(col, ptr, "use_crease_on_sharp", 0, IFACE_("Crease On Sharp"), ICON_NONE); - uiItemR(col, ptr, "use_back_face_culling", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "use_back_face_culling", 0, IFACE_("Force Backface Culling"), 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 2c7999699c7..5d952991cf7 100644 --- a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h +++ b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h @@ -343,6 +343,7 @@ typedef enum eLineartTriangleFlags { LRT_CULL_GENERATED = (1 << 2), LRT_TRIANGLE_INTERSECTION_ONLY = (1 << 3), LRT_TRIANGLE_NO_INTERSECTION = (1 << 4), + LRT_TRIANGLE_MAT_BACK_FACE_CULLING = (1 << 5), } eLineartTriangleFlags; /** diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c index a5af66cbbc5..31dd37db1a7 100644 --- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c +++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c @@ -1529,8 +1529,9 @@ static uint16_t lineart_identify_feature_line(LineartRenderBuffer *rb, double *view_vector = vv; double dot_1 = 0, dot_2 = 0; double result; + bool material_back_face = ((tri1->flags | tri2->flags) & LRT_TRIANGLE_MAT_BACK_FACE_CULLING); - if (rb->use_contour || rb->use_back_face_culling) { + if (rb->use_contour || rb->use_back_face_culling || material_back_face) { if (rb->cam_is_persp) { sub_v3_v3v3_db(view_vector, rb->camera_pos, l->gloc); @@ -1555,14 +1556,19 @@ static uint16_t lineart_identify_feature_line(LineartRenderBuffer *rb, tri2->flags |= LRT_CULL_DISCARD; } } + if (material_back_face) { + if (tri1->flags & LRT_TRIANGLE_MAT_BACK_FACE_CULLING && dot_1 < 0) { + tri1->flags |= LRT_CULL_DISCARD; + } + if (tri2->flags & LRT_TRIANGLE_MAT_BACK_FACE_CULLING && dot_2 < 0) { + tri2->flags |= LRT_CULL_DISCARD; + } + } } else { view_vector = rb->view_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 && (fabs(dot_1) + fabs(dot_2))) { edge_flag_result |= LRT_EDGE_FLAG_CONTOUR; } @@ -1573,6 +1579,16 @@ static uint16_t lineart_identify_feature_line(LineartRenderBuffer *rb, return edge_flag_result; } + /* Do not show lines other than contour on back face (because contour has one adjacent face that + * isn't a back face). + * TODO(Yiming): Do we need separate option for this? */ + if (rb->use_back_face_culling || + ((tri1->flags & tri2->flags) & LRT_TRIANGLE_MAT_BACK_FACE_CULLING)) { + if (dot_1 < 0 && dot_2 < 0) { + return edge_flag_result; + } + } + if (rb->use_crease) { if (rb->sharp_as_crease && !BM_elem_flag_test(e, BM_ELEM_SMOOTH)) { edge_flag_result |= LRT_EDGE_FLAG_CREASE; @@ -1859,6 +1875,9 @@ static void lineart_geometry_object_load(LineartObjectInfo *obi, LineartRenderBu mat->lineart.material_mask_bits : 0); tri->mat_occlusion |= (mat ? mat->lineart.mat_occlusion : 1); + tri->flags |= (mat && (mat->blend_flag & MA_BL_CULL_BACKFACE)) ? + LRT_TRIANGLE_MAT_BACK_FACE_CULLING : + 0; tri->intersection_mask = obi->override_intersection_mask; diff --git a/source/tools b/source/tools -Subproject 515e67c1932bc06f24cb50b621265c2a6e8a25a +Subproject 7fd2ed908b4f50140670caf6786e5ed245b7913 |