# Can you bake a normal map with the empty space around the objects transparent?

Is there an option in Blender to set "background" areas of a normal map bake to have an alpha of 0?

What I am doing exactly, for my own reasons, is baking the orthographic normals of various objects onto a plane in front of them, like this:

But I want everything except the object itself to be transparent in the normal map texture that is baked.

I am using a Python script to also bake maps for objects at every different combination of rotation, generating thousands of files like so:

So any solution or workaround for my particular case has to be scalable. If there is some option or feature in blender to render the empty space around objects onto the normal map with an alpha of 0, finding that is the main goal for me.

I've considered a workaround like rendering a mask with the object silhouette white against a black background and manually multiplying that with the alpha channel of the normal map in Python before saving, but if there's an option I can turn on to avoid the work of writing that script, it would help - doing that would also add to the render time, which is already quite significant, so if I can go a more direct route I would put that ahead of a workaround like that. I'm still fairly new to Blender. Thanks!

• Is it true that you can select the you can select a single object to be baked onto another single object regardless of other objects in the scene? – atomicbezierslinger Jul 29 '20 at 16:02
• Is your question the same as .. How do I bake the Normals of a single object while ignoring other objects in the scene? ? – atomicbezierslinger Jul 29 '20 at 16:05
• I don't think so - I am already baking one object to another. What I'm hoping to find out is whether the background of the scene (everywhere there are no objects) can be rendered as transparent in the normal map bake. – lambdawaff Jul 29 '20 at 16:06
• The use of the word transparent causes me to pause. I was not aware that a normal map could convey transparency. I could understand a transformation of a normal map that would for certain [special cases]. I could understand a transparency map derived from a normal map. I do generally understand files of PNG or that other type .. (Open EXR?) have transparency. So I am pausing for jargon at this point. – atomicbezierslinger Jul 29 '20 at 16:12
• I may look to see if a camera aligned to the normal of a planar target of the normal map could simply render the source target to be used as a transparency map. Perhaps there are other types of baking I never use. Of course the source of a normal map can a face parallel to another destination plane causing confusion. – atomicbezierslinger Jul 29 '20 at 16:18

One possibility is with Workbench render and the built in check_normal+y.exr MatCap. If speed is needed, this should be very fast.

1. Set the render engine to Workbench.

2. Set the lighting to MatCap and chose the "check normal" matcap.

3. Ensure Transparent is enabled under Film.

4. Make sure Color Management > View Transform is set to Standard. The default of Filmic emulates how a camera sensor shapes dynamic range, but that is definitely not what we want right now.

5. Use a camera with the Type set to Orthographic, aimed at your object as in your screenshot (it's a bit hard to tell if that one is orthographic already or not).

Render:

PNG images are encoded with a gamma correction with the expectation that they'll likely be displayed on an sRGB screen which will apply the inverse correction. Since that isn't the purpose of normal maps, you might want to be careful of this.

If you're decoding the PNGs yourself/with a library, take note of if it applies the inverse correction or not before exposing the values to your own code (and if it doesn't, either apply the inverse correction yourself or render the PNGs without correction from Blender by setting the View Transform to Raw).

Or if you can, use OpenEXR and ignore the last several paragraphs. Blender saves EXRs in linear space by default and most other software should assume they are in linear space. They also offer full float precision, so if you encounter any banding artifacts, switching to OpenEXR will likely fix those too. They are a bit big, however.

• ... use Workbench as regular render? Also Color Management > Standard (not Filmic). Saved as PNG RGBA 16 bit or EXR 32 bit. – vklidu Jul 29 '20 at 17:58
• @vklidu I did set color management to standard, I'm not sure why the values are obviously wrong in my image. Good point about workbench render, I'd forgotten that was a thing. If you want to make that an answer of your own, go ahead :) – gandalf3 Jul 29 '20 at 18:04
• If you have a time to edit (extend) your, would be great :) – vklidu Jul 29 '20 at 19:52
• @vklidu Will do, and yes it is thanks, color neutrality be damned! :D – gandalf3 Jul 29 '20 at 19:56
• This solution is possible only because matcaps are from version 2.8 in EXR :) – vklidu Jul 29 '20 at 20:06

Showing some transparency from images with Matte Nodes. Some Flaws Present. Image above.

The compositor may be a partial contributor to the solution. The flaws are visible. Your files are read and matted by color. The black pixels within a sample would be background. Please inspect and improve the nodes.

• If the inaccuracy of deriving the silhouette from the normal map is too much, you can probably arrange to extract the correct silhouette from another channel/render pass – gandalf3 Jul 29 '20 at 20:02