Can instance drawing support different colors?

In this thread, someone explained how to implement instance drawing with different colors of the same geometry.

I’m trying to use solid particle system to draw the same thing but the performance is not as good as the thread above. In Babylonjs can instance drawing support different colors as well, or can solid particle system support instance drawing? Thanks!

1 Like

@johannhuang sorry for the time taken to get a reply. Something like this ? From Use the Solid Particle System - Babylon.js Documentation

The picking is not as good. However this is probably due to the picking method used and could be changed to ray tracing as mention in this post Pick a particle in SolidParticleSystem

1 Like

@JohnK Thanks for your answer! I think solid particle system is great for static mesh, but in my case all geometries need to move, that’s why the performance drops because it needs to loop through every vertex to apply the transformation. With instancing the workload could be delegate to GPU that’s why I would like to go that route

is this one more acceptable ?

1 Like

same with rotating particles, updated by bunches of nb / 4 each frame here :

picking a bit faster :

1 Like

anyway, 2^16 objects is really a big number …
are there as many objects in your 3JS demo also ? I couldn’t see it

[EDIT] just checked : the 3JS demo has only 2000 objects, not 65000… nothing that the SPS couldn’t handle quite easily

same scale than the 3JS demo : 2000 boxes all updated each frame

1 Like

@jerome Thanks for the reply! I just checked the source code of this demo

It is indeed 2^16 = 65535 particles. Not being picky here, I just wish solid particle system can achieve this kind of performance!

Ok, I looked at the wrong example…
I quickly read the 3JS code. Actually, they test some ray / mesh (instance) intersection, it is to say a standard BBox intersection what is faster than iterating a global loop on all the SPS mesh facets.
By tweaking a bit the current SPS, I get this with a rollover :
what is obviously slower because each facet is tested.

Way faster with picking only :

Imho, the right approach, if using a SPS, would be the one I described in the post linked by JohnK : to enable the particle intersection to get their BBox computed, then to check the ray intersection with this BBox. This requires to implement such a thing.

The other approach would be to do like in the 3JS demo : use instances instead of a SPS and just check the ray intersection on these instances. It should be at least as fast as the 3JS demo.

another attempt with animation on picked particles with still an acceptable FPS rate :


Thank you for the optimization, @jerome ! As you said I think using instance is still the most performant solution for both rendering and picking. Just curious, is there any reasons solid particle system is not implemented in this way? (maybe due to backward compatibility with WebGL1?) @Deltakosh

The SPS has nothing to do with instances. It’s a different approach for different needs (sometimes the sames though).
The SPS is a big updatable (or not) mesh providing an API to manage its subparts called the solid particles. It benefits all the properties of the standard mesh by default : picking, texturing, lighting, alpha-sorting, etc that can sometimes miss on other particle systems. The counterpart is that everything is done CPU side, as optimized as possible (hope so). Its performance is directly related to the global number of vertices and to the update frequency.
Instances are drawn by the GPU with no extra draw call, but they still require each of their WorldMartrices to be computed first CPU side.
In general, with low poly objects, even very numerous (thousands, dozen thousands), the SPS can beat the Instance architecture. When going to more numerous objects or dealing with higher poly objects, Instances should be faster.

The same way, dealing with 2D objects, the standard particle system (and the GPU even more) is always faster than the SPS when going to very high numbers of particles (> 20K). The SPS can compete easily with it under 15K 2D particles and bring then extra features.

Just a matter of choosing the right tool according to the current need …

1 Like