# Blender geometry node proximity with negative values

I'm looking for a representation of the distance between 2 meshes, one in high resolution (mesh A) and the other in low resolution (mesh B), so to speak, in order to visualise micro-reliefs more easily.

I first considered using "Geometry Proximity", but this node doesn't take "negative distances" into account. If mesh A is the reference mesh :

• when mesh B is on top, I'd like the values to be positive
• when mesh B is below, I'd like the values to be negative.

I think the simplest thing would be to take into account the relationship between the B mesh and the normals of the faces in the A mesh, but I haven't the slightest idea how to do that...

To get a better idea of the problem, here's the result I get. The idea is to obtain a greyscale gradient where black is the maximum negative value and white the maximum positive value.

# Edit 1

Thank you for your help. I struggle to build the node tree...

You will find the file I'm working on with this link

Geometry Proximity returns a distance, and a distance simply is always positive. You can turn it negative by checking whether or not the point in question in above or below the target mesh : use a raycast node, target the same mesh as does your Geometry Proximity and set the ray direction to be vertical (the vector should be 0,0,1). Use the "is hit" output to switch (Switch node) between the original distance value (output from the Geometry Proximity node) and the same value multiplied by -1.

Finally, you can use the Attribute Statistic node to remap the values between 0 and 1 : use the Min and Max outputs, and pipe them into the From Min and From Max inputs of a Map Range node.

• Thank you for your help, but I struggle to build the node tree :'( ... (see edit 1 in the question) Oct 9, 2023 at 13:49
• I did away with the raycast (because Geometry Proximity provides us with the position of the closest point already, so we can use it to check whether it is above or below), it works but I cannot solve a precision issue that happens when Suzanne crosses the threshold : it seems that comparing almost identical floats breaks the effect. I haven't been able to alleviate this, sorry. blend-exchange.com/b/kL1p9e1n Oct 9, 2023 at 20:14
• Thank you very much for your time! I was thinking about : the file I provide you is an extreme simplification of what I would like to achieve. I want to apply this between a high resolution mesh (from photogrammetry) and a simplified one. So the distance are really small and are everywhere going up and down. Would it be possible if we : 1. use the raycast node and separate the geometry between the above/underneath ; 2. use a geometry proximity on both parts ; 3. multiply by -1 the underneath part ; 4. and join the geometry with their values? Oct 10, 2023 at 7:25
• If the terms of the problem are different, maybe you can try to bring the example file as close as possible to the actual one ? testing against a plane may not translate well to the actual objects Oct 10, 2023 at 11:54
• You will find here a typical example of a mesh I want to document : drive.proton.me/urls/K5SGXB6DE0#UcIWs1L8GvY7 (275 Mo) My main goal is to simplify the process of computing the distance between 2 meshes, just as we can do with the plugin Distance Map. But with huge meshes, the computation is too long. That's why I'm looking to reproduce this in a more interactive way with Geometry Nodes. Thanks for your time! Oct 10, 2023 at 13:45

Given the additional details in the comments, I am suggesting a new solution. "Above" and "below" really mean "outside" and "inside" the other object's surface, so we'll be using two raycast nodes and storing the returned distance into an attribute. If the hit is made using the second raycast node -which points inwards- then we're multiplying the distance value by -1.

A couple gotchas :

Bear in mind that normalizing these values loses the midlevel, which means there is no guarantee that a point sitting at the same exact same place as its "lowres" counterpart (=neither outside nor inside) will have a value of 0.5. This will depend just how high and how low the values go. If the highres object goes "outwards" more than it goes "inwards", then the whole of the values will be skewed towards 1. In light of this, I also stored the non-normalized distance attribute into a separate attribute, so that you can clearly discriminate vertices that are outside from vertices that are inside. Perhaps a future improvement could be storing and normalizing both distance values separately, so that the midlevel isn't lost. Not sure if this is desirable for you.

Secondly, some vertices will never hit the surface of the lowres object (usually because they lie on the border and their normal points in a direction that never crosses the other surface). For these outliers, we have to have a fallback value. I've chosen to use a Geometry Proximity node, which is a bit arbitrary but not sure what else to do really.

Finally, the blend file was too big for Blend-Exchange so I had to delete the mesh data. I left the objects, so all you should have to do is append the actual objects and join them (ctrl+J) with the ones in the file.