# How the Normal Map baking works, what is the ray direction

I've gone into some trouble understanding how the ray shoot out and the size relationship between the high and low poly mesh, below is my understanding,

But which one is right? From the menual it says the ray is generated from the low poly inwards to the high poly, then I suppose the first illustration is not right, because it points outwards.

The second illustration, the middle section should been working properly, but the left and right section has no high poly surfaces to point to, because it is starting point is inside the high poly, I searched and found someone says I can set the ray distance, then setting the distance won't change where the starting point the ray started, am I right?

The last one is I think how it should work, by having the low poly encapsulating the high poly, but I still needs some basic understanding how blender works with Normal map baking, thanks!

Edit:It turns out the ray will travel in both direction as opposed to what the Doc. says towards inwards.

The above shows the low poly has a cube inside and sphere outside, both have been reflected on the low poly cube.

So first, let's make sure we define what "inwards" means. I'm going to say it means in the opposite direction of your low poly's normals. So if we were to draw your low poly's normals on your graphs above, the normals would be pointing upwards.

As of 2.91.0-ish, rays are shot in the opposite direction of the low poly's normals-- that is, inward. Rays that fail to intersect cause 0.5,0.5,1.0 to be written (which is the same thing as saying, using the low poly's own normals.)

My memory of this in earlier versions (like 2.79, 2.80) was that rays were shot in both directions, but you would still want an enclosed high poly, because rays shot in the direction of the low poly's normals would hit the backfaces of the high poly rather than the front faces, and you'd get screwed up normals.

"Ray distance", just a version or two ago, referred to what is now "Extrusion." This means to start the rays offset in the direction of the low poly's normals. It is exactly the same as baking from a displaced low poly, or baking from a cage with a numeric shrink/fatten operation applied to all vertices. To be explict, this does change the origin of the rays.

"Max ray distance", as implemented a version or two ago, means that Blender will just discard results that arise from intersections greater than a certain distance. I'm not really sure what the intended use for this is, although it can be useful for some texture baking situations that are selected-to-active bakes but couldn't reasonably be described as high-to-low bakes, like baking text objects to a texture or something. This does not change the origin of the rays.

• As the Doc. said,"The rays are cast from the low-poly object inwards towards the high-poly object", at least for version 2.9, it should only shoots towards inwards, but I need to have a try. As for ray distance, it changes the origin of the ray, could you elaborate when to use this feasure? Commented Feb 4, 2021 at 5:21
• @user3505400 On testing in 2.91.0, high poly in the direction of the low poly normal is now ignored; it just writes 0.5,0.5,1. I'll update the answer. As mentioned, "max ray distance" does not change the origin of the ray; "extrusion" changes the origin of the ray. You can use this to virtually enclose your high poly, by offsetting the origin of the ray in the direction of the low poly normals. Commented Feb 4, 2021 at 5:33
• Doc. says "If the high-poly object is not entirely involved by the low-poly object, you can tweak the rays start point with Ray Distance", while I need to have some trials. Commented Feb 4, 2021 at 5:40
• @user3505400 Do some tests. Docs are not always right. It is probably referring to the "ray distance" used by earlier versions, which is now called "extrusion". It is not referring to "max ray distance", which is something else, and does not change the ray origin. Commented Feb 4, 2021 at 5:42
• Good point, I'll do some test after Commented Feb 4, 2021 at 6:53

I just want to point out that there is a flaw in the methodology shown in the first picture, with the lowpoly cube capturing the spheres and smoothed cube.

At first glance, this test case seems to show that some rays are being cast towards the outside of the lowpoly cube, since the sphere does appear in the bake after all. And also intuitively, it would be reasonable to think that this captured sphere has seemingly been caught by rays sent along the normals of the closest nearby face of the lowpoly (= the top face of the lowpoly cube, close to the sphere in 3d space).

However from the tests I've been running, this sphere has likely been captured by the rays sent backwards/inwards, from the opposite side of the cube (i.e. the face of the cube that sits on the floor grid in the example). This could be verified by looking at the location of the baked sphere on the UV map of the lowpoly cube.

So from there this confirms that indeed, in recent Blender versions, rays are only sent inward ; and a pushed/"extruded" cage or an extrusion distance value is always necessary to fully capture the surface of a high poly model that sits both above and below the surface of the low.

This is a different behavior from that of Marmoset Toolbag (and possibly older versions of Blender) in which the cageless behavior consists of shooting both ways.

There is really nothing wrong with the current behavior but it is indeed rather counter-intuitive since it means than any cageless bake attempting to capture a subdivided high will only ever capture about half of its surface unless an extrusion value is entered. This in turn gives the impression that Blender baking fails at a simple task that other bakers can do just fine (that is to say : a simple cageless bake at default values attempting to capture a highpoly that is both above and below the surface of the low, which is an extremely common scenario).

And, since other baking environments only require an increase in ray distance value to fix missed rays, the impression of the Blender baker being broken gets reinforced because merely increasing the ray distance will never make highpolies sitting above the surface of the low appear in the bake - only an increase in extrusion value will.