Cube has attached three separate Shaders (materials) - Pink, Green, White ...
To bake them into one texture ... add Texture node with new (empty) image and keep node selected. Do the same for other materials (like here for Pink and White). Just copy&paste node and keep selected.
In case you want bake only color pass, select Diffuse and uncheck Direct ...
One way to do this is with an intermediate bake. Assuming the original object is displaced by the modifier along its normals...
(Bake Type: 'Emit') Bake the positions of displaced shading-points of the modified object, in object space, by using these nodes:
Use a floating-point format, some numbers in the next step will be negative, so OpenEXR is good. I've ...
I may be wrong but it looks like there's no automatic way to bake the height map of a Displace modifier.
If your object is flat with 3D relief, you can apply the Displace, give it a black and white gradient texture on the Z axis, plug it into an Emission, create a plane above and bake the Emit.
If it's a more complicated object, Ilakya gives here a method to ...
I got black AO. Turns out it was caused by the wrong Cycles rendering device,
which I had set to GPU (of course). But I remembered that baking only works with CPU.
So make sure to set the rendering device to CPU.
I think you are getting too focused on the details and need to evaluate the overall goal. Sounds like you want to do:
Given an object
if no material assigned create new material
For each material in material_slots
ensure use_nodes = True
Add shader node 'ShaderNodeTexImage'
Set node location (0,0)
ob = bpy.context.object
It seems as though, as of Blender 2.92, baking a tangent space normal map without using Selected to Active does not work correctly in the presence of modifiers. I have opened issue T87449 on the Blender bug tracker about this.
In the meantime, there are a few workarounds:
Apply modifiers before baking. This is probably the best workaround, since it’s easy ...