Closed miangoleh closed 5 months ago
+1, that would be very interesting! @miangoleh did you manage to find a solution?
Hi,
Yes I was able to get depth and normals by editing the blender_script.py file. This should be added before the rendering loop.
# Enable the depth pass for all view layers
for view_layer in bpy.context.scene.view_layers:
view_layer.use_pass_z = True
view_layer.use_pass_normal = True
# Ensure the use of nodes and clear any existing nodes
bpy.context.scene.use_nodes = True
tree = bpy.context.scene.node_tree
tree.nodes.clear()
# Create input render layer node
nodes = bpy.context.scene.node_tree.nodes
links = bpy.context.scene.node_tree.links
render_layers = nodes.new('CompositorNodeRLayers')
# Create depth output nodes
depth_file_output = nodes.new(type="CompositorNodeOutputFile")
depth_file_output.label = 'Depth Output'
depth_file_output.base_path = output_dir
depth_file_output.file_slots[0].use_node_format = True
depth_file_output.format.file_format = "OPEN_EXR"
links.new(render_layers.outputs['Depth'], depth_file_output.inputs[0])
# Create normal output nodes
scale_node = nodes.new(type="CompositorNodeMixRGB")
scale_node.blend_type = 'MULTIPLY'
# scale_node.use_alpha = True
scale_node.inputs[2].default_value = (0.5, 0.5, 0.5, 1)
links.new(render_layers.outputs['Normal'], scale_node.inputs[1])
bias_node = nodes.new(type="CompositorNodeMixRGB")
bias_node.blend_type = 'ADD'
# bias_node.use_alpha = True
bias_node.inputs[2].default_value = (0.5, 0.5, 0.5, 0)
links.new(scale_node.outputs[0], bias_node.inputs[1])
normal_file_output = nodes.new(type="CompositorNodeOutputFile")
normal_file_output.label = 'Normal Output'
normal_file_output.base_path = output_dir
normal_file_output.file_slots[0].use_node_format = True
# normal_file_output.format.file_format = "OPEN_EXR"
normal_file_output.format.color_mode = 'RGBA'
normal_file_output.format.color_depth = '8'
links.new(bias_node.outputs[0], normal_file_output.inputs[0])
Hi @miangoleh
I am keep getting Found object http://.... was not rendered successfully!
when i use your code.
Can you maybe provide the full blender_script.py and confirm that nothing needs to be changed in the main.py?
Thanks,
Thanos
You can take a look at my fork
however I made more changes to camera angles and lighting there.
It seems your code does indeed generate the normals but the depth images are of filetype .exr. I could not open them locally so i tried online viewers and all of them show an entire black image. Even if i change them to png the generated images are all of one colour (white for PNG).
Exr file format is a 16 bit integer file container.
the files look dark since the depth range is small compared to the entire available range 16bit provides. You need to find the min and max of valid pixels ( forground) and rescale them to see them reasonably.
Thanks @miangoleh i ll look into it
Hi. Do you also have the script to get the zbuffer (depth maps) for each rendered image?