My vertex positions V∈ℝ³ⁿ should be the result of multiplication of a large, dense matrix B∈ℝ³ⁿˣᵏ with a vector z∈ℝᵏ:
V = B z
In my case, k≈300, so as I understand this is far too big to store the relevant rows Bᵢ for the ith vertex as vertex attributes.
Currently, I'm computing this multiplication in the vertex shader by setting z as a uniform, by packing B into a square texture then using a texelFetch and a for-loop. Something like:
uniform int n; // number of vertices
uniform int k; // size of z
uniform int s; // size of texture square where B is packed
uniform float z[512];
uniform sampler2D tex;
in float id; // index of vertex
out vec3 v;
void main()
{
v = vec3(0,0,0);
for(int j = 0;j < k; j++)
{
int index = int(id)*k+j;
int si = index % s;
int sj = int((index - si)/s);
v = v + texelFetch(tex,ivec2(si,sj),0).xyz*z[j];
}
On my MacBook Pro M1, this works reasonably well for n≈50,000 and k≈100. Increasing either, I start to get dropped frames.
Is doing this in a vertex shader a good idea?
My computation is similar to blendshapes. How are those typically computed on the GPU?
Ideally, I'd like to stick to opengl. If not, is there an opencl or some other way to best achieve this?