Passing variable length arrays to shaders

I’d like to write a shader to animate a system of particles. To work, I’d need to pass extra data per vertex. The problem is, the amount of data will change quite a bit depending on the current state of the program. Each vertex will need a set of n 4x4 matricies and a set of n floats to weight the matricies. The shader will then computer a weighted sum for each vertex to determine it’s final position.

Unfortuantley, I have no idea how to pass this information, as I wil not know in advance what n is. (Inface, n will likely change over the course of hte program). As far as I can tell, OpenGL SL will only accept fixed length information. I suppose I could try to cram everything into a texture and access it through a sampler, but this will be resolution and tricky to code.

Is there any way I can pass arbitrary data to a shader?

You can (ab)use the texcoord arrays for this.

You can send 4 floats per texture-unit per vertex.
With N texture-units, it is possible to send N/4 4x4 matrices per vertex.
So N has a pretty low maximum with this approach.

I’m not sure how many vertex-attributes you can send with each vertex, but combining the texture-units and vertex-attributes will get you quite far.

If N is not changing between render-calls, you can make a bunch of different shaders for each N.

However!
It sounds like this is massive overkill for a particle-engine, so you better be sure you need it, or invent something better.