[Bf-blender-cvs] [4fec2b06604] blender-v2.81-release: Fix T48034: Camera image offsets were scaled by image aspect

Campbell Barton noreply at git.blender.org
Fri Nov 1 23:09:55 CET 2019


Commit: 4fec2b0660452adaeb4e1a309901bb3650af9419
Author: Campbell Barton
Date:   Sat Nov 2 07:47:27 2019 +1100
Branches: blender-v2.81-release
https://developer.blender.org/rB4fec2b0660452adaeb4e1a309901bb3650af9419

Fix T48034: Camera image offsets were scaled by image aspect

Offset now matches Blender 2.7x.

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

M	source/blender/draw/modes/object_mode.c

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

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,



More information about the Bf-blender-cvs mailing list