specoolar / Blender-BakeLab2

Blender addon for baking images
GNU General Public License v3.0
304 stars 44 forks source link

Albedo Pass Not Correct #31

Open bikemurt opened 1 year ago

bikemurt commented 1 year ago

When trying to bake out Albedo, Metallic (custom pass), Roughness and Normal, the Albedo won't appear correct. image

See the albedo image with the red box is "washed out" or not as bright. That's what BakeLab2 produces compared to a manual bake I did (on top).

This is a known bug in Blender and happens when manually baking as well. The workaround is to temporarily set Metallic to zero on the Principled BSDF.

Would it be possible to temporarily set the metal channel to 0 while baking the Albedo with this tool?

It's simple and would be exactly what I need except for this issue. I may try to fix it myself and if so will put in a PR, or at least post a comment here with my change.

Edit: Also tried the Diffuse channel and a custom channel with "Color,Base Color,Albedo,Paint Color" selected. No change

bikemurt commented 1 year ago

Since the workflow seems to be: Iterate through all selected objects -> Select obj -> Reserve Materials (copy material slots) -> Prepare Materials -> Bake -> add bake map -> restore materials,

I think a change would be needed on the Prepare Materials, to somehow set the metallic to zero only during the Albedo pass:

    def PrepareMaterials(self, context, dst_obj, src_obj_list, map, bake_image):
        active_obj = context.active_object
        selected_objects = context.selected_objects

        for obj in src_obj_list:
            SelectObject(obj)
            if len(obj.material_slots) == 0:
                bpy.ops.object.material_slot_add()
            for slot in obj.material_slots:
                if slot.material is None:
                    slot.material = self.GetEmptyMaterial()
                mat = slot.material
                mat.use_nodes = True

                if map.type == 'CustomPass':
                    if map.deep_search:
                        self.ungroup_nodes(mat.node_tree)
                    self.passes_to_emit_node(mat, map.pass_name)
                if map.type == 'Albedo':

## Set Metallic of this material slot to zero ##

                    self.ungroup_nodes(mat.node_tree)
                    self.passes_to_emit_node(mat, 'Albedo,Color,Base Color,Col,Paint Color')
                if map.type == 'Displacement':
                    self.displacement_to_color(mat)
bikemurt commented 1 year ago

If anyone with some Blender/python/node knowledge knows how to do this that would be wonderful

bikemurt commented 1 year ago

See PR https://github.com/specoolar/Blender-BakeLab2/pull/32