[Bf-blender-cvs] [86e83108fdc] temp-lineart-contained: LineArt: Consistent shifting for persp and ortho cam.

YimingWu noreply at git.blender.org
Fri Feb 25 07:11:47 CET 2022


Commit: 86e83108fdc0ace81f12dbfff2fe07a02a34a7ed
Author: YimingWu
Date:   Fri Feb 25 13:50:23 2022 +0800
Branches: temp-lineart-contained
https://developer.blender.org/rB86e83108fdc0ace81f12dbfff2fe07a02a34a7ed

LineArt: Consistent shifting for persp and ortho cam.

Now always properly shifting camera for ortho and perspective.

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

M	source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c

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

diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index c96361a139d..d44a8e8ba69 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -1432,21 +1432,20 @@ static void lineart_main_perspective_division(LineartRenderBuffer *rb)
   LineartVert *vt;
   int i;
 
-  if (!rb->cam_is_persp) {
-    return;
-  }
-
   LISTBASE_FOREACH (LineartElementLinkNode *, eln, &rb->vertex_buffer_pointers) {
     vt = eln->pointer;
     for (i = 0; i < eln->element_count; i++) {
-      /* Do not divide Z, we use Z to back transform cut points in later chaining process. */
-      vt[i].fbcoord[0] /= vt[i].fbcoord[3];
-      vt[i].fbcoord[1] /= vt[i].fbcoord[3];
-      /* Re-map z into (0-1) range, because we no longer need NDC (Normalized Device Coordinates)
-       * at the moment.
-       * The algorithm currently doesn't need Z for operation, we use W instead. If Z is needed in
-       * the future, the line below correctly transforms it to view space coordinates. */
-      // `vt[i].fbcoord[2] = -2 * vt[i].fbcoord[2] / (far - near) - (far + near) / (far - near);
+      if (rb->cam_is_persp) {
+        /* Do not divide Z, we use Z to back transform cut points in later chaining process. */
+        vt[i].fbcoord[0] /= vt[i].fbcoord[3];
+        vt[i].fbcoord[1] /= vt[i].fbcoord[3];
+        /* Re-map z into (0-1) range, because we no longer need NDC (Normalized Device Coordinates)
+         * at the moment.
+         * The algorithm currently doesn't need Z for operation, we use W instead. If Z is needed
+         * in the future, the line below correctly transforms it to view space coordinates. */
+        // `vt[i].fbcoord[2] = -2 * vt[i].fbcoord[2] / (far - near) - (far + near) / (far - near);
+      }
+      /* Shifting is always needed. */
       vt[i].fbcoord[0] -= rb->shift_x * 2;
       vt[i].fbcoord[1] -= rb->shift_y * 2;
     }
@@ -2602,19 +2601,16 @@ static bool lineart_triangle_edge_image_space_occlusion(SpinLock *UNUSED(spl),
     interp_v3_v3v3_db(gloc, e->v1->gloc, e->v2->gloc, cut);
     mul_v4_m4v3_db(trans, vp, gloc);
     mul_v3db_db(trans, (1 / trans[3]));
-  }
-  else {
-    interp_v3_v3v3_db(trans, e->v1->fbcoord, e->v2->fbcoord, cut);
-  }
-  trans[0] -= cam_shift_x * 2;
-  trans[1] -= cam_shift_y * 2;
-
-  /* To accommodate `k=0` and `k=inf` (vertical) lines. here the cut is in image space. */
-  if (fabs(e->v1->fbcoord[0] - e->v2->fbcoord[0]) > fabs(e->v1->fbcoord[1] - e->v2->fbcoord[1])) {
-    cut = ratiod(e->v1->fbcoord[0], e->v2->fbcoord[0], trans[0]);
-  }
-  else {
-    cut = ratiod(e->v1->fbcoord[1], e->v2->fbcoord[1], trans[1]);
+    trans[0] -= cam_shift_x * 2;
+    trans[1] -= cam_shift_y * 2;
+    /* To accommodate `k=0` and `k=inf` (vertical) lines. here the cut is in image space. */
+    if (fabs(e->v1->fbcoord[0] - e->v2->fbcoord[0]) >
+        fabs(e->v1->fbcoord[1] - e->v2->fbcoord[1])) {
+      cut = ratiod(e->v1->fbcoord[0], e->v2->fbcoord[0], trans[0]);
+    }
+    else {
+      cut = ratiod(e->v1->fbcoord[1], e->v2->fbcoord[1], trans[1]);
+    }
   }
 
 #define LRT_GUARD_NOT_FOUND \
@@ -4091,8 +4087,11 @@ static void lineart_create_edges_from_isec_data(LineartIsecData *d)
        * them as well. */
       mul_v4_m4v3_db(v1->fbcoord, rb->view_projection, v1->gloc);
       mul_v4_m4v3_db(v2->fbcoord, rb->view_projection, v2->gloc);
-      mul_v3db_db(v1->fbcoord, (1 / v1->fbcoord[3]));
-      mul_v3db_db(v2->fbcoord, (1 / v2->fbcoord[3]));
+
+      if (rb->cam_is_persp) {
+        mul_v3db_db(v1->fbcoord, (1 / v1->fbcoord[3]));
+        mul_v3db_db(v2->fbcoord, (1 / v2->fbcoord[3]));
+      }
 
       v1->fbcoord[0] -= rb->shift_x * 2;
       v1->fbcoord[1] -= rb->shift_y * 2;



More information about the Bf-blender-cvs mailing list