GLSL: How to handle lots of inputs

I have a shader in mind that would call for a fair few inputs, I think–specifically, I’m envisaging eighty sets of inputs, with each set containing the same handful of individual inputs (with potentially-differing values, of course). It may be worth noting that each vertex would “have interest” in only one set, determined by an unchanging index specified in the vertex (likely via vertex-colours).

Now, I could likely do this “by hand”: in my shaders, specify eighty * however-many individual inputs, and then call “setShaderInput” for each.

But that seems like a very tiresome way of doing things, and calls for a lot of calls to “setShaderInput”. Further, it seems like it might be more efficient to have each vertex only access the inputs that concern it, rather than examining each and every input and using a numeric selector or set of selectors to discard the irrelevant data.

For reference, I’m using “#version 130” in my shaders. (And, for now at least, don’t intend to switch to a later version.)

So, is there a good way of doing this, perhaps?

For starters, you can use setShaderInputs(a=1, b=2) to set multiple shader inputs at once, it is more efficient, or setShaderInputs(**somedict).

One method that is used by eg. RenderPipeline is to use an array input for many values, and then pass a PTA to the setShaderInput call, after which you can then modify values in the PTA without an explicit setShaderInput call to update them. This would also allow you to use the index value specified on the vertex level to index into the appropriate set. However, this might make shader code less readable.

The most efficient way to update many inputs is a Uniform Buffer Object, but that’s introduced in OpenGL 3.1, and you are targeting OpenGL 3.0 — and besides, they are not yet fully exposed in Panda, although I could work on it for anyone who wanted to use them.

Ah, thank you–that array-input sounds like just the thing! :slight_smile:

(And I didn’t know about those options in setting shader-inputs–thank you for mentioning those!)