3
$\begingroup$

I am trying to set up a mapping on each cell produced by the Voronoii Node. But I am running into a problem that I am unable to solve.

I would like each cell to make its mapping procedurally, but I am not sure how to achieve this.


Note: In this example I would like to keep the Voronoii coordinates set to Object, as I would like to avoid any UV mapping setup.


Here is the example I get with this node configuration:

My node Configuration

$\endgroup$
6
  • $\begingroup$ connect UV to voronoi, and set voronoi to 2D mode. $\endgroup$ Commented Oct 26 at 10:24
  • $\begingroup$ @MarkusvonBroady I added a note, as I would like to keep the coordinates on Object. It occurs to me that one could use the "Normal" Coordinates in combination with the Position output of the voronoii but I am not sure how to do it. $\endgroup$
    – Noob Cat
    Commented Oct 26 at 10:39
  • $\begingroup$ Why do you need "Object", that is sort of flawed and is what is causing your problems. If you use UV or take a "position/location" from a "geometry" node it would be waay easier. $\endgroup$ Commented Oct 27 at 2:53
  • $\begingroup$ you simply need to take 2 out of 3 coordinates, and decide which coordinates you take based on normal. At least for a cube. $\endgroup$ Commented Oct 27 at 10:49
  • $\begingroup$ @MarkusvonBroady You might think about proposing an illustrated answer, unfortunately for me the comment alone does not make me understand the configuration you have in mind. $\endgroup$
    – Noob Cat
    Commented Oct 27 at 12:37

1 Answer 1

3
+50
$\begingroup$

We can force some UV mappings procedurally

Face map

This solution considers every "direction change" in the faces as a seam. Using some math involving the global axes and the face normals, we can create their mapping.

Main nodes

Here we just connect your Voronoii setup with the said mapping for faces:

Shader nodes

Face map non Z - This is a subgroup inside the "Face map" group

This maps every face, making their local Y be the projection of the given global Z onto the face (fails when face normal = global z)

The principle is simple:

  • Crossproduct from global Z to Normal gives us local X
  • Crossproduct from Normal to Local X gives us Local Y
  • Dot products of position by each local axis gives us the projected position onto these axes

Face mapping non Z

Face mapping 2 (general) - this is shown in the main nodes

Because the crossproduct is zero when normal equals global Z, we need exceptional treatment for faces that are flat on XY.

Face map general

Based on these questions:


Sphere map

For a sphere map, all we need to do is get the object coordinates (as long as its origin is at the center) and convert them to spherical coordinates remapped from 0 to 1 (where X is the horizontal angle -180 to +180 and Y is the vertical angle -90 to +90).

enter image description here

Shader nodes

enter image description here

File


WARNING

Everything below this line is experiments that I made before learning something important about what the "Object" texture coordinates mean.

They're not important for the answer, but may have some insights.

WARNING


Sphere map - using normals (requires shade smooth)

This is a simple map that takes the normals of the object and map these normals to coordinates similar to a UV sphere.

If the object is sphere-like, there will be some distortions, but it might be good enough. It also requires the object to be shade-smooth.

Sphere map with normals

Advantages:

  • Uses only a shader

Disadvantages:

  • Requires shade smooth, otherwise it will pixelate to the face size
  • If there is a concavity, the texture will invert in the cavity, creating ugly distortions.
  • Shaders don't give you access to the geometry local coordinates, meaning that if you move or rotate the object, the texture will not follow (there will be movement between the texture and the object)
    • If you intend to rotate the object, you need to copy each rotation value of the sphere as a "driver" and paste each driver value to the rotation of the "Sphere Map" group. Unfortunately, if you have two objects, that will not work.

The node group

For a sphere of radius 1, its normals are equal to its coordinates.
All this node does is to transform these normals/coordinates into spherical coordinates and map the angles from 0 to 1, the same way a UV Sphere has its UV map.

Convert normals to UV map

Sphere map using position (requires geometry nodes)

To avoid the problems of moving textures, bad concavities, etc., we can use a "position" based mapping. But since shaders don't understand local geometry position (if it does, please teach me), I had to resort to geometry nodes.

Sphere map using position

Advantages:

  • Can deal with concavities
  • Does not require shade smooth
  • Can be improved to have a displaced center (don't know if it would be useful)
  • Object can be rotated and texture will follow

Disadvantages:

  • Requires that the shader be used on top of a geometry node group.
  • May show glitches on the poles of the sphere (can't decide the X value for the poles, any value will disrupt some of the surrounding faces) - Solution is to have small faces around the pole

The geometry nodes

Concepts:

  • Uses the position the same way the normals were used in the normal sphere map
  • To avoid a seam problem (vertices on the seam need to be both x = 0 and x = 1 simultaneously for the shader to work), we create two different X attributes
    • One attribute tells if a face is High X or Low X
    • For low X faces, we subtract 1 from X, but only if it's a high X
    • For high X faces, we add 1 to X, but only if it's a low X

Geometry nodes for sphere map

The shader group

This gets the values for X and Y, join and scales.
But for X, it checks which of the two X attributes should be used based on whether it's a High X face or a Low X face

enter image description here

File

$\endgroup$
3
  • $\begingroup$ Interesting answer, do you think it is possible to make it so that it can be mapped on Meshes that are not a cube? Like a sphere? I just tried to use this material on a sphere, and as I suspected it does not give an acceptable result. Probably it is not possible to do it? $\endgroup$
    – Noob Cat
    Commented Nov 18 at 16:32
  • $\begingroup$ Yes, that's a universal "face-orientation-wise UV", but every direction change is a new UV island. For a sphere, use the standard UV mapping. $\endgroup$ Commented Nov 18 at 17:50
  • 1
    $\begingroup$ @NoobCat, check the updated answer $\endgroup$ Commented Nov 18 at 20:03

You must log in to answer this question.

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