diff options
Diffstat (limited to 'source')
5 files changed, 46 insertions, 8 deletions
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c index 1dc6816980c..ca48dc5b025 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c @@ -409,6 +409,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); } 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 2691dcc8408..c3a93867079 100644 --- a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h +++ b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h @@ -300,6 +300,7 @@ typedef struct LineartRenderBuffer { bool use_loose_edge_chain; bool use_geometry_space_chain; bool use_image_boundary_trimming; + bool use_back_face_culling; bool filter_face_mark; bool filter_face_mark_invert; diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c index 923646a133a..2e0030b2112 100644 --- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c +++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c @@ -1346,6 +1346,10 @@ static void lineart_main_cull_triangles(LineartRenderBuffer *rb, bool clip_far) /* Select the triangle in the array. */ tri = (void *)(((uchar *)eln->pointer) + rb->triangle_size * i); + if (tri->flags & LRT_CULL_DISCARD) { + continue; + } + LRT_CULL_DECIDE_INSIDE LRT_CULL_ENSURE_MEMORY lineart_triangle_cull_single(rb, @@ -1536,8 +1540,31 @@ static uint16_t lineart_identify_feature_line(LineartRenderBuffer *rb, double dot_1 = 0, dot_2 = 0; double result; - if (rb->cam_is_persp) { - sub_v3_v3v3_db(view_vector, l->gloc, rb->camera_pos); + if (rb->use_contour || rb->use_back_face_culling) { + + if (rb->cam_is_persp) { + sub_v3_v3v3_db(view_vector, rb->camera_pos, l->gloc); + } + 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 (rb->use_contour && (result = dot_1 * dot_2) <= 0 && (dot_1 + dot_2)) { + edge_flag_result |= LRT_EDGE_FLAG_CONTOUR; + } + + /* Because the ray points towards the camera, so backface is when dot value being negative.*/ + if (rb->use_back_face_culling) { + if (dot_1 < 0) { + tri1->flags |= LRT_CULL_DISCARD; + } + if (dot_2 < 0) { + tri2->flags |= LRT_CULL_DISCARD; + } + } } else { view_vector = rb->view_vector; @@ -3160,6 +3187,12 @@ static LineartRenderBuffer *lineart_create_render_buffer(Scene *scene, rb->chain_preserve_details = (lmd->calculation_flags & LRT_CHAIN_PRESERVE_DETAILS) != 0; + /* This is used to limit calculation to a certain level to save time, lines who have higher + * occlusion levels will get ignored. */ + rb->max_occlusion_level = lmd->level_end_override; + + rb->use_back_face_culling = (lmd->calculation_flags & LRT_USE_BACK_FACE_CULLING) != 0; + int16_t edge_types = lmd->edge_types_override; rb->use_contour = (edge_types & LRT_EDGE_FLAG_CONTOUR) != 0; @@ -4178,12 +4211,6 @@ bool MOD_lineart_compute_feature_lines(Depsgraph *depsgraph, * See definition of LineartTriangleThread for details. */ rb->triangle_size = lineart_triangle_size_get(scene, rb); - /* This is used to limit calculation to a certain level to save time, lines who have higher - * occlusion levels will get ignored. */ - rb->max_occlusion_level = (lmd->flags & LRT_GPENCIL_USE_CACHE) ? - lmd->level_end_override : - (lmd->use_multiple_levels ? lmd->level_end : lmd->level_start); - /* FIXME(Yiming): See definition of int #LineartRenderBuffer::_source_type for detailed. */ rb->_source_type = lmd->source_type; rb->_source_collection = lmd->source_collection; diff --git a/source/blender/makesdna/DNA_lineart_types.h b/source/blender/makesdna/DNA_lineart_types.h index 7ef03422c7f..bd123de4a54 100644 --- a/source/blender/makesdna/DNA_lineart_types.h +++ b/source/blender/makesdna/DNA_lineart_types.h @@ -50,6 +50,7 @@ typedef enum eLineartMainFlags { LRT_USE_CREASE_ON_SMOOTH_SURFACES = (1 << 15), LRT_USE_CREASE_ON_SHARP_EDGES = (1 << 16), LRT_USE_CUSTOM_CAMERA = (1 << 17), + LRT_USE_BACK_FACE_CULLING = (1 << 19), LRT_USE_IMAGE_BOUNDARY_TRIMMING = (1 << 20), LRT_CHAIN_PRESERVE_DETAILS = (1 << 22), } eLineartMainFlags; diff --git a/source/blender/makesrna/intern/rna_gpencil_modifier.c b/source/blender/makesrna/intern/rna_gpencil_modifier.c index 02987bb0eab..1b822438d9e 100644 --- a/source/blender/makesrna/intern/rna_gpencil_modifier.c +++ b/source/blender/makesrna/intern/rna_gpencil_modifier.c @@ -3450,6 +3450,14 @@ static void rna_def_modifier_gpencillineart(BlenderRNA *brna) prop, "Image Boundary Trimming", "Trim all edges right at the boundary of image(including overscan region)"); + + prop = RNA_def_property(srna, "use_back_face_culling", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "calculation_flags", LRT_USE_BACK_FACE_CULLING); + RNA_def_property_ui_text( + prop, + "Back Face Culling", + "Remove all back faces to speed up calculation, this will create edges in " + "different occlusion levels than when disabled"); RNA_def_property_update(prop, 0, "rna_GpencilModifier_update"); prop = RNA_def_property(srna, "use_invert_collection", PROP_BOOLEAN, PROP_NONE); |