[Bf-blender-cvs] [3d2db8c03de] lineart-shadow: LineArt: Continue shadowing

YimingWu noreply at git.blender.org
Tue Jul 13 10:45:55 CEST 2021


Commit: 3d2db8c03de72621bf23b6b8c3f91a8810281086
Author: YimingWu
Date:   Sat Jul 10 13:28:44 2021 +0800
Branches: lineart-shadow
https://developer.blender.org/rB3d2db8c03de72621bf23b6b8c3f91a8810281086

LineArt: Continue shadowing

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

M	source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
M	source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
M	source/blender/gpencil_modifiers/intern/lineart/lineart_intern.h

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

diff --git a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
index a92382aee0d..3bc8f6d14a0 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
+++ b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
@@ -106,11 +106,21 @@ typedef struct LineartEdgeSegment {
   unsigned char material_mask_bits;
 } LineartEdgeSegment;
 
+typedef struct LineartShadowEdge {
+  /* Two end points in framebuffer coordinates viiewed from the light source. */
+  double fbc1[4], fbc2[4];
+  ListBase shadow_segments;
+} LineartShadowSegmentContainer;
+
 typedef struct LineartShadowSegment {
-  LineartEdgeSegment base;
-  /* global left and right pos, because when casting shadows at some point there will be
+  struct LineartShadowSegment *prev, *next;
+  /* In NDC, not in global linear. */
+  double at;
+  /* Left and right pos, because when casting shadows at some point there will be
    * non-continuous cuts. */
-  double gl[4], gr[4];
+  double fbc1[4], fbc2[4];
+  /* Global position. */
+  double g1[4], g2[4];
 } LineartShadowSegment;
 
 typedef struct LineartVert {
@@ -291,6 +301,8 @@ typedef struct LineartRenderBuffer {
 
   ListBase chains;
 
+  ListBase shadow_segments;
+
   /* For managing calculation tasks for multiple threads. */
   SpinLock lock_task;
 
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index 078acdfad3e..5484142f12c 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -94,14 +94,16 @@ typedef struct LineartIsecData {
 } LineartIsecData;
 
 static LineartBoundingArea *lineart_edge_first_bounding_area(LineartRenderBuffer *rb,
-                                                             LineartEdge *e);
+                                                             double *fbcoord1,
+                                                             double *fbcoord2);
 
 static void lineart_bounding_area_link_edge(LineartRenderBuffer *rb,
                                             LineartBoundingArea *root_ba,
                                             LineartEdge *e);
 
 static LineartBoundingArea *lineart_bounding_area_next(LineartBoundingArea *this,
-                                                       LineartEdge *e,
+                                                       double *fbcoord1,
+                                                       double *fbcoord2,
                                                        double x,
                                                        double y,
                                                        double k,
@@ -385,32 +387,26 @@ static void lineart_bounding_area_line_add(LineartRenderBuffer *rb,
   ba->line_count++;
 }
 
-#define LRT_EDGE_BA_MARCHING_BEGIN \
-  double x = e->v1->fbcoord[0], y = e->v1->fbcoord[1]; \
-  LineartBoundingArea *ba = lineart_edge_first_bounding_area(rb, e); \
+#define LRT_EDGE_BA_MARCHING_BEGIN(fb1, fb2) \
+  double x = fb1[0], y = fb1[1]; \
+  LineartBoundingArea *ba = lineart_edge_first_bounding_area(rb, fb1, fb2); \
   LineartBoundingArea *nba = ba; \
-  LineartTriangleThread *tri; \
-  /* These values are used for marching along the line. */ \
-  double l, r; \
-  double k = (e->v2->fbcoord[1] - e->v1->fbcoord[1]) / \
-             (e->v2->fbcoord[0] - e->v1->fbcoord[0] + 1e-30); \
-  int positive_x = (e->v2->fbcoord[0] - e->v1->fbcoord[0]) > 0 ? \
-                       1 : \
-                       (e->v2->fbcoord[0] == e->v1->fbcoord[0] ? 0 : -1); \
-  int positive_y = (e->v2->fbcoord[1] - e->v1->fbcoord[1]) > 0 ? \
-                       1 : \
-                       (e->v2->fbcoord[1] == e->v1->fbcoord[1] ? 0 : -1); \
+  double k = (fb2[1] - fb1[1]) / (fb2[0] - fb1[0] + 1e-30); \
+  int positive_x = (fb2[0] - fb1[0]) > 0 ? 1 : (fb2[0] == fb1[0] ? 0 : -1); \
+  int positive_y = (fb2[1] - fb1[1]) > 0 ? 1 : (fb2[1] == fb1[1] ? 0 : -1); \
   while (nba)
 
-#define LRT_EDGE_BA_MARCHING_NEXT \
+#define LRT_EDGE_BA_MARCHING_NEXT(fb1, fb2) \
   /* Marching along `e->v1` to `e->v2`, searching each possible bounding areas it may touch. */ \
-  nba = lineart_bounding_area_next(nba, e, x, y, k, positive_x, positive_y, &x, &y);
+  nba = lineart_bounding_area_next(nba, fb1, fb2, x, y, k, positive_x, positive_y, &x, &y);
 
 #define LRT_EDGE_BA_MARCHING_END
 
 static void lineart_occlusion_single_line(LineartRenderBuffer *rb, LineartEdge *e, int thread_id)
 {
-  LRT_EDGE_BA_MARCHING_BEGIN
+  LineartTriangleThread *tri;
+  double l, r;
+  LRT_EDGE_BA_MARCHING_BEGIN(e->v1->fbcoord, e->v2->fbcoord)
   {
     for (int i = 0; i < nba->triangle_count; i++) {
       tri = (LineartTriangleThread *)nba->linked_triangles[i];
@@ -444,7 +440,7 @@ static void lineart_occlusion_single_line(LineartRenderBuffer *rb, LineartEdge *
         }
       }
     }
-    LRT_EDGE_BA_MARCHING_NEXT
+    LRT_EDGE_BA_MARCHING_NEXT(e->v1->fbcoord, e->v2->fbcoord)
   }
   LRT_EDGE_BA_MARCHING_END
 }
@@ -4040,9 +4036,10 @@ static void lineart_main_add_triangles(LineartRenderBuffer *rb)
  * to get next along the way.
  */
 static LineartBoundingArea *lineart_edge_first_bounding_area(LineartRenderBuffer *rb,
-                                                             LineartEdge *e)
+                                                             double *fbcoord1,
+                                                             double *fbcoord2)
 {
-  double data[2] = {e->v1->fbcoord[0], e->v1->fbcoord[1]};
+  double data[2] = {fbcoord1[0], fbcoord1[1]};
   double LU[2] = {-1, 1}, RU[2] = {1, 1}, LB[2] = {-1, -1}, RB[2] = {1, -1};
   double r = 1, sr = 1;
 
@@ -4050,23 +4047,19 @@ static LineartBoundingArea *lineart_edge_first_bounding_area(LineartRenderBuffer
     return lineart_get_bounding_area(rb, data[0], data[1]);
   }
 
-  if (lineart_LineIntersectTest2d(e->v1->fbcoord, e->v2->fbcoord, LU, RU, &sr) && sr < r &&
-      sr > 0) {
+  if (lineart_LineIntersectTest2d(fbcoord1, fbcoord2, LU, RU, &sr) && sr < r && sr > 0) {
     r = sr;
   }
-  if (lineart_LineIntersectTest2d(e->v1->fbcoord, e->v2->fbcoord, LB, RB, &sr) && sr < r &&
-      sr > 0) {
+  if (lineart_LineIntersectTest2d(fbcoord1, fbcoord2, LB, RB, &sr) && sr < r && sr > 0) {
     r = sr;
   }
-  if (lineart_LineIntersectTest2d(e->v1->fbcoord, e->v2->fbcoord, LB, LU, &sr) && sr < r &&
-      sr > 0) {
+  if (lineart_LineIntersectTest2d(fbcoord1, fbcoord2, LB, LU, &sr) && sr < r && sr > 0) {
     r = sr;
   }
-  if (lineart_LineIntersectTest2d(e->v1->fbcoord, e->v2->fbcoord, RB, RU, &sr) && sr < r &&
-      sr > 0) {
+  if (lineart_LineIntersectTest2d(fbcoord1, fbcoord2, RB, RU, &sr) && sr < r && sr > 0) {
     r = sr;
   }
-  interp_v2_v2v2_db(data, e->v1->fbcoord, e->v2->fbcoord, r);
+  interp_v2_v2v2_db(data, fbcoord1, fbcoord2, r);
 
   return lineart_get_bounding_area(rb, data[0], data[1]);
 }
@@ -4076,7 +4069,8 @@ static LineartBoundingArea *lineart_edge_first_bounding_area(LineartRenderBuffer
  * get the next bounding area the line is crossing.
  */
 static LineartBoundingArea *lineart_bounding_area_next(LineartBoundingArea *this,
-                                                       LineartEdge *e,
+                                                       double *fbcoord1,
+                                                       double *fbcoord2,
                                                        double x,
                                                        double y,
                                                        double k,
@@ -4098,8 +4092,8 @@ static LineartBoundingArea *lineart_bounding_area_next(LineartBoundingArea *this
     if (positive_y > 0) {
       uy = this->u;
       ux = x + (uy - y) / k;
-      r1 = ratiod(e->v1->fbcoord[0], e->v2->fbcoord[0], rx);
-      r2 = ratiod(e->v1->fbcoord[0], e->v2->fbcoord[0], ux);
+      r1 = ratiod(fbcoord1[0], fbcoord2[0], rx);
+      r2 = ratiod(fbcoord1[0], fbcoord2[0], ux);
       if (MIN2(r1, r2) > 1) {
         return 0;
       }
@@ -4131,8 +4125,8 @@ static LineartBoundingArea *lineart_bounding_area_next(LineartBoundingArea *this
     else if (positive_y < 0) {
       by = this->b;
       bx = x + (by - y) / k;
-      r1 = ratiod(e->v1->fbcoord[0], e->v2->fbcoord[0], rx);
-      r2 = ratiod(e->v1->fbcoord[0], e->v2->fbcoord[0], bx);
+      r1 = ratiod(fbcoord1[0], fbcoord2[0], rx);
+      r2 = ratiod(fbcoord1[0], fbcoord2[0], bx);
       if (MIN2(r1, r2) > 1) {
         return 0;
       }
@@ -4159,7 +4153,7 @@ static LineartBoundingArea *lineart_bounding_area_next(LineartBoundingArea *this
     }
     /* If the line is completely horizontal, in which Y difference == 0. */
     else {
-      r1 = ratiod(e->v1->fbcoord[0], e->v2->fbcoord[0], this->r);
+      r1 = ratiod(fbcoord1[0], fbcoord2[0], this->r);
       if (r1 > 1) {
         return 0;
       }
@@ -4183,8 +4177,8 @@ static LineartBoundingArea *lineart_bounding_area_next(LineartBoundingArea *this
     if (positive_y > 0) {
       uy = this->u;
       ux = x + (uy - y) / k;
-      r1 = ratiod(e->v1->fbcoord[0], e->v2->fbcoord[0], lx);
-      r2 = ratiod(e->v1->fbcoord[0], e->v2->fbcoord[0], ux);
+      r1 = ratiod(fbcoord1[0], fbcoord2[0], lx);
+      r2 = ratiod(fbcoord1[0], fbcoord2[0], ux);
       if (MIN2(r1, r2) > 1) {
         return 0;
       }
@@ -4214,8 +4208,8 @@ static LineartBoundingArea *lineart_bounding_area_next(LineartBoundingArea *this
     else if (positive_y < 0) {
       by = this->b;
       bx = x + (by - y) / k;
-      r1 = ratiod(e->v1->fbcoord[0], e->v2->fbcoord[0], lx);
-      r2 = ratiod(e->v1->fbcoord[0], e->v2->fbcoord[0], bx);
+      r1 = ratiod(fbcoord1[0], fbcoord2[0], lx);
+      r2 = ratiod(fbcoord1[0], fbcoord2[0], bx);
       if (MIN2(r1, r2) > 1) {
         return 0;
       }
@@ -4242,7 +4236,7 @@ static LineartBoundingArea *lineart_bounding_area_next(LineartBoundingArea *this
     }
     /* Again, horizontal. */
     else {
-      r1 = ratiod(e->v1->fbcoord[0], e->v2->fbcoord[0], this->l);
+      r1 = ratiod(fbcoord1[0], fbcoord2[0], this->l);
       if (r1 > 1) {
         return 0;
       }
@@ 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list