Distributed rendering of single images #104327

Merged
David Zhang merged 22 commits from David-Zhang-10/flamenco:single-image-render into main 2024-09-03 06:47:49 +02:00
Showing only changes of commit cbbd481407 - Show all commits

View File

@ -187,6 +187,9 @@ render = bpy.context.scene.render
bpy.context.scene.use_nodes = True
render.use_compositing = True
node_tree = bpy.context.scene.node_tree
overscan = 16
# TODO: check if the render layers node actually exists
feed_in_input = None
render_layers_node = None
for node in node_tree.nodes:
@ -198,29 +201,45 @@ for link in node_tree.links:
if link.from_socket == feed_in_input:
feed_in_output = link.to_socket
image_nodes = []
crop_nodes = []
from os import listdir
from os.path import isfile, join
root = "${path.join(renderDir, path.basename(renderOutput))}/######"
image_files = [f for f in listdir(root) if isfile(join(root, f))]
image_nodes = []
translate_nodes = []
for image_file in image_files:
image_node = node_tree.nodes.new('CompositorNodeImage')
image_node.image = bpy.data.images.load(root + '/' + image_file)
image_nodes.append(image_node)
crop_node = node_tree.nodes.new('CompositorNodeCrop')
left, top, right, bottom = image_file.split('-')
crop_node.max_x = ${settings.tile_size_x}
crop_node.min_y = ${settings.tile_size_y}
if left == '0':
crop_node.min_x = 0
crop_node.max_x = ${settings.tile_size_x}
else:
crop_node.min_x = overscan
crop_node.max_x = ${settings.tile_size_x} + overscan
if top == '0':
crop_node.max_y = 0
crop_node.min_y = ${settings.tile_size_y}
else:
crop_node.max_y = overscan
crop_node.min_y = ${settings.tile_size_y} + overscan
translate_node = node_tree.nodes.new('CompositorNodeTranslate')
translate_node.inputs[1].default_value = (int(left), int(top))
node_tree.links.new(image_node.outputs[0], crop_node.inputs[0])
crop_nodes.append(crop_node)
node_tree.links.new(crop_node.outputs[0], translate_node.inputs[0])
translate_nodes.append(translate_node)
alpha_overs = [node_tree.nodes.new('CompositorNodeAlphaOver') for _ in range(len(image_nodes) - 1)]
for i in range(len(image_nodes) - 1):
if i == 0:
node_tree.links.new(crop_nodes[i].outputs[0], alpha_overs[i].inputs[1])
node_tree.links.new(translate_nodes[i].outputs[0], alpha_overs[i].inputs[1])
else:
node_tree.links.new(alpha_overs[i - 1].outputs[0], alpha_overs[i].inputs[1])
node_tree.links.new(crop_nodes[i + 1].outputs[0], alpha_overs[i].inputs[2])
node_tree.links.new(translate_nodes[i + 1].outputs[0], alpha_overs[i].inputs[2])
node_tree.links.new(alpha_overs[-1].outputs[0], feed_in_output)
node_tree.nodes.remove(render_layers_node)
render.image_settings.file_format = 'PNG'