Setting massive shader constants

Hi!
It’s great we can set array of vec4 as shader constant, but setting massive arrays this way is pretty slow. Can it be optimised somehow in the future? Is it worth to create request in github or it’s fast as it can be now?

E.g. as I can see “UpdateChecksums” is called each time, maybe it can be called only once, when all the array was updated?

How massive is massive in this context? And do you have a project or repo of this being slow?

Well, number of bones for skinning in shader can be pretty big. And problem becomes more critical with increasing number of meshes. I will send you a link to project in a private message.

1 Like

Here’s the situation - I want to animate hundreds of people. Or even thousands. If we do it through shader skinning, we need to send a large set of shader constants for each mesh - bone matrices for the current frame.

Of course, there are many nuances here. For example, each such mesh will produce separate drawcalls. And it is not a quick task to calculate matrices for thousands of bodies.
But… the road will lead to the one who walks. I guess.

1 Like

GPU skinning will eventually be supported by the engine (I’m hoping to get this plus instancing in before EOY). In the future I want to get SSBOs in as well, which should be a more generic way to get huge data sets into shaders, however it’s not as universally available

5 Likes

At the moment, good GPU animation is realized through extensions.
@Ivan_Lytkin has already done it and will tell you how exactly.

However, there is a big problem - automatic optimization of samplers. The thing is that you need to use some texture in a vertex shader, and the same texture should NOT be used in a pixel shader (right, it is not needed there). However, as soon as a texture is not used in the pixel shader, it is automatically dropped from the material. Which creates an almost unsolvable problem. :frowning:

In general, it’s not the first time I’ve encountered the fact that if I pass a bunch of textures in a material, but in the process of testing a shader I disable one of the textures in it, everything goes wrong at once, because the other textures stop hitting their assigned samplers.

3 Likes

I am also experiment with mesh-binary.
With go.set system for enemy animation take:

1)go.set
1500ms for 15s of gameplay.

2)go.set commented
261ms for 15s of gameplay.

for idx = 1, #self.cache.calculated do
	OPTIONS.index = idx
        go.set(self.url, "bones", self.cache.calculated[idx], OPTIONS)
end

Mb if we can set array of vec4 as shader constant in one call it can be faster?

go.set(self.url, "bones", self.cache.calculated, {index = 1, size = #self.cache.calculated})