# How to pass arbitrary floating-point data from Animation Nodes into a shader?

I want to pass arbitrary floating-point data from Animation Nodes into a shader.

I have found the Set Vertex Color node, but I have two problems with this method. The first is that the values are limited to the range [0.0, 1.0], and the second I think is due to color space transformations.

For example, the Red channel output is in the range 0.3 to 0.5:

0.47818
0.42225
0.4
0.37775
0.35661


But if I log the values in the shader using a (very slow) custom OSL script, I find that the incoming R values are different:

0.094118
0.117647
0.070588
0.133333
0.145098


How can I send an unbounded floating point value to the shader without any value transformation side-effects?

Animation Nodes:

Shader:

shader shaderDebug(color input=0,output color debug=0)
{
debug = input + 0.00001; // script is not a no-op; dont optimize away
printf("debug: %f, %f, %f\n" , input[0], input[1], input[2] );
}


## 1 Answer

You can transfer any kind of data (float, integer, negative, greater than 1, etc.) from Animation Nodes to Shader (Material) with the help of UV Map Data Output node or Set Vertex Colors node but for this, you need Animation Nodes + Extra Nodes.

Method-1: First, we have to find the total number of vertices for individual polygons using the Mesh Object Input node and Separate Polygons node. Then, Create Float List (the list you want to pass to the shader), and now we have to make its length equal to the total number of vertices of polygons which we can achieve with Fill List node (length = total number of vertices of polygons). Now, connect this final list to the UV Map Data Output node (Note: Create Float List's length <= Total number of vertices),

We have stored the data in UV coordinates which we can access in the material (I have added the color ramp node to show the difference between the values of the passed list),

Blend File:

Method-2: This is also doable with Set Vertex Colors node in Blender2.81x but node-tree is more complex and slower. Here is the example, in which first I have mapped the Float List to 0-1 range then passes it as vertex colors.

Then, in the material, I have re-mapped them to back their original values with the Map Range node,

Blend File:

• Method 1 requires using a fork which I view as a disadvantage, but I do think that UV data can go outside the [0, 1] range and would not be subject to color space transformation, so it should probably work. Method 2 doesn't require a fork but I think it still has range and color space problems. How does sending one float value as R, G, and B, and then in the shader reading the vertex Attribute's Fac affect the value? – slerfsterdn Nov 4 '19 at 23:55
• In method-2, first I have mapped the Float List to 0-1 range then transfer to the shader as vertex colors. Then, use the Map Range node to re-map them to their original values. Btw, what do you mean by fork? – 3DSinghVFX Nov 5 '19 at 6:21
• Ah, I see -- I overlooked the Map Range node in Method 2, but I think this method still has problems with color space transformation. As for Method 1, what I meant by "fork" is "a fork of the Animation Nodes project" -- now I'm dependent on an additional developer and additional releases. However, I installed Animation Nodes + Extra Nodes and verified that Method 1 works and so far I don't think that it can be done with vanilla Animation Nodes. Thanks for your work there. Have you written any doc about the extra nodes? If so, where can I find it? – slerfsterdn Nov 5 '19 at 10:12
• The link from where you have downloaded the AnimationNodes + Extra Nodes is the daily build means you always get updated build. I have not written any Doc but I have been making many tutorials on YouTube channel 3D Singh VFX: youtube.com/3DSinghVFX – 3DSinghVFX Nov 5 '19 at 15:38