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:
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 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.
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).
Shader nodes
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.
Advantages:
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.
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.
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
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
File