[SOLVED] Python API: baking normal map save wrong color space on export

Hello Devtalk!

I’m currently working on a script to bake a normal map from a texture.
But after some hours of research, I have a colorspace problem on the exported normal map.

Description of each steps:

  1. Loading Python modules
  2. Managing custom args via the argparse module
  3. Activate the builtin addon “import images as planes” and import my texture
  4. Scale the object 3 times to avoid seams on the border when rendering
  5. Applying a subsurf (needed for displacing)
  6. Replace the shader of the object with the correct shader (with displace activated) and load the texture inside of it
  7. Duplicate the object, scale it down 3 times and applying an empty material
  8. Select both objects and bake
  9. Save the baked image
  10. Delete the temporary object used to bake

When I open my saved image, the normal looks very weird (yellowish instead of purplish blue).

When I did the same steps but import the image as plane by hand, all worked as expected and the final exported map is correct.

This is all my files: https://1drv.ms/u/s!AmJL0Awo6vVNjZUz9yhDAQXt8WdwuQ?e=EOm4z6

Thank you,
Léo D.

I get around the colorspace issue by saving it as a .exr file. .png seems to have RGB hard-coded.

Hi @Josephbburg,
thank you for replying.
I tried few times but the exported .exr is corrupted (I also changed the output type to exr).

If it is corrupted when you save it from Blender, that’s a bug. That should never happen.

After multiple tests with Blender 2.90, I discovered that work as expected so I updated to this version.

1 Like