BlenderProc icon indicating copy to clipboard operation
BlenderProc copied to clipboard

Bug for rendering normal map?

Open Uio96 opened this issue 2 years ago • 1 comments

Describe the issue

I find that when rendering normals map, the bproc.renderer.enable_normals_output() operation has to be put after bproc.camera.add_camera_pose() to make it function properly. Otherwise, the output will be blank.

I am not sure if that is a special design or a potential bug. I do not go into the details of enable_normals_output operation. But if it is a special design, maybe it is better to state it in the tutorial or some examples.

Minimal code example

import blenderproc as bproc
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('camera', help="Path to the camera file, should be examples/resources/camera_positions")
parser.add_argument('scene', help="Path to the scene.obj file, should be examples/resources/scene.obj")
parser.add_argument('output_dir', help="Path to where the final files, will be saved, could be examples/basics/basic/output")
args = parser.parse_args()

bproc.init()

# load the objects into the scene
objs = bproc.loader.load_obj(args.scene)

# define a light and set its location and energy level
light = bproc.types.Light()
light.set_type("POINT")
light.set_location([5, -5, 5])
light.set_energy(1000)

# define the camera resolution
bproc.camera.set_resolution(512, 512)

# Move here
bproc.renderer.enable_normals_output()

# read the camera positions file and convert into homogeneous camera-world transformation
with open(args.camera, "r") as f:
    for line in f.readlines():
        line = [float(x) for x in line.split()]
        position, euler_rotation = line[:3], line[3:6]
        matrix_world = bproc.math.build_transformation_mat(position, euler_rotation)
        bproc.camera.add_camera_pose(matrix_world)

# activate normal and depth rendering
# bproc.renderer.enable_normals_output()
bproc.renderer.enable_depth_output(activate_antialiasing=False)

# render the whole pipeline
data = bproc.renderer.render()

# write the data to a .hdf5 container
bproc.writer.write_hdf5(args.output_dir, data)

Files required to run the code

No response

Expected behavior

I simply modify the examples in examples/basics/basic/main.py by changing bproc.renderer.enable_normals_output(). The output of the normals rendering will be blank, while the original one's output is good.

BlenderProc version

Github main branch

Uio96 avatar Jul 24 '23 15:07 Uio96

Indeed the enable_normals_output needs to know the camera poses, such that normals can be transformed into the camera frame. You are right this should be better documented.

cornerfarmer avatar Jul 24 '23 16:07 cornerfarmer