2
$\begingroup$

Background: We are building an automated pipeline to extract motion (i.e. vector pass output) from animated blends by running scripts using blender's python API. We are able to programmatically set up nodes and run rendering. We need access to full precision x,y motion components, and the only way we found of accessing that was via bpy.data.images['Viewer Node'].pixels. This gives correct output when running with GUI.

Problem: We need to run blender in background mode on many examples, and in background mode bpy.data.images['Viewer Node'].pixels has a) wrong resolution (does not respect scene.render.resolution_x), b) wrong info (everything is zero).

Existing solutions: We know that it is possible to modify blender source code to fix this, but we want to open source our pipeline, and creating a custom blender build to run it might be too much of an impediment for people. We'd like to make this work with a standard blender version.

Questions:

  1. Is it possible to access vector pass data in some other way, without using the Viewer Node, so that rendering can be done in the background?
  2. Or, is there a way to force Viewer Node to output correct data in background mode?
$\endgroup$
  • $\begingroup$ Can you give a bit more detail about what the viewer node is connected to? Is it just the standard vector pass or are you doing some processing in the compositor? $\endgroup$ – Ray Mairlot Feb 22 '18 at 18:02
  • $\begingroup$ @RayMairlot, we simply connect the Viewer Node to the vector output in render layers; no compositing. $\endgroup$ – user2113258 Feb 22 '18 at 18:37
  • $\begingroup$ Did you take a look at this link before? It seems that there is a way to enable back-dropping using Python but I have not been able to figure out how as Blender's documentation is a bit unclear. It would be great if you can understand what the documentation is saying and enable backdropping using Python. If you did, could you please take a look at my question here and post an answer? $\endgroup$ – Amir Mar 14 '18 at 1:11
  • $\begingroup$ @Amir, we haven't worked with backdropping $\endgroup$ – user2113258 Mar 14 '18 at 11:12
1
$\begingroup$

Another option to evaluate would be to store the result in MultilayerEXR When writing a MultiLayerEXR file as output. this vector pass is also stored inside the generated EXR file:

render = scene.render
render.layers[0].use_pass_vector = True
render.image_settings.file_format = "OPEN_EXR_MULTILAYER"
# after rendering the open exr file 
bpy.ops.render.render(write_still=True).

After rendering all layers in blender (before and after compositing are written inside the create OpenEXR file. No fiddling needed in the compositor.

There is currently no API available to read the Render Result directly from the renderer.

$\endgroup$
  • $\begingroup$ This is probably the best answer if you are only looking for vector pass output, which is what my question is about. In our case, we use nodes to process some of the other outputs in addition so my answer worked well for us. $\endgroup$ – user2113258 Mar 14 '18 at 11:08
1
$\begingroup$

In the end the solution was to use multilayer EXR output by constructing a simple node graph automatically in python (Blender 2.78).

bpy.context.scene.use_nodes = True
bpy.context.scene.render.layers[0].use_pass_combined = True
bpy.context.scene.render.layers[0].use_pass_vector = True

tree = bpy.context.scene.node_tree
rl = tree.nodes.new('CompositorNodeRLayers')
rl.location = 0, 200

output = tree.nodes.new('CompositorNodeOutputFile')
output.location = 200, 200
output.format.file_format = 'OPEN_EXR_MULTILAYER'
output.base_path = output_folder

links = tree.links
links.new(rl.outputs['Speed'], output.inputs[0])
$\endgroup$
  • $\begingroup$ This works, but if vector pass output is the only thing needed, better to skip the nodes and use answer from J. Bakker. $\endgroup$ – user2113258 Mar 14 '18 at 11:10

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.