[Bf-blender-cvs] [0f2e0a25e13] master: LineArt: Consistent backface culling behavior

YimingWu noreply at git.blender.org
Tue Feb 22 05:52:21 CET 2022


Commit: 0f2e0a25e13d2d67f3d08d068ba11e255794bb6b
Author: YimingWu
Date:   Tue Feb 22 12:51:49 2022 +0800
Branches: master
https://developer.blender.org/rB0f2e0a25e13d2d67f3d08d068ba11e255794bb6b

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

===================================================================

M	release/datafiles/locale
M	release/scripts/addons
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/tools

===================================================================

diff --git a/release/datafiles/locale b/release/datafiles/locale
index 2d12637a69d..2a5095eed30 160000
--- a/release/datafiles/locale
+++ b/release/datafiles/locale
@@ -1 +1 @@
-Subproject commit 2d12637a69df7643484a8a3655b7eeb6faa170a7
+Subproject commit 2a5095eed3028e91624d27ca93e4c65f572b809d
diff --git a/release/scripts/addons b/release/scripts/addons
index 089aef61deb..bb62f10715a 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit 089aef61debbece2baff6516e33fc7491629b1d0
+Subproject commit bb62f10715a871d7069d2b2c74b2efc97c3c350c
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
index 515e67c1932..7fd2ed908b4 160000
--- a/source/tools
+++ b/source/tools
@@ -1 +1 @@
-Subproject commit 515e67c1932bc06f24cb50b621265c2a6e8a25a9
+Subproject commit 7fd2ed908b4f50140670caf6786e5ed245b79137



More information about the Bf-blender-cvs mailing list