WIP: Single-frame job compiler #104194
@ -101,10 +101,13 @@ render.use_compositing = False
|
||||
bpy.context.scene.cycles.use_denoising = False
|
||||
render.image_settings.file_format = 'OPEN_EXR_MULTILAYER'
|
||||
render.use_crop_to_border = True
|
||||
render.border_min_x = ${tile.column} * ${settings.tile_size} / 100
|
||||
render.border_max_x = ${settings.tile_size} / 100 + ${tile.column} * ${settings.tile_size} / 100
|
||||
render.border_min_y = ${tile.row} * ${settings.tile_size} / 100
|
||||
render.border_max_y = ${settings.tile_size} / 100 + ${tile.row} * ${settings.tile_size} / 100`;
|
||||
|
||||
tile_size_normalized = ${settings.tile_size} / 100
|
||||
|
||||
render.border_min_x = ${tile.column} * tile_size_normalized
|
||||
render.border_max_x = tile_size_normalized + ${tile.column} * tile_size_normalized
|
||||
render.border_min_y = ${tile.row} * tile_size_normalized
|
||||
render.border_max_y = tile_size_normalized + ${tile.row} * tile_size_normalized`;
|
||||
if (settings.use_denoising) {
|
||||
pythonExpression += `
|
||||
for layer in bpy.context.scene.view_layers:
|
||||
@ -151,19 +154,23 @@ if len(filenames) <= 1:
|
||||
|
||||
row_max = math.ceil(100 / ${settings.tile_size}) - 1
|
||||
|
||||
bpy.context.scene.render.resolution_x = ${settings.resolution_x}
|
||||
bpy.context.scene.render.resolution_y = ${settings.resolution_y}
|
||||
bpy.context.scene.render.resolution_percentage = ${settings.resolution_percentage}
|
||||
bpy.context.scene.render.use_compositing = True
|
||||
bpy.context.scene.use_nodes = True
|
||||
bpy.context.scene.node_tree.nodes.clear()
|
||||
bpy.context.scene.render.image_settings.file_format = 'OPEN_EXR_MULTILAYER'
|
||||
bpy.context.scene.render.filepath = basepath + "MERGED"
|
||||
bpy_render = bpy_render
|
||||
bpy_scene = bpy.context.scene
|
||||
node_tree = bpy_scene.node_tree
|
||||
|
||||
bpy_render.resolution_x = ${settings.resolution_x}
|
||||
bpy_render.resolution_y = ${settings.resolution_y}
|
||||
bpy_render.resolution_percentage = ${settings.resolution_percentage}
|
||||
bpy_render.use_compositing = True
|
||||
bpy_scene.use_nodes = True
|
||||
node_tree.nodes.clear()
|
||||
bpy_render.image_settings.file_format = 'OPEN_EXR_MULTILAYER'
|
||||
bpy_render.filepath = basepath + "MERGED"
|
||||
denoising = "${settings.use_denoising}" == "true"
|
||||
|
||||
# Takes the column and row number and creates a translate node with the right coordinates to align a tile
|
||||
def create_translate(dimensions):
|
||||
translate_node = bpy.context.scene.node_tree.nodes.new(type='CompositorNodeTranslate')
|
||||
translate_node = node_tree.nodes.new(type='CompositorNodeTranslate')
|
||||
translate_node.use_relative = True
|
||||
for dimension in dimensions:
|
||||
if dimensions[dimension] == 0:
|
||||
@ -180,7 +187,7 @@ def align_tiles(input):
|
||||
file_name = image_node.image.name_full
|
||||
dimensions = {'X': int(file_name.split('c')[-1].split('_')[0]), 'Y': int(file_name.split('c')[0].replace('r', ''))}
|
||||
translated_list.append(create_translate(dimensions))
|
||||
bpy.context.scene.node_tree.links.new(image_node.outputs[input], translated_list[index].inputs['Image'])
|
||||
node_tree.links.new(image_node.outputs[input], translated_list[index].inputs['Image'])
|
||||
return translated_list
|
||||
|
||||
# Create a list of image nodes
|
||||
@ -188,7 +195,7 @@ image_nodes = []
|
||||
for index, file in enumerate(filenames):
|
||||
bpy.ops.image.open(filepath=renders + file.name, use_sequence_detection=False)
|
||||
image = bpy.data.images[bpy.path.basename(file.name)]
|
||||
image_nodes.append(bpy.context.scene.node_tree.nodes.new(type='CompositorNodeImage'))
|
||||
image_nodes.append(node_tree.nodes.new(type='CompositorNodeImage'))
|
||||
image_nodes[index].image = image
|
||||
|
||||
# Create translates for Combined, Albedo and Normal and put them in a list
|
||||
@ -197,7 +204,7 @@ if denoising:
|
||||
albedo_translates = align_tiles("Denoising Albedo")
|
||||
normal_translates = align_tiles("Denoising Normal")
|
||||
|
||||
output_node = bpy.context.scene.node_tree.nodes.new(type='CompositorNodeComposite')
|
||||
output_node = node_tree.nodes.new(type='CompositorNodeComposite')
|
||||
alpha_over_nodes = []
|
||||
albedo_mix_nodes = []
|
||||
normal_mix_nodes = []
|
||||
@ -205,42 +212,42 @@ normal_mix_nodes = []
|
||||
for index, node in enumerate(combined_translates):
|
||||
if index == 0:
|
||||
# Take the first two image nodes and combine them
|
||||
alpha_over_nodes.append(bpy.context.scene.node_tree.nodes.new(type='CompositorNodeAlphaOver'))
|
||||
bpy.context.scene.node_tree.links.new(combined_translates[0].outputs['Image'], alpha_over_nodes[index].inputs[1])
|
||||
bpy.context.scene.node_tree.links.new(combined_translates[1].outputs['Image'], alpha_over_nodes[index].inputs[2])
|
||||
alpha_over_nodes.append(node_tree.nodes.new(type='CompositorNodeAlphaOver'))
|
||||
node_tree.links.new(combined_translates[0].outputs['Image'], alpha_over_nodes[index].inputs[1])
|
||||
node_tree.links.new(combined_translates[1].outputs['Image'], alpha_over_nodes[index].inputs[2])
|
||||
if denoising:
|
||||
albedo_mix_nodes.append(bpy.context.scene.node_tree.nodes.new(type='CompositorNodeMixRGB'))
|
||||
albedo_mix_nodes.append(node_tree.nodes.new(type='CompositorNodeMixRGB'))
|
||||
albedo_mix_nodes[index].blend_type = 'ADD'
|
||||
bpy.context.scene.node_tree.links.new(albedo_translates[0].outputs['Image'], albedo_mix_nodes[index].inputs[1])
|
||||
bpy.context.scene.node_tree.links.new(albedo_translates[1].outputs['Image'], albedo_mix_nodes[index].inputs[2])
|
||||
normal_mix_nodes.append(bpy.context.scene.node_tree.nodes.new(type='CompositorNodeMixRGB'))
|
||||
node_tree.links.new(albedo_translates[0].outputs['Image'], albedo_mix_nodes[index].inputs[1])
|
||||
node_tree.links.new(albedo_translates[1].outputs['Image'], albedo_mix_nodes[index].inputs[2])
|
||||
normal_mix_nodes.append(node_tree.nodes.new(type='CompositorNodeMixRGB'))
|
||||
normal_mix_nodes[index].blend_type = 'ADD'
|
||||
bpy.context.scene.node_tree.links.new(normal_translates[0].outputs['Image'], normal_mix_nodes[index].inputs[1])
|
||||
bpy.context.scene.node_tree.links.new(normal_translates[1].outputs['Image'], normal_mix_nodes[index].inputs[2])
|
||||
node_tree.links.new(normal_translates[0].outputs['Image'], normal_mix_nodes[index].inputs[1])
|
||||
node_tree.links.new(normal_translates[1].outputs['Image'], normal_mix_nodes[index].inputs[2])
|
||||
else:
|
||||
# Take one image node and the previous alpha over node
|
||||
alpha_over_nodes.append(bpy.context.scene.node_tree.nodes.new(type='CompositorNodeAlphaOver'))
|
||||
bpy.context.scene.node_tree.links.new(alpha_over_nodes[index-1].outputs['Image'], alpha_over_nodes[index].inputs[1])
|
||||
bpy.context.scene.node_tree.links.new(combined_translates[index+1].outputs['Image'], alpha_over_nodes[index].inputs[2])
|
||||
alpha_over_nodes.append(node_tree.nodes.new(type='CompositorNodeAlphaOver'))
|
||||
node_tree.links.new(alpha_over_nodes[index-1].outputs['Image'], alpha_over_nodes[index].inputs[1])
|
||||
node_tree.links.new(combined_translates[index+1].outputs['Image'], alpha_over_nodes[index].inputs[2])
|
||||
if denoising:
|
||||
albedo_mix_nodes.append(bpy.context.scene.node_tree.nodes.new(type='CompositorNodeMixRGB'))
|
||||
albedo_mix_nodes.append(node_tree.nodes.new(type='CompositorNodeMixRGB'))
|
||||
albedo_mix_nodes[index].blend_type = 'ADD'
|
||||
bpy.context.scene.node_tree.links.new(albedo_mix_nodes[index-1].outputs['Image'], albedo_mix_nodes[index].inputs[1])
|
||||
bpy.context.scene.node_tree.links.new(albedo_translates[index+1].outputs['Image'], albedo_mix_nodes[index].inputs[2])
|
||||
normal_mix_nodes.append(bpy.context.scene.node_tree.nodes.new(type='CompositorNodeMixRGB'))
|
||||
node_tree.links.new(albedo_mix_nodes[index-1].outputs['Image'], albedo_mix_nodes[index].inputs[1])
|
||||
node_tree.links.new(albedo_translates[index+1].outputs['Image'], albedo_mix_nodes[index].inputs[2])
|
||||
normal_mix_nodes.append(node_tree.nodes.new(type='CompositorNodeMixRGB'))
|
||||
normal_mix_nodes[index].blend_type = 'ADD'
|
||||
bpy.context.scene.node_tree.links.new(normal_mix_nodes[index-1].outputs['Image'], normal_mix_nodes[index].inputs[1])
|
||||
bpy.context.scene.node_tree.links.new(normal_translates[index+1].outputs['Image'], normal_mix_nodes[index].inputs[2])
|
||||
node_tree.links.new(normal_mix_nodes[index-1].outputs['Image'], normal_mix_nodes[index].inputs[1])
|
||||
node_tree.links.new(normal_translates[index+1].outputs['Image'], normal_mix_nodes[index].inputs[2])
|
||||
if index + 1 == len(combined_translates) - 1:
|
||||
if denoising:
|
||||
denoise_node = bpy.context.scene.node_tree.nodes.new(type='CompositorNodeDenoise')
|
||||
bpy.context.scene.node_tree.links.new(alpha_over_nodes[index].outputs['Image'], denoise_node.inputs['Image'])
|
||||
bpy.context.scene.node_tree.links.new(albedo_mix_nodes[index].outputs['Image'], denoise_node.inputs['Albedo'])
|
||||
bpy.context.scene.node_tree.links.new(normal_mix_nodes[index].outputs['Image'], denoise_node.inputs['Normal'])
|
||||
bpy.context.scene.node_tree.links.new(denoise_node.outputs['Image'], output_node.inputs['Image'])
|
||||
denoise_node = node_tree.nodes.new(type='CompositorNodeDenoise')
|
||||
node_tree.links.new(alpha_over_nodes[index].outputs['Image'], denoise_node.inputs['Image'])
|
||||
node_tree.links.new(albedo_mix_nodes[index].outputs['Image'], denoise_node.inputs['Albedo'])
|
||||
node_tree.links.new(normal_mix_nodes[index].outputs['Image'], denoise_node.inputs['Normal'])
|
||||
node_tree.links.new(denoise_node.outputs['Image'], output_node.inputs['Image'])
|
||||
else:
|
||||
# Link the last image node and feed the output into the composite node
|
||||
bpy.context.scene.node_tree.links.new(alpha_over_nodes[index].outputs['Image'], output_node.inputs['Image'])
|
||||
node_tree.links.new(alpha_over_nodes[index].outputs['Image'], output_node.inputs['Image'])
|
||||
break
|
||||
bpy.ops.render.render(write_still=True)`;
|
||||
const command = author.Command("blender-render", {
|
||||
|
Loading…
Reference in New Issue
Block a user