0

With the new 3.3 Hair and UV Map nodes, the obvious use case is hair alpha cards! How would you use the new node to unwrap along the hair curves? We've gotten this far, but as you can see there are some errors where it guesses wrong:

enter image description here

ogbog
  • 191
  • 9

3 Answers3

2

Map Hair Curves (without meshing/ topology)

UV Mapping hair curves

Overview

There are 4 ways to render hair (without geo); 2 in cycles and 2 in eevee. 3 of them have virtual surfaces that we can uv.

Cycles:

  1. 3D curves
  2. Rounded Ribbons

Eevee:

  1. Strip

The Idea is to use shader nodes - where we have access to the surface (attributes) - to construct the UV’s together with the help of geometry nodes for some attribute we don’t have in the shader graph.

3D curves

Explanation:

We do something similar to cylinder projection/mapping. We basically make a radial gradient for X and use Z (up-along the curve) as Y - in this case that is the spline parameter Factor (or curve info Intercept).

We first have to construct the relative xy coordinates of the curve. To use on a gradient texture node set to radial, or with arctan2).

To construct this we will need the curve Normal, Tangent, and position from geometry nodes.

We will get the direction and magnitude of the surface from the underlying curve - by subtracting curve position the surface’s position (texture coordinate object) - , when put through a dot product with the curve normal will give us a range of values in the direction of the normal (, so 1 when it matches the normal in magnitude and direction, -1 when it points in the opposite direction, the values in between, and passed). This is our X.

For the Y we need to do the same thing, but have the direction be perpendicular to [90° from] the normal. For this we do a cross product between the curve normal and tangent. (then do the same thing as stated above) This is the Y.

To make the radial gradient use the built in node for that with this as the vector. If you want to know the math, it’s $\arctan\!2{(y,x)} \ + \ \pi \over \pi$ ((arctan2(y,x) + pi) / pi). This is your UVs’ U.

Your UVs’ V is the spline parameter Factor (from GN) or curve info Intercept.

Implementation:

  • Get Attributes from GN (on the point domain)

    Untitled

  • Make Surface Direction (in shader node)

    Untitled

  • Make the X coordinate

    Untitled

  • Make Y coordinate

    Untitled

  • Make U

    Untitled

  • Make V

    Untitled


Strip

enter image description here

Rounded Ribbons

enter image description here

…since the surfaces faces the camera we need the uv's to do the same. we can take the camera direction (from the surface) and cross product with the curve tangent to get a direction pointing across the surface - which you can call the Surface Tangent - . We can use this direction with a dot product with the non-normalized direction of the surface to the curve positive (or the “relative position”) like we did with the 3D Curves.

The radius also didn’t matter before, because it was radial where it doesn't matter how far the surface is from the center.

shmuel
  • 1,560
  • 10
  • Should I move my answer here https://blender.stackexchange.com/q/64515/165102 ? – shmuel May 19 '23 at 00:01
  • No, I think it's fine here. This question/post is more popular and has many more views (~600 in 6 months vs ~600 views in 6.5 years!). If you like feel free to post a link in the comments there that refers to this question here. – Blunder May 20 '23 at 11:05
  • Quote: "...2 in Cycles and 2 in Eevee..." <- there is a little mistake because there is only "3. Strip" for Eevee, no "4. ..." – Blunder May 20 '23 at 11:09
  • @Blunder it's not a mistake. I also said "3 of them have virtual surfaces that we can uv." in eevee there is also the option to render as strand – shmuel May 21 '23 at 04:00
1

What you can do is construct the uv map from the factor of the hair and profile curves to get a square uv in the 0-1 range, and then it's possible to remap that range by scaling and moving it.

So capture or store the factor attribute before converting the curve to mesh, combine them into a xy vector and store it as the uvmap. enter image description here

note that it gets stored as an attribute so you need to tell your material to use it via an attribute node.

enter image description here

Dosvi
  • 11
  • 2
1

You can use curve info node, without converting to mesh.

enter image description here

Intercept - The point along the strand (1 at the tip and 0 at the root).

Combining it with random, you can set 2D map

Crantisz
  • 35,244
  • 2
  • 37
  • 89