[Bf-blender-cvs] [8faaa9873f3] temp-lineart-contained: LineArt: Back face culling.
YimingWu
noreply at git.blender.org
Tue Jun 29 11:29:16 CEST 2021
Commit: 8faaa9873f3123274cfb6d22ae683f8d7daf3269
Author: YimingWu
Date: Tue Jun 29 17:28:56 2021 +0800
Branches: temp-lineart-contained
https://developer.blender.org/rB8faaa9873f3123274cfb6d22ae683f8d7daf3269
LineArt: Back face culling.
===================================================================
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_cpu.c
M source/blender/makesdna/DNA_lineart_types.h
M source/blender/makesrna/intern/rna_gpencil_modifier.c
===================================================================
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
index 51df49c6f55..45c1281b4ee 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
@@ -419,6 +419,7 @@ static void options_panel_draw(const bContext *UNUSED(C), Panel *panel)
uiItemR(layout, ptr, "use_overlap_edge_type_support", 0, NULL, ICON_NONE);
uiItemR(layout, 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);
+ uiItemR(layout, 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 3f6e7ba717a..1d1c91cf5c2 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_as_contour;
bool use_loose_edge_chain;
bool use_geometry_space_chain;
+ 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 ed54c4a879c..611357d4815 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -1335,6 +1335,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,
@@ -1547,7 +1551,7 @@ static uint16_t lineart_identify_feature_line(LineartRenderBuffer *rb,
double dot_1 = 0, dot_2 = 0;
double result;
- if (rb->use_contour) {
+ if (rb->use_contour || rb->use_back_face_culling) {
if (rb->cam_is_persp) {
sub_v3_v3v3_db(view_vector, l->gloc, rb->camera_pos);
@@ -1559,9 +1563,19 @@ static uint16_t lineart_identify_feature_line(LineartRenderBuffer *rb,
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 && (dot_1 + dot_2)) {
+ if (rb->use_contour && (result = dot_1 * dot_2) <= 0 && (dot_1 + dot_2)) {
edge_flag_result |= LRT_EDGE_FLAG_CONTOUR;
}
+
+ /* Because the camera ray starts from camera, so backface is when dot value being positive. */
+ if (rb->use_back_face_culling) {
+ if (dot_1 > 0) {
+ tri1->flags |= LRT_CULL_DISCARD;
+ }
+ if (dot_2 > 0) {
+ tri2->flags |= LRT_CULL_DISCARD;
+ }
+ }
}
/* For when face mark filtering decided that we discard the face but keep_contour option is on.
@@ -3150,6 +3164,18 @@ static LineartRenderBuffer *lineart_create_render_buffer(Scene *scene,
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;
+ /* 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;
+ if (rb->max_occlusion_level < 1) {
+ rb->use_back_face_culling = true;
+ if (G.debug_value = 4000) {
+ printf("Backface culling enabled automatically.\n");
+ }
+ }
+
int16_t edge_types = lmd->edge_types_override;
/* lmd->edge_types_override contains all used flags in the modifier stack. */
@@ -4190,10 +4216,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->level_end_override;
-
/* 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 3031a021487..df082d92a8b 100644
--- a/source/blender/makesdna/DNA_lineart_types.h
+++ b/source/blender/makesdna/DNA_lineart_types.h
@@ -60,6 +60,7 @@ typedef enum eLineartMainFlags {
LRT_USE_CREASE_ON_SMOOTH_SURFACES = (1 << 16),
LRT_USE_CREASE_ON_SHARP_EDGES = (1 << 17),
LRT_FILTER_FACE_MARK_KEEP_CONTOUR = (1 << 18),
+ LRT_USE_BACK_FACE_CULLING = (1 << 19),
} eLineartMainFlags;
typedef enum eLineartEdgeFlag {
diff --git a/source/blender/makesrna/intern/rna_gpencil_modifier.c b/source/blender/makesrna/intern/rna_gpencil_modifier.c
index 112ea01908f..bdaa844a9ba 100644
--- a/source/blender/makesrna/intern/rna_gpencil_modifier.c
+++ b/source/blender/makesrna/intern/rna_gpencil_modifier.c
@@ -3111,6 +3111,15 @@ static void rna_def_modifier_gpencillineart(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Crease On Sharp Edges", "Allow crease to show on sharp edges");
RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
+ 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");
+
RNA_define_lib_overridable(false);
}
More information about the Bf-blender-cvs
mailing list