• 2D
  • Performance for 2dCanvas, sky background (small vs large)

I want to create a background sky with hundred of stars. The stars position is dynamic, and they also blink from time to time, so I need to refresh the background.

I have 2 options: 1. Create ONE large canvas (screen size), and manually draw each star. Update the whole canvas for blinking. 2. Create a small Node/Scene, each one representing one star. Update only the blinking star.

My question is, when you create a Canvas, does it creates a video texture or an memory buffer the size of the canvas ? When we refresh, does the whole canvas size is copied ? Does Godot handles well hundred of 2d nodes ?

thanks for your help, this is my first project in Godot, but I have already developed different games.

Hi,

The best from performance point of view would be probably to use MultiMeshInstance2D to draw hundred of stars each frame.

If you want to make them blinking by rotation and scale that would be possible by transform, and if you need to use animation, that would be probably also possible by custom data + custom shader.

I don't know how it would be compared to drawing on some buffer or texture though. If you would update only stars you need without erasing whole texture maybe that would work better, but that depends how often your stars will change, because if too frequently then it will be almost the same as drawing them each frame.

I don't know much about Godot 2D drawing, but I know viewport may be used as buffer/texture if that helps. I guess by default Godot draw to back buffer.

7 days later

An alternative is to use particles, but GPU-based Particles are limited to the GLES3 backend. You can only use CPUParticles when using the GLES2 backend.

Good idea for the particles, but I mainly target android device, and I have understand that GLES 3 should not be used on android, if I am right.

As @Calinou said, you can use CPU particles which should work with both GLES 2 & 3. CPU particles should be able to handle hundreds just fine it's thousands, especially tens or hundreds of thousands when CPU particles will become obviously too slow to handle it all.