# Can I color a curve in Cycles by the direction it's running?

I'd like to colour a beveled curve in Cycles by its tangent (the tangent of the actual curve - not its beveled faces).

For example:

In this image, the curves running up/down are blue, and the left/right curves are green. Is this information accessible in Cycles?

• care to share a small sample blend ? :) Dec 16, 2015 at 9:03
• I don't actually have a good blend yet - I still need to write the script to import the fiber tracts. Will hopefully get to that in the next few days. Dec 16, 2015 at 14:42
• Alas, my laptop is I'd fried :( Time do do some research on the best choice for new hardware! Dec 18, 2015 at 2:59
• There might be a way to do this using using the Texture Coordinate node... near the bottom there is a text field where you can use another object to control the texture space... an empty for example or a flat plane with a texture map with a full range of colors perhaps... Jan 27, 2016 at 1:58
• @zeffii I have a sample blend, but it's impractically large - 334,000 vertices in my curve object. Turns into 23.4 million Tris after beveling :/ I can share if you like. Feb 1, 2016 at 16:33

This is totally possible with the Tangent node (Input > Tangent):

Change the type from Radial to UV Map and also enable Use UV for mapping in Curve's data tab:

The problem is we get black instead of Z-axis direction. That's easily fixable - add both green and red channels together and invert them into a blue channel. To also not care about the direction of axis we make the tangent vector values absolute:

• This looks really promising! My context doesn't care about the sign of the tangent though.. so up-pointing-down should look the same as down-pointing-up. I suppose I could take the absolute value of the tangent vector. Can you think of the best way to make it note care about the sign of the tangent, without throwing out half of the colour space? Jan 29, 2016 at 21:48

Think I may have figured out a way. If you enable "use UV for mapping" you'll copy the curve U/V coords to the UV map of the beveled object.

You can then use the vector transform node to strip off the object transform:

AFAIK this will fail if any of the curves have been transformed in edit mode since it relies on the object transform to get the coords back to world space.

Not sure if this is the best way, but I think any solution would have to be based around the "Use UV for Mapping" function as I don't think Cycles has access to the path itself, just the beveled and tessellated output mesh.

• Don't fully follow yet, but looks interesting! ...I'm wondering, would this get easier if I dropped the Cycles restriction? Jan 27, 2016 at 12:30
• @ajwood UV's on itself are useless. There has to be math done with normal and tangent vectors from geometry node to get the actual spacial orientation of the surface. If Cycles cannot do it then there might be solution involving converting the curves into mesh and assigning vertex colors with script. Jan 27, 2016 at 15:54