Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-11-02 01:10:13 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-11-02 01:10:13 +0300
commite83a23acb2a835fede1c2d59b0738171dd04a192 (patch)
tree44502f7e32a59230aebc1d0637fe8353e969a607
parente9da7a5b8de7f4e2bb399de256a0116836f830df (diff)
parent4fec2b0660452adaeb4e1a309901bb3650af9419 (diff)
Merge branch 'blender-v2.81-release'
-rw-r--r--source/blender/draw/modes/object_mode.c45
1 files 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,