1
$\begingroup$

I have a particular request:

For each pixel of an image, I would like to know at what distance the ray first entered the mesh and at what distance the ray last exited the mesh of an object.

In fact, I need to generate not only the "visible" depth map of an image, but also the "invisible" depth map. Those would consist in two point clouds that would act like a "mould" for my object.

Would it be possible to solve this with a Python script? Should I loop over each pixel and call the ray_casting function? I'm afraid it would take a long time to compute (I have many images to generate).

What functions would you use? Any help on how to code this is welcomed, I am Blender beginner.

Thanks

$\endgroup$
  • $\begingroup$ What is your ultimate goal here? You could split mesh into visible and invisible(backfacing) faces and render and composite 2 depth maps or perhaps even do it with Cycles node material. $\endgroup$ – kheetor May 7 '18 at 17:00
  • $\begingroup$ The goal here is to train a neural network to predict the two point clouds of an object from one image. For that I need many pictures with correct annotation (the two point clouds). - Regarding splitting the mesh, how would that work if the mesh in non-convex? (one ray enters and exit the volume several times) - Regarding the cycles node material, could you ellaborate a bit more on how you would design that? Thanks! $\endgroup$ – user56235 May 7 '18 at 21:21
2
$\begingroup$

Here is an example setup for rendering both front and back depth using red and blue channels with Blender Cycles.

We are rendering "depth" through Cycles emission that mixes with transparency so we can receive emission from the backfacing surface as well. In this setup the emission value is derived from world space Z-coordinate and orthographic camera is facing down.

Dual depth

Red emission receives depth as is, so a face that has Z-coordinate of 0 is black and 1 is fully red. Red depth is multiplied by inverse of Transparent Depth so we are only receiving it from the front surfaces where the value is 0 and inverse is 1.

Blue emission receives inverse of depth, so a face that has Z-coordinate of 1 is black and 0 is fully blue. Blue depth is multiplied by the Transparent Depth so we are only receiving it from the backfacing surfaces where the value is 1.

$\endgroup$
  • $\begingroup$ Your solution works great except I get an issue when the solid in not convex (the rays enter and exit the solid several times). In this case the blue emissions of several surfaces add up and fake the result. For the blue emission, how could I just use the furthest surface and ignore the other ones? $\endgroup$ – user56235 May 13 '18 at 7:14
  • $\begingroup$ As far as I know the concept of "last surface" is impossible using material nodes. The meshes in this workflow need to be such that the rays don't enter and exit multiple times as you can't distinguish between surfaces at various depths. Isn't this true for your intended use/intention as well? You can't express depth values of multiple overlapping faces in an image. If you need to use models that are incompatible with this render technique you could look into flipping the camera to the other side of the object where you can again read the first surface. $\endgroup$ – kheetor May 13 '18 at 15:37
  • $\begingroup$ Ok I understand, unfortunately the objects I will use are complex to the light enters and exits the volume several times. I will try your second technique then, using two cameras Thanks for your help $\endgroup$ – user56235 May 13 '18 at 16:34
  • $\begingroup$ But using the image approach, machine vision will only be able to see the first and last surface though. This won't be a point cloud type of information. Will it be able to analyze complex shapes properly without the full information? $\endgroup$ – kheetor May 14 '18 at 8:53
  • $\begingroup$ Yes we will lose information for complex shapes but for most of them the first and last surface already provide a lot of information. $\endgroup$ – user56235 May 17 '18 at 9:37
0
$\begingroup$

Thank you kheetor!

I have used your solution below:

enter image description here

It works great but I get an issue when the solid in not convex (the rays enter and exit the solid several times). In this case the blue emissions of several surfaces add up and fake the result. For the blue emission, how could I just use the furthest surface and ignore the other ones?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.