PDA

View Full Version : A vector of arbitrary length as a uniform



nbdspcl
04-17-2014, 12:37 PM
What is the efficient way to provide a vector with data of arbitrary length into a shader from which the shader can read values that are not unique for each vertex? This probably can be done with uniforms, but what is the way to use a vector of arbitrary length as a uniform?

P.S. There are shader storage blocks which can be probably used for for that kind of task, but I'd like first to try to get by with uniforms.

mhagain
04-17-2014, 03:42 PM
For absolutely arbitrary length you can't really do it as there is a limited amount of uniform storage space, which varies according to hardware and driver. You'll need to query what is supported on any given machine and set a maximum based on that.

Since you mention that you've a preference to get by with just uniforms I'm assuming that you're aiming for relatively low hardware specs. If you're not averse to raising them just a little bit, vertex textures may be a better option. This sets your minimum hardware requirements to SM3 (or about GL2.1 level) which essentially guarantees you support for 4 vertex texture slots, 2048x2048 textures and non-power-of-two textures (compare to 256 vertex shader constant registers - which OpenGL uses for uniforms).

nbdspcl
04-17-2014, 04:27 PM
mhagain

I supposed that since Shader Storage Blocks have both read and write access from shaders, and uniforms are read only, using uniforms maybe somewhat faster. But as it seems, vectors of variable length cannot be declared as uniforms (if a vector is declared without specifying its size, it can only be indexed with constant expressions which are known at compilation time anyways). The question generally was about if there is a commonly used method to pass variably sized data to shaders. As I understand, there are two ways for this: through Shader Storage Blocks (SSB) and using the textures buffers as a container for data. It seems that SSB are easier for using, and if using textures for passing data is not significantly faster, then SSB seem like the preferable way?