Decal draw calls

Hi All,

I wanted to use decals for marks on the meshes I shoot at. Since decals are meshes every shot it increases number of draw calls (there is a lot of shooting in my project). I am worried that this will eventually affect the performance. Is this something to worry about and is there any easy way around it?

Here is a playground with decal marks on the mesh.

1 Like

You can use Mesh.MergeMeshes to create a single mesh from all decals:

5 Likes

Thanks @Evgeni_Popov, this should work for draw calls. I have a machine gun with shooting rate 100ms so there can be a lot of bullets fired at a mesh. I hope merging will handle it. Do you know of any way to mitigate the effect of increasing number of verticies?

From the other side, you can dispose each decal after a short time so there will be not too much of them at any time.

1 Like

You could also look into instances: Instances | Babylon.js Documentation (babylonjs.com) or particle systems: Particle System | Babylon.js Documentation (babylonjs.com), but they won’t “stick” to the mesh automatically like the decals, you’d have to implement this behavior yourself.

There is another decal technique which is rendering the decal(s) in a texture and then when rendering the mesh we are reading from this additional texture to render the decals over the material.

One drawback is that there is an additional texture per mesh that can receive decals. There’s even more than one additional texture if you want to support bump/metallic/… textures for the decals. Another drawback is that you can’t selectively remove one decal while keeping the others: you can only remove all the decals at once (by clearing the decal texture or by removing it altogether).

Because of the one (or more) texture per mesh, it’s not usable if all your meshes can receive decals. If you are using it only for a subset (say for the characters) then it could be conceivable (if the remove-all-or-none decals is ok for you)… I’m going to make a blog post about this (with working code), but not before some weeks.

5 Likes

That sounds good for my use-case. I dont need to remove decals at all since the damage is permanent. I am looking forward to the blog post. Its nice to have feature as I have other visual feedbacks so no rush. Thanks!

Here is the other decal technique I was targeting in my last post:

1 Like

This is perfect, thanks!

2 Likes

This is a great read @Evgeni_Popov ! I’m looking forward to using this technique!

1 Like