Skip to content

Output roughness/metallic images are incorrect #1190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
xdobetter opened this issue Apr 24, 2025 · 0 comments
Open

Output roughness/metallic images are incorrect #1190

xdobetter opened this issue Apr 24, 2025 · 0 comments
Labels
question Question, not yet a bug ;)

Comments

@xdobetter
Copy link

xdobetter commented Apr 24, 2025

Describe the issue

As the title suggests, I'm trying to output the roughness and metallic images from a .glb file using BlenderProc, but the results seem incorrect or unexpected. I followed the suggested method from Issue #1131.

Minimal code example

Below is a code snippet I’m using (for metallic/roughness):

import blenderproc as bproc
import argparse
import ipdb

# blenderproc run examples/datasets/abo/main.py resources\abo-3dmodels\3dmodels\original\8\B07TC2NYX8.glb examples/datasets/abo/output2
parser = argparse.ArgumentParser()
parser.add_argument('path', help="Path to the downloaded .blend file")
parser.add_argument('output_dir', nargs='?', default="examples/datasets/abo/output", help="Path to where the final files will be saved")
args = parser.parse_args()

# Initialize BlenderProc
bproc.init()

# Load the .glb object
glb_path = args.path  # Use the path argument from command line
objs = bproc.loader.load_obj(glb_path)

# 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)

# Find point of interest, all cam poses should look towards it
poi = bproc.object.compute_poi(bproc.filter.all_with_type(objs, bproc.types.MeshObject))

# Sample three camera poses
for i in range(3):
    # Sample random camera location around the objects
    location = bproc.sampler.part_sphere([0, 0, 0], radius=2.5, part_sphere_dir_vector=[1, 0, 0], mode="SURFACE")
    # Compute rotation based on vector going from location towards poi
    rotation_matrix = bproc.camera.rotation_from_forward_vec(poi - location)
    # Add homog cam pose based on location an rotation
    cam2world_matrix = bproc.math.build_transformation_mat(location, rotation_matrix)
    bproc.camera.add_camera_pose(cam2world_matrix)

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

# enable segmentation,roughness,metallic masks (per class and per instance)
from blenderproc.python.types.MeshObjectUtility import get_all_mesh_objects, MeshObject
objects = get_all_mesh_objects()
for obj in objects:
    print("removing invalid normals")
    materials = obj.get_materials()
    for material in materials:
        material.set_principled_shader_value("Normal", [1,1,1])
        principled_bsdf = material.get_the_one_node_with_type("BsdfPrincipled")
        print(principled_bsdf)
        for key in ["Roughness", "Metallic"]:
            print(key, principled_bsdf.inputs[key].default_value)
            obj.set_cp("cp_" + key.lower(),  principled_bsdf.inputs[key].default_value)
bproc.renderer.enable_segmentation_output(map_by=["cp_roughness", "cp_metallic", "instance"], \
                            default_values={'cp_roughness': None, 'cp_metallic': None, 'cp_specular': None})


# Set max samples for quick rendering
bproc.renderer.set_max_amount_of_samples(5) # 5 samples per pixel

# 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

The objects being rendered are as follows. (I found that I am unable to upload this model. If you need it, you can leave your email address and I will send it to you.)

Expected behavior

The correct result is as shown in the first line. The erroneous result rendered by the code above is as shown in the second line.

Image

BlenderProc version

v.2.7.0

@xdobetter xdobetter added the question Question, not yet a bug ;) label Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question, not yet a bug ;)
Projects
None yet
Development

No branches or pull requests

1 participant