[Bf-blender-cvs] [610588702f8] temp-lanpr-cleanup2: LANPR: Ortho camera live update support for viewport.
YimingWu
noreply at git.blender.org
Wed Nov 13 06:05:29 CET 2019
Commit: 610588702f8dd454d342d26b97eed7ecaed2f19a
Author: YimingWu
Date: Wed Nov 13 13:02:23 2019 +0800
Branches: temp-lanpr-cleanup2
https://developer.blender.org/rB610588702f8dd454d342d26b97eed7ecaed2f19a
LANPR: Ortho camera live update support for viewport.
Note: Incorrect view direction leads to incorrect contour in ortho
viewport, in render mode both ortho and perspective is working.
===================================================================
M source/blender/draw/engines/lanpr/lanpr_engine.c
M source/blender/editors/include/ED_lanpr.h
M source/blender/editors/lanpr/lanpr_cpu.c
===================================================================
diff --git a/source/blender/draw/engines/lanpr/lanpr_engine.c b/source/blender/draw/engines/lanpr/lanpr_engine.c
index 887b404e014..1e00e75a2fa 100644
--- a/source/blender/draw/engines/lanpr/lanpr_engine.c
+++ b/source/blender/draw/engines/lanpr/lanpr_engine.c
@@ -234,6 +234,7 @@ static void lanpr_cache_init(void *vedata)
lanpr_share.near_clip = v3d->clip_start;
lanpr_share.far_clip = v3d->clip_end;
lanpr_share.viewport_camera_override = 1;
+ lanpr_share.camera_is_persp = rv3d->is_persp;
}
else {
lanpr_share.viewport_camera_override = 0;
diff --git a/source/blender/editors/include/ED_lanpr.h b/source/blender/editors/include/ED_lanpr.h
index 1ce18304dfd..808f3cc814f 100644
--- a/source/blender/editors/include/ED_lanpr.h
+++ b/source/blender/editors/include/ED_lanpr.h
@@ -295,6 +295,7 @@ typedef struct LANPR_RenderBuffer {
int _pad;
int viewport_override;
+ char viewport_is_persp;
double camera_pos[3];
double near_clip, far_clip;
} LANPR_RenderBuffer;
@@ -350,6 +351,7 @@ typedef struct LANPR_SharedResource {
/** When drawing in the viewport, use the following values. */
/** Set to override to -1 before creating lanpr render buffer to use scene camera. */
int viewport_camera_override;
+ char camera_is_persp;
double camera_pos[3];
double near_clip, far_clip;
double viewinv[4][4];
diff --git a/source/blender/editors/lanpr/lanpr_cpu.c b/source/blender/editors/lanpr/lanpr_cpu.c
index 43cc63f195b..d566e1057d8 100644
--- a/source/blender/editors/lanpr/lanpr_cpu.c
+++ b/source/blender/editors/lanpr/lanpr_cpu.c
@@ -95,6 +95,7 @@ static int lanpr_triangle_line_imagespace_intersection_v2(SpinLock *spl,
LANPR_RenderLine *rl,
Object *cam,
double *override_camera_loc,
+ char override_cam_is_persp,
double vp[4][4],
double *CameraDir,
double *From,
@@ -674,10 +675,6 @@ static void lanpr_calculate_single_line_occlusion(LANPR_RenderBuffer *rb,
1 :
(rl->r->fbcoord[1] == rl->l->fbcoord[1] ? 0 : -1);
- /* printf("PX %d %lf PY %d %lf\n", PositiveX, rl->r->fbcoord[0] - */
- /* rl->l->fbcoord[0], PositiveY, rl->r->fbcoord[1] - */
- /* rl->l->fbcoord[1]); */
-
while (nba) {
for (lip = nba->linked_triangles.first; lip; lip = lip->next) {
@@ -693,6 +690,7 @@ static void lanpr_calculate_single_line_occlusion(LANPR_RenderBuffer *rb,
c,
rb->viewport_override ? rb->camera_pos :
NULL,
+ rb->viewport_is_persp,
rb->view_projection,
rb->view_vector,
&l,
@@ -1023,18 +1021,18 @@ static void lanpr_cull_triangles(LANPR_RenderBuffer *rb)
int v_count = 0, t_count = 0;
Object *o;
-
double view_dir[3], clip_advance[3];
copy_v3_v3_db(view_dir, rb->view_vector);
copy_v3_v3_db(clip_advance, rb->view_vector);
double cam_pos[3];
double clip_start, clip_end;
- if(rb->viewport_override){
+ if (rb->viewport_override) {
copy_v3_v3_db(cam_pos, rb->camera_pos);
clip_start = rb->near_clip;
clip_end = rb->far_clip;
- }else{
+ }
+ else {
Object *cam = ((Object *)rb->scene->camera);
cam_pos[0] = cam->obmat[3][0];
cam_pos[1] = cam->obmat[3][1];
@@ -1043,8 +1041,6 @@ static void lanpr_cull_triangles(LANPR_RenderBuffer *rb)
add_v3_v3_db(cam_pos, clip_advance);
}
-
-
veln = lanpr_new_cull_point_space64(rb);
teln = lanpr_new_cull_triangle_space64(rb);
rv = &((LANPR_RenderVert *)veln->pointer)[v_count];
@@ -1566,10 +1562,11 @@ static void lanpr_perspective_division(LANPR_RenderBuffer *rb)
{
LANPR_RenderVert *rv;
LANPR_RenderElementLinkNode *reln;
- Camera *cam = rb->scene->camera? rb->scene->camera->data : NULL;
+ Camera *cam = rb->scene->camera ? rb->scene->camera->data : NULL;
int i;
- if (cam && cam->type != CAM_PERSP) {
+ if ((rb->viewport_override && (!rb->viewport_is_persp)) ||
+ (!rb->viewport_override && cam && cam->type != CAM_PERSP)) {
return;
}
@@ -1577,7 +1574,7 @@ static void lanpr_perspective_division(LANPR_RenderBuffer *rb)
rv = reln->pointer;
for (i = 0; i < reln->element_count; i++) {
mul_v3db_db(rv[i].fbcoord, 1 / rv[i].fbcoord[3]);
- if(cam){
+ if (cam) {
rv[i].fbcoord[0] -= cam->shiftx * 2;
rv[i].fbcoord[1] -= cam->shifty * 2;
}
@@ -1826,6 +1823,8 @@ static void lanpr_make_render_geometry_buffers(Depsgraph *depsgraph,
/* lock becore accessing shared status data */
BLI_spin_lock(&lanpr_share.lock_render_status);
+ memset(rb->material_pointers, 0, sizeof(void *) * 2048);
+
if (lanpr_share.viewport_camera_override) {
copy_m4_m4_db(proj, lanpr_share.persp);
invert_m4_m4(inv, lanpr_share.viewinv);
@@ -1839,8 +1838,6 @@ static void lanpr_make_render_geometry_buffers(Depsgraph *depsgraph,
float sensor = BKE_camera_sensor_size(cam->sensor_fit, cam->sensor_x, cam->sensor_y);
real fov = focallength_to_fov(cam->lens, sensor);
- memset(rb->material_pointers, 0, sizeof(void *) * 2048);
-
real asp = ((real)rb->w / (real)rb->h);
if (cam->type == CAM_PERSP) {
@@ -1924,6 +1921,7 @@ static int lanpr_triangle_line_imagespace_intersection_v2(SpinLock *UNUSED(spl),
LANPR_RenderLine *rl,
Object *cam,
double *override_cam_loc,
+ char override_cam_is_persp,
double vp[4][4],
double *CameraDir,
double *From,
@@ -1947,12 +1945,6 @@ static int lanpr_triangle_line_imagespace_intersection_v2(SpinLock *UNUSED(spl),
double *LFBC = rl->l->fbcoord, *RFBC = rl->r->fbcoord, *FBC0 = rt->v[0]->fbcoord,
*FBC1 = rt->v[1]->fbcoord, *FBC2 = rt->v[2]->fbcoord;
- /* printf("(%f %f)(%f %f)(%f %f) (%f %f)(%f %f)\n", FBC0[0], FBC0[1], FBC1[0], FBC1[1], */
- /* FBC2[0], FBC2[1], LFBC[0], LFBC[1], RFBC[0], RFBC[1]); */
-
- /* bound box. */
- /* if (MIN3(FBC0[2], FBC1[2], FBC2[2]) > MAX2(LFBC[2], RFBC[2])) */
- /* return 0; */
if ((MAX3(FBC0[0], FBC1[0], FBC2[0]) < MIN2(LFBC[0], RFBC[0])) ||
(MIN3(FBC0[0], FBC1[0], FBC2[0]) > MAX2(LFBC[0], RFBC[0])) ||
(MAX3(FBC0[1], FBC1[1], FBC2[1]) < MIN2(LFBC[1], RFBC[1])) ||
@@ -1977,13 +1969,14 @@ static int lanpr_triangle_line_imagespace_intersection_v2(SpinLock *UNUSED(spl),
copy_v3_v3_db(Cv, CameraDir);
- if (override_cam_loc) {
+ if ((override_cam_loc && override_cam_is_persp)) {
copy_v3_v3_db(vd4, override_cam_loc);
}
else {
copy_v4db_v4fl(vd4, cam->obmat[3]);
}
- if (override_cam_loc || (((Camera *)cam->data)->type == CAM_PERSP)) {
+ if ((override_cam_loc && override_cam_is_persp) ||
+ (!override_cam_loc && ((Camera *)cam->data)->type == CAM_PERSP)) {
sub_v3_v3v3_db(Cv, vd4, rt->v[0]->gloc);
}
@@ -2005,13 +1998,6 @@ static int lanpr_triangle_line_imagespace_intersection_v2(SpinLock *UNUSED(spl),
StL = lanpr_point_triangle_relation(LFBC, FBC0, FBC1, FBC2);
StR = lanpr_point_triangle_relation(RFBC, FBC0, FBC1, FBC2);
- /* for (rv = rt->intersecting_verts.first; rv; rv = rv->next) { */
- /* if (rv->intersecting_with == rt && rv->intersecting_line == rl) { */
- /* Cut = tMatGetLinearRatio(rl->l->fbcoord[0], rl->r->fbcoord[0], */
- /* rv->fbcoord[0]); break; */
- /* } */
- /* } */
-
DotLA = fabs(DotL);
if (DotLA < DBL_EPSILON) {
DotLA = 0;
@@ -2033,11 +2019,12 @@ static int lanpr_triangle_line_imagespace_intersection_v2(SpinLock *UNUSED(spl),
Cut = DotRA > DotLA ? 1 - Cut : Cut;
}
- if (override_cam_loc || (((Camera *)cam->data)->type == CAM_PERSP)) {
+ if ((override_cam_loc && override_cam_is_persp) ||
+ (!override_cam_loc && ((Camera *)cam->data)->type == CAM_PERSP)) {
interp_v3_v3v3_db(gloc, rl->l->gloc, rl->r->gloc, Cut);
mul_v4_m4v3_db(Trans, vp, gloc);
- mul_v3db_db(Trans, (1 / Trans[3]) /**HeightMultiply/2*/);
- if(cam){
+ mul_v3db_db(Trans, (1 / Trans[3]));
+ if (cam) {
Camera *camera = cam->data;
Trans[0] -= camera->shiftx * 2;
Trans[1] -= camera->shifty * 2;
@@ -2045,7 +2032,6 @@ static int lanpr_triangle_line_imagespace_intersection_v2(SpinLock *UNUSED(spl),
}
else {
interp_v3_v3v3_db(Trans, rl->l->fbcoord, rl->r->fbcoord, Cut);
- /* mul_v4_m4v3_db(Trans, vp, gloc); */
}
/* prevent vertical problem ? */
@@ -2268,9 +2254,6 @@ static LANPR_RenderVert *lanpr_triangle_line_intersection_test(LANPR_RenderBuffe
gloc, testing->v[0]->gloc, testing->v[1]->gloc, testing->v[2]->gloc))) {
return 0;
}
- /*else if(result < 0) {
- return 0;
- }*/
Result = mem_static_aquire(&rb->render_data_pool, sizeof(LANPR_RenderVert));
@@ -2308,11 +2291,12 @@ static LANPR_RenderLine *lanpr_triangle_generate_intersection_line_only(
double ZMin, ZMax;
Camera *cam;
- if(rb->viewport_override){
+ if (rb->viewport_override) {
ZMax = rb->far_clip;
ZMin = rb->near_clip;
copy_v3db_v3fl(cl, rb->camera_pos);
- }else{
+ }
+ else {
ZMax = ((Camera *)rb->camera->data)->clip_end;
ZMin = ((Camera *)rb->camera->data)->clip_start;
cam = rb->camera->data;
@@ -2406,7 +2390,7 @@ static LANPR_Re
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list