Merge branch 'blender-v2.81-release'
This commit is contained in:
commit
e83a23acb2
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue