Hello and welcome!
There is an example with SPS and dynamic texture labeling which may be useful - https://playground.babylonjs.com/#A9K31I#3
(have a look at texture number - there are only 2 textures at all)
Before breaking down this merging of 2 PG’s let’s understand why the original was slow. You were smart to create instances of the original box, but then you go and create 10k plane meshs which defeats the purpose of using instances. Then we get into the dynamic texture and material. In my mind also creating 10k of these would also be quite costly. The way I understand it is we need 1 giant texture which we will then index into in with different UV offsets. Since we can’t do that with instances, the SPS is the way to go.
To build one giant string (since we can only have 1 text draw call) I create a single string which I keep adding to in line 67. (I’m starting to think maybe and array would be better like the SPS demo)
Now in this position function is where things will differ. I’m still trying to understand the uv offset math from the SPS, but once the correct numbers are in place we should be all set. I commented the area where the UV offset needs to be calculated.
Let’s keep it going! @labris Thank you for the great start!
Thanks everybody for all the examples and directions given! They really helped me!
The SPS is really powerful! It was able to render thousands of boxes with high performance!
I continued @msDestiny14 edit in the playground (https://playground.babylonjs.com/#Y13S7S#20) to change how the labels are drawn, allowing to use different color for each label/box, and to support multiple materials (in case the texture size limit is reached).
I just couldn’t figure out how to set the texture just for the top face of the cube particle, is it possible? Does a individual particle have a faceUV property like the normal meshes such as shown in the doc examples (Map Materials to Individual Mesh Faces | Babylon.js Documentation)?
About the performance, with 40k boxes (200 x 200) it is very fluid! But if I set to 400x400 I think it’s taking too much memory for the textures and the playground is crashing.
This is way beyond what I’ll actually need in the final product (even 10k cubes is more than enough), but I’m just wondering if there is a way to go even further with this approach.