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 ec0f9b47e2 - Show all commits

View File

@ -17,7 +17,7 @@ const JOB_TYPE = {
},
{
key: "frame", type: "int32", required: true,
eval: "f'{C.scene.frame_current}'",
eval: "C.scene.frame_current",
description: "Frame to render. Examples: '47', '1'"
},
@ -68,6 +68,22 @@ const JOB_TYPE = {
visible: "hidden",
description: "File extension used when rendering images"
},
{
key: "resolution_x",
type: "int32",
required: true,
eval: "C.scene.render.resolution_x",
visible: "hidden",
description: "Resolution X"
},
{
key: "resolution_y",
type: "int32",
required: true,
eval: "C.scene.render.resolution_y",
visible: "hidden",
description: "Resolution Y"
},
]
};
@ -84,6 +100,10 @@ function compileJob(job) {
const renderDir = path.dirname(renderOutput);
const renderTasks = authorRenderTasks(settings, renderDir, renderOutput);
for (const rt of renderTasks) {
job.addTask(rt);
}
}
// Do field replacement on the render output path.
@ -103,7 +123,7 @@ function renderOutputPath(job) {
}
function calcBorders(tileSizeX, tileSizeY, width, height) {
borders = [];
let borders = [];
for (let y = 0; y < height; y += tileSizeY) {
for (let x = 0; x < width; x += tileSizeX) {
borders.push([x, y, Math.min(x + tileSizeX, width), Math.min(y + tileSizeY, height)]);
@ -116,9 +136,8 @@ function calcBorders(tileSizeX, tileSizeY, width, height) {
function authorRenderTasks(settings, renderDir, renderOutput) {
print("authorRenderTasks(", renderDir, renderOutput, ")");
let renderTasks = [];
render = C.scene.render;
let borders = calcBorders(settings.tile_size_x, settings.tile_size_y, render.resolution_x, render.resolution_y);
for (border of borders) {
let borders = calcBorders(settings.tile_size_x, settings.tile_size_y, settings.resolution_x, settings.resolution_y);
for (let border of borders) {
const task = author.Task(`render-${border[0]}-${border[1]}`, "blender");
let pythonExpr = `import bpy
@ -126,18 +145,19 @@ render = bpy.context.scene.render
render.image_settings.file_format = 'OPEN_EXR_MULTILAYER'
render.use_compositing = False
render.border_min_x = ${border[0]} // settings.resolution_x
render.border_min_y = ${border[1]} // settings.resolution_y
render.border_max_x = ${border[2]} // settings.resolution_x
render.border_max_y = ${border[3]} // settings.resolution_y
render.use_border = True`
render.border_min_x = ${border[0]} / ${settings.resolution_x}
render.border_min_y = ${border[1]} / ${settings.resolution_y}
render.border_max_x = ${border[2]} / ${settings.resolution_x}
render.border_max_y = ${border[3]} / ${settings.resolution_y}
render.use_border = True
bpy.ops.render.render(write_still=True)`
const command = author.Command("blender-render", {
exe: "{blender}",
exeArgs: "{blenderArgs}",
argsBefore: [],
blendfile: settings.blendfile,
args: [
"--render-output", path.join(renderDir, path.basename(renderOutput)),
"--render-output", path.join(renderDir, path.basename(renderOutput), border[0] + "-" + border[1] + "-" + border[2] + "-" + border[3]),
"--render-format", settings.format,
"--python-expr", pythonExpr
]