1
$\begingroup$

I'm writing a multi-view synthetic dataset generator and I want to save my rendered images as multi-layer EXR. I have a basic Python script that loads a template file with the compositing nodes below, append an object and renders from different views by varying the camera position.

When I render a scene in Blender, I get the desired result: a multi-layer EXR image with denoised colors, raw normals and clipped depths. However, I cannot find a way to render to the File Output node in Python, since scene.render.filepath is different than nodes['File Output'].base_path. When I call bpy.ops.render.render(write_still=True), I get a multi-layer EXR that essentially ignores my output node and just uses the value in Output Properties. This is true even if I remove the denoising node.

Is there any way to render through the File Output node in Python? Is my Composite node actually correct? I need compositing because I want to use the denoiser to reduce render times. Both scene.use_nodes and scene.render.use_compositing are set to True in my code.

Nodes

$\endgroup$
2
$\begingroup$

In order to change the path of the output node you would have to set OutputNode.base_path. Make sure RenderSettings.use_compositing as well as Scene.use_nodes is enabled. Tested against the following node setup successfully:

enter image description here

import bpy, os

C = bpy.context

# Enable Post Processing and Use Nodes
C.scene.render.use_compositing = True
C.scene.use_nodes = True

# Get the File Output Node by name
out = C.scene.node_tree.nodes.get("File Output")

if out:
    # Set the output path of the node based 
    # on the regular path of the output
    out_dir = os.path.dirname(C.scene.render.filepath)
    out.base_path = os.path.join(out_dir, "multilayer_")
    # Call the render operator
    bpy.ops.render.render(write_still=True)

Related: How to properly connect the Denoise node in Compositor?


Rendering in headless mode works as well:

./Blender -b file.blend -P script.py

enter image description here Layer Contact Sheet node in Natron

$\endgroup$
3
  • $\begingroup$ Thanks, but this is exactly what I am doing and the file output node doesn't get used. All I get is an EXR with 10 different buffers in /tmp/. I should specify that I am running this from the command-line using blender scene.blend --python your_script.py and not from the Scripting interface, where you code works. I feel like this is a bug. $\endgroup$
    – Hubble
    Mar 18 at 18:32
  • $\begingroup$ Works for me like a charm in Blender 2.92.0, added my results @Hubble $\endgroup$
    – brockmann
    Mar 18 at 19:12
  • 1
    $\begingroup$ Somehow two copies are saved, one in /tmp/ and one in my output directory. Not sure what was the issue before, but this is resolved. Thanks! $\endgroup$
    – Hubble
    Mar 18 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.