Search code examples
androidlibgdx

Libgdx decalbatch particles alpha


I have a decalbatch and some decal in it. Lets say 50. I have a groupstrategy and a cuszom shader.

My probleme is when I do something in that shader than my all particles responding to that. So when I change the alpha on the shader than it changes on all particle decal.

How can I change one by one on that shader? Thanks


Solution

  • Shader uniforms and constants affect everything in the batch.

    If you want to continue doing this with shader uniforms, you could flush the batch and then submit more decals each time you change the value of the parameter, but you would need to keep them sorted for transparent decals to look correct. You could do this by creating a GroupStrategy that sorts all the decals and then assigns them groups in ascending order from far to near, creating a new group each time the affected parameter is different.

    The above has the potential to cause a lot of batch flushing which could cause a performance hit. An alternative is to use the existing vertex attributes to encode your data per decal. However, the only one that's really available is vertex color, since you need the texture coordinates and position attributes as is. So you can only put data into the color of the decal, if you aren't using color for tinting purposes.

    A third possibility is to use a library that allows more customization than DecalBatch, such as FlexBatch. FlexBatch can be used sort of like a DecalBatch, but you can define whatever vertex attributes you need.