From 4fec2b0660452adaeb4e1a309901bb3650af9419 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 2 Nov 2019 07:47:27 +1100 Subject: Fix T48034: Camera image offsets were scaled by image aspect Offset now matches Blender 2.7x. --- source/blender/draw/modes/object_mode.c | 45 +++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c index 70bccb4849c..fe17019a5b5 100644 --- a/source/blender/draw/modes/object_mode.c +++ b/source/blender/draw/modes/object_mode.c @@ -1235,22 +1235,42 @@ static void DRW_shgroup_camera_background_images(OBJECT_Shaders *sh_data, uv2img_space[1][1] = image_height; const float fit_scale = image_aspect / camera_aspect; - img2cam_space[0][0] = 1.0 / image_width; - img2cam_space[1][1] = 1.0 / fit_scale / image_height; + if (camera_aspect < image_aspect) { + img2cam_space[0][0] = 1.0 / (1.0 / fit_scale) / image_width; + img2cam_space[1][1] = 1.0 / image_height; + } + else { + img2cam_space[0][0] = 1.0 / image_width; + img2cam_space[1][1] = 1.0 / fit_scale / image_height; + } /* Update scaling based on image and camera framing */ float scale_x = bgpic->scale; float scale_y = bgpic->scale; + float scale_x_offset = image_width; + float scale_y_offset = image_height; + if (image_aspect > 1.0f) { + scale_x_offset /= image_aspect; + if (camera_aspect > 1.0f) { + scale_x_offset *= min_ff(image_aspect, camera_aspect); + scale_y_offset *= min_ff(image_aspect, camera_aspect); + } + } + else { + scale_y_offset *= image_aspect; + if (camera_aspect < 1.0f) { + scale_x_offset /= max_ff(image_aspect, camera_aspect); + scale_y_offset /= max_ff(image_aspect, camera_aspect); + } + } + if (bgpic->flag & CAM_BGIMG_FLAG_CAMERA_ASPECT) { if (bgpic->flag & CAM_BGIMG_FLAG_CAMERA_CROP) { - if (image_aspect > camera_aspect) { - scale_x *= fit_scale; - scale_y *= fit_scale; - } + /* pass */ } else { - if (image_aspect > camera_aspect) { + if (camera_aspect < image_aspect) { scale_x /= fit_scale; scale_y /= fit_scale; } @@ -1262,7 +1282,12 @@ static void DRW_shgroup_camera_background_images(OBJECT_Shaders *sh_data, } else { /* Stretch image to camera aspect */ - scale_y /= 1.0 / fit_scale; + if (camera_aspect < image_aspect) { + scale_x /= fit_scale; + } + else { + scale_y *= fit_scale; + } } // scale image to match the desired aspect ratio @@ -1270,8 +1295,8 @@ static void DRW_shgroup_camera_background_images(OBJECT_Shaders *sh_data, scale_m4[1][1] = scale_y; /* Translate */ - translate_m4[3][0] = image_width * bgpic->offset[0] * 2.0f; - translate_m4[3][1] = image_height * bgpic->offset[1] * 2.0f; + translate_m4[3][0] = bgpic->offset[0] * 2.0f * scale_x_offset; + translate_m4[3][1] = bgpic->offset[1] * 2.0f * scale_y_offset; mul_m4_series(bg_data->transform_mat, win_m4_translate, -- cgit v1.2.3