I use PyOpengl and Python 3.
I have 50 thousand vertices. Position of each vertex could be calculated in vertex shader as
#version 300 es
uniform v_coefficients_weights[COEFFICIENTS_AMOUNT];
in vec3 v_coefficients[COEFFICIENTS_AMOUNT];
in vec3 v_initial_position;
out vec3 v_position;
void main() {
v_position = v_initial_position + v_coefficients * coefficients_weights;
}
Amount of coefficients varies between 0 and 199 — it's not a problem for me to generate 200 vertex shaders to cover each situation. I need to change position of vertices tens of thousands times per application calls as fast as it's possible, so I cannot calculate them once on start.
Though, I cannot provide arrays for each vertex because documentation says:
Attribute variables cannot be declared as arrays or structures.
I see following solutions of this issue:
- (will not work) hardcode suffices of variables names to emulate arrays:
- use vectors with names like coefficients_000, coefficients_001, ..., coefficients_199;
- use matrices to have 4 vectors in each of variable — will it be better than previous solution with vectors (maybe performance of matrices product is faster than 4 products of vectors)?
- calculate vertices positions by myself using C/NumPy;
- calculate vertices positions by myself in parallel using OpenCL;
- (will not work) store all coefficients in
uniform int v_coefficients[COEFFICIENTS_AMOUNT*VERTICES_AMOUNT]
and access needed ones according to vertex number, which will be stored inin int vertex_id
; - store coefficients in textures (proposed by @HolyBlackCat).
Are there any other solutions of my issue? Is there optimal solution in proposed above? Will I go out of memory if I will use 200 float 3-vectors for each vertex?
I imagine the solution with hardcoded indices as:
#version 300 es
uniform v_coefficients_weights[COEFFICIENTS_AMOUNT];
in vec3 v_coefficients_000;
in vec3 v_coefficients_001;
...
in vec3 v_coefficients_199;
in vec3 v_initial_position;
out vec3 v_position;
void main() {
v_position = v_initial_position
+ v_coefficients[0] * coefficients_weights_000
+ v_coefficients[1] * coefficients_weights_001
+ ...
+ v_coefficients[199] * coefficients_weights_199;
}