3
$\begingroup$

This is what I'm trying to get procedurally via shading nodes:

enter image description here

This model is for reference. I want the peaks to be white and lows to be black so that I could bake Emit and get a heightmap.

Edit

(copied from comments of deleted answer)

Mostly for Displacement is used bake from flat surface (Linear Gradient texture or by Normal Z", but it seems to work only with flat surfaces. I thought there is a method to apply a gradient in Object Space, but it seems to work only in World Space.

As for the Bake Displacement from Multires method - fine details must be sculpted. What if I'm not going to use sculpting in my case, where hires features are made using a combination of mesh tools, shrinkwrap or cloth simulation that I want to bake to a lowpoly mesh? How am I supposed to bake displacement in this case?

enter image description here

$\endgroup$
4
  • $\begingroup$ If it is just a spherical object use Spherical Gradient texture ... $\endgroup$
    – vklidu
    Oct 30, 2022 at 16:30
  • $\begingroup$ I've added a screenshot for reference. The actual model is much more complex. $\endgroup$
    – ilyak
    Oct 30, 2022 at 16:33
  • 1
    $\begingroup$ So show your complex one, and the base mesh you want to use this height map ... $\endgroup$
    – vklidu
    Oct 30, 2022 at 17:33
  • 1
    $\begingroup$ If you're looking for 'height above sphere' and there are no undercuts, Length of object-space would do.. (mapped to a nice min and max) $\endgroup$
    – Robin Betts
    Oct 30, 2022 at 19:36

4 Answers 4

3
$\begingroup$

Point Position Map

as reaction to your comment about concave/convex distortion ... Height map is calculated from zero elevation in up (Normal Z) direction. If your mesh state with some topology below base mesh surface you would have to use Point Position Map instead of Height Map (if I'm right).

Here is an example of Point Position Map baked from modified default Torus object:

  • I'm skipping first two steps of previous answer with Vertex Distance.
  • Default Torus is just deformed in concave/convex direction to see effect
  • Bake type Position (as usual -keep Image Texture node selected)

Note: When hit New texture type Generated be sure 32-bit Float is checked! Othewise data will be cropped and your displacement ends with just a part of mesh since data will contains only positive values from 0-1 on XYZ).

enter image description here enter image description here

Bake used by Displacement material

(enable Experimental Features, under Material > Settings > Suface > Displacement switch to Displacement Only) on Torus B

enter image description here enter image description here

Comparison enter image description here

Bake used dy Displacement modifier

In edit mode scale all vertices to zero, add modifier (see image), under texture properties don't forget to uncheck Colour > Clamp otherwise you get only quarter of torus :).

enter image description here

The reason to scale vertices at zero location is that Point Position Map refers by colour to position point in a global space, but used by any displacement the value is added on top of existing point position.

When used by Microdisplacement (described above) it can be compensated by vector Subtract math node, but when this map is used by Displacement modifier there is not such option to math this kind of compensation.

Tip: Scale from zero to original shape back is not possible off course, so if you want to preserve original shape you can use Shape Keys :)

Both versions ...

Later I will try to check GN ...

$\endgroup$
3
  • $\begingroup$ Yes, it got the job done. Thank you very much vklidu! The only two things I didn't quite get are why we need to scale down to zero and set Displacement Strength to 0.5. I know it works, but don't quite get how :) I'm also wondering if Position map can be used externally e.g. to displace geometry in a game engine. $\endgroup$
    – ilyak
    Dec 4, 2022 at 21:25
  • $\begingroup$ Btw, your great ideas have inspired me to experiment with other ways to get a displacement map from a hires model. There's an option called Reshape in the Multires modifier. Here's what I did: 1. I duplicated my base mesh, added a Shrikwrap modifier, set the hires model as Target, 2. Added the original base mesh to selection and acquired the Shrinkwrapped mesh shape by clicking the Reshape button in the Multires modifier of the base mesh which I previously subdivided a few times. Then I just baked from multires and voilà - a nice looking classic greyscale heightmap, Yippee! $\endgroup$
    – ilyak
    Dec 4, 2022 at 21:26
  • $\begingroup$ Great you found your solution. Feel free to post your Answer with descriptive illustrations so others can learn from you :) Ad to "Scale Zero" - answer edited, hope it helps :) $\endgroup$
    – vklidu
    Dec 5, 2022 at 11:41
2
$\begingroup$

GN - Raycast

For non-spherical objects here is even more simple version with Geometry Nodes.

  • In this example I used Spheres (instead of your hairs) on Torus (your Monkey head) ...

enter image description here

  • for Torus add this node tree ...

enter image description here enter image description here

Distance output is used as Attribute in material node tree to be Baked and saved as EXR 32-bit file to be properly used for Displacement.

enter image description here enter image description here

Notes:

  • This setup uses Raycast node shooting rays from Torus to another mesh (spheres in this case). Those ray lengths are visualised as grayscale in material.

  • This doesn't solve all mesh conditions, like if you scatter shape like a mushrooms on torus surface - rays pass at bottom through a legs and stop at a head top, but rays for whole head stops at bottom of flat head part. To get proper result a rays should come from outside like a cage. I mean there is not a proper solution for all possible conditions (in example with mushrooms there wouldn't be taken into account leg in any cases for height map technique anyway :) Could be working for your Monkey head with mesh hairs.

  • I used *Math (Multiply) to assign all infinity rays (not Hit) value zero (black).

  • To bake Displacement from one object to another was feature of Blender 2.79 (Blender Internal render engine), but you had to scale base mesh in a way of "cage" to cover whole object. Usually used Alt+S Shrink/Fatten operator. That is not a big deal for torus but would be crucial for mesh like monkey head. Some more info here.

