Skip to main content
Bounty Ended with 50 reputation awarded by Noob Cat
Improvements on the sphere coordinates
Source Link
Daniel Möller
  • 3.8k
  • 10
  • 14

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)

Sphere map - using normals (requires shade smooth)

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)

Mapping for spheres based on position updated
Source Link
Daniel Möller
  • 3.8k
  • 10
  • 14

We can force some UV mappings procedurally

We can do our own UV mapping in shader nodes, consideringThis solution considers every change of face direction is"direction change" in the faces as a seam. We just needUsing some math with the face normals andinvolving the global axes and the face normals, we can create their mapping.

Sphere map (using- using normals - require(requires shade smooth)

Important:Sphere map with normals

If you intend to rotate the object, you need to "invert" the rotate vector inside the node group, then you need to copy each rotation value of the sphere as a "driver" and add each driver value to the rotation of the "Sphere Map" groupAdvantages:

  • Uses only a shader

Sphere map with normals 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.

Sphere map (usingusing position - require(requires geometry nodes)

Sphere map using position

One quirk that can happen with normals is if you have concave objects, the concavity will have inverted texture.

To avoid thisthe problems of moving textures, bad concavities, etc., we can use a "position" based mapping. But since shaders don't understand local geometry position-wise map (does the exact same thing as the previous mapif it does, but using positionsplease teach me), I had to resort to geometry nodes.

Sphere map using position

  • 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 (to achieve this in shader, one would probably need to attach a driver to the rotation of the map taking the rotation of the object)

CaveatsDisadvantages:

  • Since shaders don't understand local geometry position (if it does, please teach me), I had to resort toRequires that the shader be used on top of a geometry nodesnode group.
  • The only attribute that gets interpolated by the shader is the one added to points, this means thatMay show glitches on the seam will have eitherpoles of the start orsphere (can't decide the endX value for the poles, not both. Soany value will disrupt some of the surrounding faces connected) - 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 get funny mappingproblem (I'll probably take some time latervertices on the seam need to think about a solutionbe both x = 0 and x = 1 simultaneously for the shader to this... vague ideas are formingwork)., 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 geometry nodesshader group

Geometry nodes for sphere map 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

We can do our own UV mapping in shader nodes, considering every change of face direction is a seam. We just need some math with the face normals and the global axes.

Sphere map (using normals - require shade smooth)

Important:

If you intend to rotate the object, you need to "invert" the rotate vector inside the node group, then you need to copy each rotation value of the sphere as a "driver" and add each driver value to the rotation of the "Sphere Map" group

Sphere map with normals

Sphere map (using position - require geometry nodes)

Sphere map using position

One quirk that can happen with normals is if you have concave objects, the concavity will have inverted texture.

To avoid this, we can use a position-wise map (does the exact same thing as the previous map, but using positions).

  • 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 (to achieve this in shader, one would probably need to attach a driver to the rotation of the map taking the rotation of the object)

Caveats:

  • Since shaders don't understand local geometry position (if it does, please teach me), I had to resort to geometry nodes.
  • The only attribute that gets interpolated by the shader is the one added to points, this means that the seam will have either the start or the end value, not both. So faces connected to the seam get funny mapping (I'll probably take some time later to think about a solution to this... vague ideas are forming).

The geometry nodes

Geometry nodes for sphere map

We can force some UV mappings procedurally

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.

Sphere map - using normals (requires 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.

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

  • 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

added 39 characters in body
Source Link
Daniel Möller
  • 3.8k
  • 10
  • 14

Face map

We can do our own UV mapping in shader nodes, considering every change of face direction is a seam. We just need some math with the face normals and the global axes.

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 (using normals - require 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.

Important:

If you intend to rotate the object, you need to "invert" the rotate vector inside the node group, then you need to copy each rotation value of the sphere as a "driver" and add each driver value to the rotation of the "Sphere Map" group

Sphere map with normals

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 - require geometry nodes)

Sphere map using position

One quirk that can happen with normals is if you have concave objects, the concavity will have inverted texture.

To avoid this, we can use a position-wise map (does the exact same thing as the previous map, but using positions).

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 (to achieve this in shader, one would probably need to attach a driver to the rotation of the map taking the rotation of the object)

Caveats:

  • Since shaders don't understand local geometry position (if it does, please teach me), I had to resort to geometry nodes.
  • The only attribute that gets interpolated by the shader is the one added to points, this means that the seam will have either the start or the end value, not both. So faces connected to the seam get funny mapping (I'll probably take some time later to think about a solution to this... vague ideas are forming).

The geometry nodes

Geometry nodes for sphere map

File

Face map

We can do our own UV mapping in shader nodes, considering every change of face direction is a seam. We just need some math with the face normals and the global axes.

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 (using normals - require 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.

Important:

If you intend to rotate the object, you need to "invert" the rotate vector inside the node group, then you need to copy each rotation value of the sphere as a "driver" and add each driver value to the rotation of the "Sphere Map" group

Sphere map with normals

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 - require geometry nodes)

Sphere map using position

One quirk that can happen with normals is if you have concave objects, the concavity will have inverted texture.

To avoid this, we can use a position-wise map (does the exact same thing as the previous map, but using positions).

Advantages:

  • Can deal with concavities
  • Can be improved to have a displaced center (don't know if it would be useful)
  • Object can be rotated and texture will follow (to achieve this in shader, one would probably need to attach a driver to the rotation of the map taking the rotation of the object)

Caveats:

  • Since shaders don't understand local geometry position (if it does, please teach me), I had to resort to geometry nodes.
  • The only attribute that gets interpolated by the shader is the one added to points, this means that the seam will have either the start or the end value, not both. So faces connected to the seam get funny mapping (I'll probably take some time later to think about a solution to this... vague ideas are forming).

The geometry nodes

Geometry nodes for sphere map

File

Face map

We can do our own UV mapping in shader nodes, considering every change of face direction is a seam. We just need some math with the face normals and the global axes.

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 (using normals - require 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.

Important:

If you intend to rotate the object, you need to "invert" the rotate vector inside the node group, then you need to copy each rotation value of the sphere as a "driver" and add each driver value to the rotation of the "Sphere Map" group

Sphere map with normals

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 - require geometry nodes)

Sphere map using position

One quirk that can happen with normals is if you have concave objects, the concavity will have inverted texture.

To avoid this, we can use a position-wise map (does the exact same thing as the previous map, but using positions).

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 (to achieve this in shader, one would probably need to attach a driver to the rotation of the map taking the rotation of the object)

Caveats:

  • Since shaders don't understand local geometry position (if it does, please teach me), I had to resort to geometry nodes.
  • The only attribute that gets interpolated by the shader is the one added to points, this means that the seam will have either the start or the end value, not both. So faces connected to the seam get funny mapping (I'll probably take some time later to think about a solution to this... vague ideas are forming).

The geometry nodes

Geometry nodes for sphere map

File

added 257 characters in body
Source Link
Daniel Möller
  • 3.8k
  • 10
  • 14
Loading
New solutions for sphere like objects
Source Link
Daniel Möller
  • 3.8k
  • 10
  • 14
Loading
Attached the voronoii and made a node group for organizing
Source Link
Daniel Möller
  • 3.8k
  • 10
  • 14
Loading
Source Link
Daniel Möller
  • 3.8k
  • 10
  • 14
Loading