My object consists of two materials. One of them has a texture attached. What I want is to uv map the whole object to a single texture so I can read it in opengl easily without an mtl file.
So, this is what I did in steps(I'm a beginner and I don't know what I might have done wrong so I'll mention as many steps as possible even though they may be irrelevant, obviously correct or very simple steps):
1)I set up 3 views: 3D Viewport, UV editor and shader editor.
2)I joined the parts of my object into a single one. Now in the collection I can see it is referred to as a single object.
3)I select the object in edit mode. Now I can see the uv unwrapping in uv editor.
4 ) Having selected the object in edit mode, I add a new uv map under the object data properties :
5 ) In the 3d viewport I press U and choose smart UV project. Now I can see the new uv unwrapping :
6 ) I create a new image in UV editor and save it. Now the background behind the uv unwrapping is black so the texture has been created.
7 ) For the material that has a texture I added a few nodes in shader editor. You can see how it was in the 1st picture and what I added in the second :
8 ) The other material has no texture attached so I only added the two nodes(the texture image node with the bake texture and its uv map input).
9 ) Having selected the texture nodes with the texture to be baked(in both materials), I go to render properties -> bake and I change bake type to diffuse, uncheck direct and indirect, leaving only color, and then press bake.
Doing that, it seems that the material with the texture goes over the other material producing this :
In the previous bake the material that is open in shader editor is the one with the texture. If I view the other material(the can, the metal) and bake again , this is what I get:
This time, the material with the texture is baked only where it should but the other material ends up as black for some reason. I tried adding a texture to the metal , making its nodes in shader editor just like the ones of the other material. In the 3d viewport I can see the new texture is loaded correctly but in the bake I still see black.
What am I doing wrong and why does it matter what material I choose in shader editor?
This is the blender file. Hopefully I've done the packing correctly. In this version I've attached a green texture to the can.