Note : I decided to drop ShaderForge for my specific needs and have zero experience with actual shader coding (except for having fun with ShaderEditor on my phone).
I’m on 5.5 and I’m trying to send an array of floats to my shader. I read that you cannot declare an array under the shader’s properties and people suggested using the recently introduced Material.GetFloatArray.
My array looks like this:
Uniform float myArray[255];
The thing is… it always returns null.
On the other hand, GetFloat works as long as the float is declared in the shader properties (and in the subshader).
I also noticed that using SetFloatArray and then GetFloatArray always works… But I can pass any string with SetFloatArray, which means it’s allocating new resources rather than actually finding my array.
Like I said, I can read and set a single float just fine, but that’s because I can declare it under properties!
I tried using MaterialPropertyBlock too but it doesn’t change anything (and I’m not 100% sure what this does).
You can not pass any string to SetFloatArray/GetFloatArray. It is the property name, therefore it needs to match the uniform name, which is in your case “myArray”.
What I meant with my other statement is the following :
float[ ] floatArray = new float[2] {1f, 2f};
float[ ] floatArrayFromShader = MyMaterial.GetFloatArray(“myArray”) ; //returns null
MyMaterial.SetFloatArray(“randomrandom”, floatArray) ;
floatArrayFromShader = MyMaterial. GetFloatArray(“randomrandom”); //returns 1 and 2.
Also, I tried using the other syntax to get and unique ID from a property, but it doesn’t change (the returned ID increases by 1 if the string I’m passing has never been passed before, or it keeps returning the same id… Even between “plays”). In any case, the ID doesn’t allow me to retrieve the float array.
Sorry if the syntax is sketchy, but I’m on my phone!
EDIT: I noticed that despite the fact that MyMaterial.GetFloatArray(“myArray”) always returns null; if I use myArray in my code, and update it using SetFloatArray, it does work. I just can’t read the contents (and for what I want to do it’s not important).