I’m trying to send arrays of colors and floats to my PBR Shader from a script and access them in Shader Graph:
// From Script....
// no an array but using this to access the arrays below...
material.setInt("baseColorsCount", baseColors.Length);
// Array
material.SetColorArray ("baseColors", baseColors);
material.SetFloatArray ("baseStartHeights", baseStartHeights);
But what property do I select in order to access the values in the graph?
I haven’t been using arrays with Shader Graph. I can only think about Texture2D Array.
Other than that, each property besides their name, have reference. This is what you want, to access properties from the script.
You need set it, if you like, to be more meaningful and use it in material.SetFloat, GetFloat etc.
Something like that ( you got different version of Shader Graph, so it may look a bit different).
In this case, you use “_PrimaryColor”. I also suggest to cache string into int and use shader ID, rather string.
and I’m trying to create the following shader but in Shader Graph, but as you can see, the shader uses two arrays and I have no idea how to get around this and keep using Shader Graph:
So far I managed to get “heightPercent” working in my shader. I could even make a custom function and get it over with, but those arrays are confusing me.
In case someone else comes across this I thought I’d add an option.
In some cases you can use a Gradient as a color array. Setting the mode to fixed makes it more obvious. Use the Sample Gradient node to look up the color you want.
The Sample Gradient node uses a 0 to 1 index though so there’s a little bit of math if you using integers.