2
$\begingroup$

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:

enter image description here

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:

enter image description here

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!

$\endgroup$
9
  • $\begingroup$ 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? $\endgroup$ Commented Jul 29, 2020 at 16:02
  • $\begingroup$ Is your question the same as .. How do I bake the Normals of a single object while ignoring other objects in the scene? ? $\endgroup$ Commented Jul 29, 2020 at 16:05
  • $\begingroup$ 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. $\endgroup$
    – lambdawaff
    Commented Jul 29, 2020 at 16:06
  • $\begingroup$ 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. $\endgroup$ Commented Jul 29, 2020 at 16:12
  • $\begingroup$ 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. $\endgroup$ Commented Jul 29, 2020 at 16:18

2 Answers 2

9
$\begingroup$

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.

    Render Properties

  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:

Suzanne


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.

$\endgroup$
6
  • 3
    $\begingroup$ ... use Workbench as regular render? Also Color Management > Standard (not Filmic). Saved as PNG RGBA 16 bit or EXR 32 bit. $\endgroup$
    – vklidu
    Commented Jul 29, 2020 at 17:58
  • $\begingroup$ @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 :) $\endgroup$
    – gandalf3
    Commented Jul 29, 2020 at 18:04
  • $\begingroup$ If you have a time to edit (extend) your, would be great :) $\endgroup$
    – vklidu
    Commented Jul 29, 2020 at 19:52
  • $\begingroup$ @vklidu Will do, and yes it is thanks, color neutrality be damned! :D $\endgroup$
    – gandalf3
    Commented Jul 29, 2020 at 19:56
  • $\begingroup$ This solution is possible only because matcaps are from version 2.8 in EXR :) $\endgroup$
    – vklidu
    Commented Jul 29, 2020 at 20:06
2
$\begingroup$

enter image description here

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

enter image description here

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.

$\endgroup$
1
  • 2
    $\begingroup$ 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 $\endgroup$
    – gandalf3
    Commented Jul 29, 2020 at 20:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .