I'm trying to sample a nurbs surface given certain constraints. Basically I'm trying to reproduce in 3D the following 2D situation. I don't know how to do this in 2D either so I need suggestions anyway.

The black curve would be my spline surface, the green line would be a plane above the surface. What I want to do is to shoot rays from the plane ortogonally, in equally spaced points, compute the intersections of such rays with the surfaces and store those points (the ones in the blue circle).

Is there a way to achieve this?

(I'm trying to emulate a depth map).

enter image description here

  • $\begingroup$ Hello! Can I ask you more in details what do you mean when you say "store those points" ? Do you want to obtain a Python (numpy) array representation of those points, or you want a mesh made of quadrilateral faces, or something different? $\endgroup$ – Nicola Sap Sep 18 '18 at 13:17
  • $\begingroup$ Ideally I'd like to have an image where each pixel stores the z coordinates, literally a depth map. I could sample the (u,v) coordinates but that wouldn't be the same thing. $\endgroup$ – user8469759 Sep 18 '18 at 13:19

1) Z-buffer (real depth map)

Place a camera above the surface

enter image description here

Set it to Ortographic. Then go in Camera view (Numpad 0) and change its Clipping values in such a way that they are the "tightest" possible to display all the curve (i.e. the biggest possible "Start" and the smallest possible "End")

enter image description here enter image description here

Render the image (F12), then select "Z-Buffer" in the list of Channels below the render window:

enter image description here

This will give you an actual depth map.

or 2) Z-dependent Emission color (faked depth map using Cycles)

Place your surface in a scene where the world is completely black and there are no lights. Use "Cycles" as the render engine.

Note down the minimum and the maximum "z" location (in my example, 0.1 and 0.9)

enter image description here

Assign a material that has the following node structure:

enter image description here

where in the Math nodes you'll use the values of min(z) and (max(z)-min(z)) noted down before, in my case 0.1 and 0.8.

Of course the colorRamp can be changed according to your needs.

This will color your surface with a different color according to its height:

enter image description here.

Place an ortographic camera along the "z" axis (frame the surface from above) and render. The render will be a depth map

enter image description here

  • $\begingroup$ Any chance you can attach the obj of your surface? So I can reproduce your example. $\endgroup$ – user8469759 Sep 18 '18 at 14:09
  • $\begingroup$ sorry I've closed the file. however, it was just a Add>NURBS surface subdivided in edit mode and with a vertex pulled away. (May I ask you to avoid leaving multiple comments? The comment section is not for extended conversation. Thanks) $\endgroup$ – Nicola Sap Sep 18 '18 at 14:15
  • $\begingroup$ Very last question, how do I save the depth map into a file (.png)? $\endgroup$ – user8469759 Sep 18 '18 at 15:19
  • $\begingroup$ Unfortunately, the "easy" way is just to take a screenshot, as "Save as Image" will always export the full rendered picture (even if you have selected "Z-buffer"). The "clean" way is by using compositor "File Output" node as explained here: blender.stackexchange.com/questions/57972/… $\endgroup$ – Nicola Sap Sep 18 '18 at 15:28

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.