diff options
author | YimingWu <xp8110@outlook.com> | 2022-02-25 08:50:23 +0300 |
---|---|---|
committer | YimingWu <xp8110@outlook.com> | 2022-02-25 08:57:27 +0300 |
commit | e7cae5187773f41e62830be597c6f598bff0653f (patch) | |
tree | 6ae40b1ebe41e9cb5b68e7d2b6ba59b804608a1c /source/blender | |
parent | 7d7dd66ba78fc97795edeb7c1a0221e4bb676c85 (diff) |
Fix T95984: Use consistent shifting for persp and ortho cam.
Now always properly shifting camera for ortho and perspective.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c index 31dd37db1a7..2f648d7ed4b 100644 --- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c +++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c @@ -1388,21 +1388,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; } @@ -2521,19 +2520,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 \ @@ -2959,9 +2955,10 @@ static LineartEdge *lineart_triangle_intersect(LineartRenderBuffer *rb, * 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; v2->fbcoord[0] -= rb->shift_x * 2; |