I have a game with 30-50 GO objects on screen. Each has two sprites a character and a hover thing. The hover thing can be active the closer the cursor is to the character GO.
But setting the alpha for the hover for all of these with sprite.set_constant adds a ton of drawcalls!! How can I smoothly animate alpha of these sprites without the performance impact?
Until we have custom vertex formats, it’s going to be tricky.
One idea is ofc to have these objects in the gui world.
Another idea might be to encode the alpha in the z component of the position and use that as the alpha modifier. E.g. when the cursor is closer to the object, the z increases, and when it’s further away, the z decreases. And having a known range between e.g. [0.4, 0.5], you can then easily set the alpha in the shader.
I see that Defold generates vertex buffers every frame to batch the draw of sprites and meshes/models with materials of the “World” vertex space. The different values of uniform constants break these batches.
I think that it will be useful to have material constants that Defold adds as attributes of vertices. Yes, the engine will generate a bit more data to draw sprites. But the different alpha values are not going to break batches anymore!
So, those new material constants can have float and vec4 data types. It’ll be enough.
How can look a modified sprite.vp/sprite.fp, without tint constant:
@Pkeod: I would suggest to quantize the alpha somehow and to prepare different sprites for each alpha value. Of course this could be expensive in texture space if the sprite is quite large…
That’s a good idea for overlays. What we ended up doing to reduce drawcalls is very aggressively disabling the extra sprite components since alpha at 0 still adds a drawcall but disabled component does not. For some things (that were previously set dynamically) we did prebake the alpha into the sprite too instead of manually setting it at runtime.