Shader Arrays Setting their lengths

Not 100% sure if you would classify this as a bug. But its has caused me no end of problems until I tracked down the root cause.

I created a shader which as it was intended to be a data driven shader had an array to hold data. This was defined in the shader code as vec4 Data[100].

However most of it was intended to be used as more data was added to the model via the modeller. When the shader is constructed you Use setVector4(“Data[#]”, vector4(x,y,z,w)); or whatever. What I found is that if you do not pad the set the data for the entire array perhaps padding out with vector4(0,0,0,0)s or some such when it compiles it pays no attention to the array size set in the code, but it is instead fixed at however many values you set. Later when you add values lengthening the data you want to send they are not recognised by the shader. Because the array is not defined as being that long.

Now this could be intended this way to prevent things not being initialised properly, but I have not encountered a warning regarding this and it has caused me several days of trouble trying to work out why the shader was not working.

Would you be able to setup a small repro of the problem?

Note that if you declare a vec4 array in the shader, you probably want to use setArray4(data, array) instead of setVector4. I don’t think setVector4("data[X]", vec4) is meant to be supported in this case…

Will try it out. The setVector4(“Data[0]”, vec4) works fine though. However perhaps the problem I have with the array not extending into the declared area is because of this so I will check it out.

Thanks for the info. I will put together a little project to test it out.

Hmm. I have done the repo and both versions seems to work fine. So it must just be some other issue with my code or something not updating correctly. I apologise and in future will try the repo thing first.

1 Like