# How to use shaders in a system with a variable amount of inputs?

So I’m making an electric field simulation in which the user can dynamically create charges through a mouse click.Currently, the electric field is just calculated on the CPU with a pretty bad algorithm on every cell within a grid.https://i.imgur.com/BFtnkou.gifv

To illustrate the equipotential lines, I have made a shader that computes the potential according to the charge position and q(electric charge).https://i.imgur.com/hipLStv.gifv

This is the shader code for glslViewer:

[code=glsl]#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
#define PI 3.14159265

void main( void ) {
vec2 position = ( gl_FragCoord.xy / u_resolution.y );
vec2 mousePos = u_mouse/u_resolution.y;
vec2 r = position - mousePos;
vec2 r2 = position - vec2(0.5, 0.5);
float potential = 0.125/length® - 0.125/length(r2);
potential = clamp(potential, -1.0, 1.0);
float cutoff = sin(2.0PI10.0potential);
cutoff = smoothstep(1.0,0.0, 0.5
abs(cutoff)/fwidth(cutoff));
//Maps negative potential to blue
// and positive potential to red
gl_FragColor = cutoff * vec4(potential, 0.0, -potential, 1.0);
}

``````

[i]Quick edit:[/i] I know I'll have to modify the shader, obviously.
My problem is: how do I use this shader with a dynamic amount of charges? One of the GLSL paradigms is that the shader can't just have a variable amount of inputs--therefore, I can't just throw in an array of vec3 to represent q and position of every charge and hope the shader knows how to sum up the electric potential without knowing the array size [i]a priori[/i].

My two cents on solving the problem:
[ul]
[li]Use a floating point texture FPT.