I have some automated code below that I have written to set up render nodes for full output, depth, object index (segmentation) and surface normal maps.
I notice the output of the normal map is in World Space. Is there a trivial way of changing the render node of the normal map to camera space?
def PrepareRender(context, resolution, output_dir):
scene = context.scene
scene.render.engine = 'CYCLES'
scene.render.filepath = output_dir
#Output open exr .exr files
context.scene.render.image_settings.file_format = 'OPEN_EXR'
context.scene.render.image_settings.use_zbuffer = True
context.scene.render.image_settings.color_depth = '16'
context.scene.render.image_settings.use_preview = False
context.scene.render.image_settings.exr_codec = 'ZIP'
scene.cycles.samples = 1
# Configure renderer to record object index
scene.view_layers["ViewLayer"].use_pass_object_index = True
scene.view_layers["ViewLayer"].use_pass_z = True
scene.view_layers["ViewLayer"].use_pass_normal = True
# Switch on nodes and get reference
scene.use_nodes = True
tree = scene.node_tree
links = tree.links
## Clear default nodes
for node in tree.nodes:
tree.nodes.remove(node)
# Create a node for outputting the rendered image
image_output_node = tree.nodes.new(type="CompositorNodeOutputFile")
image_output_node.label = "Image_Output"
image_output_node.base_path = os.path.join(output_dir, "image")
image_output_node.location = 400,0
# Create a node for outputting the depth of each pixel from the camera
depth_output_node = tree.nodes.new(type="CompositorNodeOutputFile")
depth_output_node.label = "Depth_Output"
depth_output_node.base_path = os.path.join(output_dir, "depth")
depth_output_node.location = 400,-100
# Create a node for outputting the index of each object
index_output_node = tree.nodes.new(type="CompositorNodeOutputFile")
index_output_node.label = "Index_Output"
index_output_node.base_path = os.path.join(output_dir, "mask")
index_output_node.location = 400,-200
# Create a node for outputting the surface normals of each pixel
normal_output_node = tree.nodes.new(type="CompositorNodeOutputFile")
normal_output_node.label = "Normal_Output"
normal_output_node.base_path = os.path.join(output_dir, "normal")
normal_output_node.location = 400, -300
# Create a node for the output from the renderer
render_layers_node = tree.nodes.new(type="CompositorNodeRLayers")
render_layers_node.location = 0,0
# Link all the nodes together
links.new(render_layers_node.outputs['Image'], image_output_node.inputs['Image'])
links.new(render_layers_node.outputs['Depth'], depth_output_node.inputs['Image'])
links.new(render_layers_node.outputs['IndexOB'], index_output_node.inputs['Image'])
links.new(render_layers_node.outputs['Normal'], normal_output_node.inputs['Image'])
camera = scene.camera
scene.render.resolution_x = resolution
scene.render.resolution_y = resolution
return image_output_node, depth_output_node, index_output_node, normal_output_node
Output of render for each node, left to right (image, index, depth, normal)