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
path: root/source
diff options
context:
space:
mode:
authorJeroen Bakker <j.bakker@atmind.nl>2019-08-07 16:43:44 +0300
committerJeroen Bakker <j.bakker@atmind.nl>2019-08-08 08:53:21 +0300
commit66356dae943d50215be7699d842989b5e7fe0398 (patch)
treeeadc58ebbed092f59039f2223241543621b9865b /source
parent9fd9d90247305e3d1453ac6b8936b49e7dc492f3 (diff)
Fix T67638: Stretched Camera Background Images
The matrices that projects background images in the 3d view were incorrect. The root cause was that the coordinate systems were not respected, that was most noticeable when rotating a stretched image. We re-validated conversions of coordinate spaces (UV -> Image -> Camera -> Window) and made sure that the rotation is done in image space. Reviewed By: campbellbarton Differential Revision: https://developer.blender.org/D5431
Diffstat (limited to 'source')
-rw-r--r--source/blender/draw/modes/object_mode.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c
index 98c52c300cf..87fc74f1f72 100644
--- a/source/blender/draw/modes/object_mode.c
+++ b/source/blender/draw/modes/object_mode.c
@@ -1254,9 +1254,9 @@ static void DRW_shgroup_camera_background_images(OBJECT_Shaders *sh_data,
float camera_aspect_y = 1.0;
float camera_offset_x = 0.0;
float camera_offset_y = 0.0;
- float camera_aspect = 1.0;
float camera_width = size[0];
float camera_height = size[1];
+ float camera_aspect = camera_width / camera_height;
if (!DRW_state_is_image_render()) {
rctf render_border;
@@ -1284,48 +1284,52 @@ static void DRW_shgroup_camera_background_images(OBJECT_Shaders *sh_data,
uv2img_space[0][0] = image_width;
uv2img_space[1][1] = image_height;
- img2cam_space[0][0] = (1.0 / image_width);
- img2cam_space[1][1] = (1.0 / 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;
/* Update scaling based on image and camera framing */
float scale_x = bgpic->scale;
float scale_y = bgpic->scale;
if (bgpic->flag & CAM_BGIMG_FLAG_CAMERA_ASPECT) {
- float fit_scale = image_aspect / camera_aspect;
if (bgpic->flag & CAM_BGIMG_FLAG_CAMERA_CROP) {
if (image_aspect > camera_aspect) {
scale_x *= fit_scale;
- }
- else {
- scale_y /= fit_scale;
+ scale_y *= fit_scale;
}
}
else {
if (image_aspect > camera_aspect) {
+ scale_x /= fit_scale;
scale_y /= fit_scale;
}
else {
scale_x *= fit_scale;
+ scale_y *= fit_scale;
}
}
}
+ else {
+ /* Stretch image to camera aspect */
+ scale_y /= 1.0 / fit_scale;
+ }
// scale image to match the desired aspect ratio
scale_m4[0][0] = scale_x;
scale_m4[1][1] = scale_y;
- /* Translate, using coordinates that aren't squashed by the aspect. */
- translate_m4[3][0] = bgpic->offset[0] * 2.0f * max_ff(1.0f, 1.0f / camera_aspect);
- translate_m4[3][1] = bgpic->offset[1] * 2.0f * max_ff(1.0f, camera_aspect);
+ /* Translate */
+ translate_m4[3][0] = image_width * bgpic->offset[0] * 2.0f;
+ translate_m4[3][1] = image_height * bgpic->offset[1] * 2.0f;
mul_m4_series(bg_data->transform_mat,
win_m4_translate,
win_m4_scale,
- translate_m4,
img2cam_space,
- scale_m4,
+ translate_m4,
rot_m4,
+ scale_m4,
uv2img_space);
DRWPass *pass = (bgpic->flag & CAM_BGIMG_FLAG_FOREGROUND) ? psl->camera_images_front :