From c6fe597759d7a333681ac7bc7e71a2e0c2a73163 Mon Sep 17 00:00:00 2001 From: Vincent Bousquet Date: Tue, 5 Dec 2023 00:12:08 +0100 Subject: [PATCH] Keep user defined render aspect ratio when scaling for target PF resolution --- addons/vpx_lightmapper/vlm_render_baker.py | 11 +++++------ addons/vpx_lightmapper/vlm_utils.py | 7 ++++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/addons/vpx_lightmapper/vlm_render_baker.py b/addons/vpx_lightmapper/vlm_render_baker.py index f10c96c..1270560 100644 --- a/addons/vpx_lightmapper/vlm_render_baker.py +++ b/addons/vpx_lightmapper/vlm_render_baker.py @@ -282,9 +282,8 @@ def render_all_groups(op, context): scene.render.engine = 'CYCLES' scene.render.use_border = False scene.render.use_crop_to_border = False - render_size = vlm_utils.get_render_size(context) - scene.render.resolution_x = render_size[0] - scene.render.resolution_y = render_size[1] + scene.render.resolution_x = opt_render_width + scene.render.resolution_y = opt_render_height scene.render.film_transparent = True scene.view_settings.view_transform = 'Raw' scene.view_settings.look = 'None' @@ -579,7 +578,7 @@ def sortkey(x): # Create temp render scene for rendering object masks & influence map opt_mask_size = 1024 # Height used for the object masks - opt_mask_pad = math.ceil(opt_mask_size * 2 / render_size[1]) + opt_mask_pad = math.ceil(opt_mask_size * 2 / opt_render_height) mask_scene = bpy.data.scenes.new('VLM.Tmp Mask Scene') mask_scene.collection.objects.link(camera_object) mask_scene.camera = camera_object @@ -643,8 +642,8 @@ def sortkey(x): render_ratio = context.scene.vlmSettings.render_ratio / 100.0 img_nodes = [] bake_img = bpy.data.images.new('Bake', int(dup.vlmSettings.bake_width * render_ratio), int(dup.vlmSettings.bake_height * render_ratio), alpha=True, float_buffer=True) - mask_scene.render.resolution_x = render_size[0] - mask_scene.render.resolution_y = render_size[1] + mask_scene.render.resolution_x = opt_render_width + mask_scene.render.resolution_y = opt_render_height for mat in dup.data.materials: node_uvmap = mat.node_tree.nodes.new(type='ShaderNodeAttribute') node_uvmap. attribute_name = 'UVMap' diff --git a/addons/vpx_lightmapper/vlm_utils.py b/addons/vpx_lightmapper/vlm_utils.py index aea3e9c..89a7893 100644 --- a/addons/vpx_lightmapper/vlm_utils.py +++ b/addons/vpx_lightmapper/vlm_utils.py @@ -54,7 +54,7 @@ def get_lm_threshold(): def get_render_size(context): - # render height apply to projected playfield, so upscale accordingly + # render height apply to projected playfield, so upscale accordingly, keeping user defined aspect ratio camera = context.scene.camera if not camera: logger.error("ERROR: missing camera") @@ -80,9 +80,10 @@ def get_render_size(context): if v_size <= 0.0: logger.error("ERROR: invalid view") return + ar = context.scene.render.resolution_x / context.scene.render.resolution_y rh = round(context.scene.vlmSettings.render_height * context.scene.vlmSettings.render_ratio / (100.0 * v_size)) - rw = round(rh * (max_u - min_u) / v_size) - print(f'. Render size set to {int(rw)}x{int(rh)} for an expected playfield render of {round(u_size*rw)}x{round(v_size*rh)}, target playfield height was {round(context.scene.vlmSettings.render_height * context.scene.vlmSettings.render_ratio / 100.0)}') + rw = round(rh * ar) + print(f'. Render size computed to {int(rw)}x{int(rh)} for an expected playfield render of {round(u_size*rw)}x{round(v_size*rh)}, target playfield height was {round(context.scene.vlmSettings.render_height * context.scene.vlmSettings.render_ratio / 100.0)}') return (int(rw), int(rh))