2
votes

I am trying to pass an array of point lights from an object class to the vertex shader in OpenGL ES 2.0 on Android.

The point lights are stored as a float[] array and the shader would ideally read the floats as a vec4[] array.

The float[] can be passed to the vertex shader by calling glUniform4fv(...floatArray, 0) and is declared in the vertex shader as uniform vec4 u_PointLights[990] but this is extremely slow.

I'm trying to get the floats into GPU memory; first thought was a VBO but after binding the data and passing it to the shader, I can only read a single vec4 and not an array (i.e. cannot declare attribute vec4[] a_PointLights).

What is the best way to get second vec4[] into the shader?

Thanks,

Richard

1
What part of it is extremely slow, the transfer to the shader uniform or just the actual rendering? You might have some slowdown in your shader if theres large complicated for loops and if statements (branching is SLOW in shaders) Failing that a uniform buffer object might be more performant for transfering large arrays, but I don't think it should be too slow sending your array to the uniform.WearyWanderer
I don't think uniform buffer objects are available on ES 2, sadly, though they arrive with ES 3. But second the query about the shaders themselves: how are you processing the data? Conditionality and random access are ideally to be avoided in shaders; attacking one like a conventional imperative program doesn't usually lead to good results.Tommy
Also, how often are you calling glUniform4fv? Once per frame?Tommy
Tommy - Yes, once per frame. WearyWanderer - the point lights are dynamic (sourced from a particle generator) so the vertex shader compares the distance from every point in the buffer against every vertex in each visible triangle.Richard Klassen

1 Answers

1
votes

In OpenGL ES 2.0 you can't do anything else really - either client-side uniforms or attributes, both of which are going to be somewhat limited.

In OpenGL ES 3.0 you could use a Uniform Buffer Object, but note that very large arrays of uniforms are always going to be relatively expensive, especially on mobile.