2

I'm attempting to use micropolygon displacement to displace a cube into a larger cube, in an attempt to wrap my head around this feature. As near as I can tell, the following should work. Take a cube with each face having UVs in the range -1 to 1, so that 0 is in the center of the face. Calculate the length of the UV, which should be in the range 0 to sqrt(2), and map that to 1 to sqrt(3). Use that as the displacement height. The cube is of course set to smooth shading.

The result is close to a cube, but off. enter image description here

Chris_F
  • 142
  • 5

3 Answers3

2

I would like to point out :

  • I think your math is off
  • You can get the length of a vector with a Vector Math node set to "Length"
  • The UV map vector Z coordinate is 0 (I think)

The resulting node tree would be :

enter image description here

But since the "Displacement" node pushes geometry along the normals, you can get rid of your UV map setup like so :

enter image description here

Gorgious
  • 30,723
  • 2
  • 44
  • 101
  • Maybe should point out, unless I'm up the creek, (which I often am), that the displacement is along vertex normals, and the same for all, so these solutions rely on there being no vertex at the center of the faces. – Robin Betts Jun 19 '20 at 11:17
  • 1
    You are right, my answer doesn't work if the cube is subdivided. But then if you manage to use the face normal, you get a cube that looks like it was beveled because there is a separation between where the vertex should go according to the different face normals it is attached to – Gorgious Jun 19 '20 at 11:23
  • 1
    A solution would be to use a Vector Displacement node to add the corresponding delta but honestly it seems too complicated for the expected result and wouldn't even be usable on other meshes – Gorgious Jun 19 '20 at 11:32
  • Well, you were right about my math being off, but you solution is also incorrect which is why it only works for a cube with 4 vertices. The displacement value should have been sqrt(1+u^2+v^2) – Chris_F Jun 19 '20 at 19:32
2

After sleeping on it I realized my mistake. The displacement factor should be sqrt(1+u^2+v^2).

enter image description here

Chris_F
  • 142
  • 5
1

I'll add another method suggested by this video.

You need to plug the "Object" coordinates from the "Texture Coordinate" node into a "Vector Displacement" node set to "Object Space", not tangent with a midlevel of 0.

This will scale each point along its base coordinates, thus scaling the geometry uniformly.

Also, it works with a subdivided cube, and really any mesh geometry.

enter image description here

enter image description here

Gorgious
  • 30,723
  • 2
  • 44
  • 101
  • 1
    Phew! .. that's a bit simpler. – Robin Betts Jun 22 '20 at 09:22
  • 1
    Yup :) There seems to be a slight deformation along the Z axis though on Suzanne... Couldn't figure why, the cube deformation looks uniform though. – Gorgious Jun 22 '20 at 09:52
  • 1
    Every shading point is displaced by [its own coordinate in the given space] with the origin set to (Midlevel,Midlevel,Midlevel). The displacement, here, actually takes place in Object space. Because the given Generated space is 0-1 along the sides of the object's bounding box, (with its origin at min XYZ,) and a monkey is not a cube, the given Generated space, from which the original coordinates are taken, is non-uniformly scaled with respect to the Object space in which the displacement takes place. Use Object texture coordinates, and a midlevel of 0. – Robin Betts Jun 22 '20 at 10:51
  • Oh, right ! That makes perfect sense :) – Gorgious Jun 22 '20 at 12:10