DLR-RM / BlenderProc

A procedural Blender pipeline for photorealistic training image generation
GNU General Public License v3.0
2.73k stars 444 forks source link

How to render a object with roughness/metallic textures and output roughness/metallic images? #1131

Open bbbbubble opened 1 month ago

bbbbubble commented 1 month ago

Describe your feature request

As dicussed in #1105 , with this piece of code, we can output roughness/metallic images with default values of roughness/metallic.

# some objects' normals are affected by textures
mesh_objects = convert_to_meshes([obj for obj in scene_meshes()])
for obj in mesh_objects:
    print("removing invalid normals")
    for mat in obj.get_materials():
        mat.set_principled_shader_value("Normal", [1,1,1])
        principled_bsdf = mat.get_the_one_node_with_type("BsdfPrincipled")
        for key in ["Roughness", "Metallic", "Specular"]:
            obj.set_cp("cp_"+ key.lower(),  principled_bsdf.inputs[key].default_value)

...

bproc.renderer.enable_segmentation_output(map_by=["cp_roughness", "cp_metallic", "cp_specular", 'instance'],default_values={'cp_roughness': None, 'cp_metallic': None, 'cp_specular': None} )

However, if we have objects with roughness/metallic textures, the results are wrong: image Any solutions? Thanks!

Describe a possible solution

No response

cornerfarmer commented 1 month ago

@bbbbubble

No one can answer this question? It seems like a very basic problem...

The feature you request is currently not part of blenderproc. Feel free to implement it and submit a PR. It should work similar to the old SegMapRenderer (https://github.com/DLR-RM/BlenderProc/blob/main/blenderproc/python/renderer/SegMapRendererUtility.py#L269), but instead of using a single color per object, you would need to connect the roughness texture with the emission shader.

PS: Please use this issue for further comments

bbbbubble commented 1 month ago

@bbbbubble

No one can answer this question? It seems like a very basic problem...

The feature you request is currently not part of blenderproc. Feel free to implement it and submit a PR. It should work similar to the old SegMapRenderer (https://github.com/DLR-RM/BlenderProc/blob/main/blenderproc/python/renderer/SegMapRendererUtility.py#L269), but instead of using a single color per object, you would need to connect the roughness texture with the emission shader.

PS: Please use this issue for further comments

Thank you! I have made it work. ^^

Lizb6626 commented 1 month ago

@bbbbubble

Hi! Could you share the code of rendering roughness images here?