Skip to content

Commit

Permalink
Keep user defined render aspect ratio when scaling for target PF reso…
Browse files Browse the repository at this point in the history
…lution
  • Loading branch information
vbousquet committed Dec 4, 2023
1 parent a4a68be commit c6fe597
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
11 changes: 5 additions & 6 deletions addons/vpx_lightmapper/vlm_render_baker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
7 changes: 4 additions & 3 deletions addons/vpx_lightmapper/vlm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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))


Expand Down

0 comments on commit c6fe597

Please sign in to comment.