$\endgroup$
11
  • $\begingroup$ 2 passes? Bake base object-space P into a UV map, and then bake [displaced P as rendered, minus base P from previous baked image]? $\endgroup$
    – Robin Betts
    Nov 2, 2022 at 22:40
  • $\begingroup$ ??? @RobinBetts what? Too much sketchy :) "P" is position? If you mean this ... I found it a few hours ago ... But I'm not able to set it right. Please make proper answer. Thanks $\endgroup$
    – vklidu
    Nov 2, 2022 at 23:31
  • $\begingroup$ That's the one! @Nathan 's covered it. I didn't know whether 2 passes were acceptable. I've done it before, will try to reproduce. $\endgroup$
    – Robin Betts
    Nov 3, 2022 at 8:13
  • $\begingroup$ ... but the displaced and base meshes have to have the same topology. Are you thinking of sticking stuff on? $\endgroup$
    – Robin Betts
    Nov 3, 2022 at 14:21
  • 1
    $\begingroup$ Than it doesn't make it better than your comparing vertex distances in my deleted answer. I'm not thinking anymore ... :) $\endgroup$
    – vklidu
    Nov 3, 2022 at 16:25
2
$\begingroup$

At some scenario Raycast technique produces height at unwanted places (specifically at small concave surface where ray hits opposite side of a mesh) ... for that I'm bringing back this solution (which require one more step, but seems to work without mentioned issue).*


GN - Compare vertex distance

For non-spherical base object, where you need to bake meshed details into height map - you can try this workaround - Compare vertex distance between base mesh and hires.

I'm not saying it is optimal - it is just working for this example.
Big disadvantage of this technique is you need dense topology for fine details (it is nondestructive way, but could be heavy) since color information is stored per vertex for baking.


Let say for a Torus you want bubbles as height map ...
01 - Add Remesh and Decimate modifier

enter image description here

02 - Duplicate Torus (without modifiers) add Multires and Shrinkwrap modifier > Projection ...

enter image description here

03 - Duplicate Torus (without modifiers), add Multires and Geometry Nodes modifier and set this node tree (made by Robin Betts in this thread. Just Blender 3.4 has no Transfer Attribute node (seen in 3.3) ... use Sample Index node instead.

enter image description here enter image description here

and this a material and Bake > Emit ... to get height map saved in EXR format.

enter image description here

04 - Torus (base mesh) with Subdivision and Displace modifier using baked texture is identical ...

enter image description here

$\endgroup$
6
  • $\begingroup$ @RobinBetts Are you interested to answer this in some easier way? I mean to compare base mesh and hires to generate distance map. I was thinking if Raycast node could handle this better - Cast rays from base object face normal to hit hires surface in that direction ... but I'm not able set it right. Thank you ... I'm quite interested if that is possible without all these multires modifiers. $\endgroup$
    – vklidu
    Oct 31, 2022 at 18:46
  • $\begingroup$ Wow! I hadn't even contemplated this angle of attack, until you pointed out my own post :D ! I guess you could use this for full vector displacement, too? $\endgroup$
    – Robin Betts
    Oct 31, 2022 at 18:51
  • $\begingroup$ @RobinBetts ... now it is your turn here :) Thanks $\endgroup$
    – vklidu
    Oct 31, 2022 at 18:58
  • $\begingroup$ You've got to store the difference attribute on the geometry, somewhere along the line. So hi-res is unavoidable? But only for baking, then you can chuck it. $\endgroup$
    – Robin Betts
    Oct 31, 2022 at 19:07
  • $\begingroup$ @vklidu Great setup! The only thing I haven't been able to figure out yet is how to bake it in a scenario where the hires mesh has both concave and convex topology e.g. your torus example, but with the icospheres extruded inwards or both inwards and outwards imgur.com/iXKLMoQ That would be much appreciated. $\endgroup$
    – ilyak
    Nov 15, 2022 at 22:28
0
$\begingroup$

Since there's no obvious and direct way to bake a displacement map from a hipoly model to lowpoly UVs, I've decided to share my approach to baking a heightmap from a hires mesh that doesn't have sculpted features (meaning its details were modeled otherwise).

  1. Select the the hires mesh > add a Remesh modifier: enter image description here

  2. Duplicate the base mesh > add a Subdivision Surface modifier, crank up Viewport Levels > add a Shrinkwrap modifier and set the following parameters: enter image description here NB: Make sure the copy has the same location as the hires mesh.

  3. Make another copy (this time from the duplicate) > apply all the modifiers > add a Multiresolution modifier, click the Rebuild Subdivisions button in the Generate section: enter image description here

  4. Set Level Viewport to 0 > go to the Bake section in Render Settings, check Bake from Multires, set Bake Type to Displacement and click the Bake button: enter image description here > enter image description here NB: Make sure Cycles is set as Render engine.

This method is less precise than the one described by vklidu. I for one wasn't able to bake a heightmap that could fully reproduce all the features of the original mesh enter image description here

$\endgroup$

You must log in to answer this question.

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