Scene Foliage loading, and saving performance

So, I found this issue in my game, And this is more of a “Trying to understand how it works” More than anything. I have had long loading times for the main scene (A large, open world scene) and i always figured it had something to do with the terrain size and some initializing scripts. However, I found that loading times are minimal once I get rid of the foliage.

Now, I will say, I just did a quick full map foliage tool. I know that is very lazy and counterproductive to performance, but i was just going to have something working and deal with it later.

Before removing the foliage, there were around a few hundred thousand (maybe 400k?, short/medium culling distance, around 20000 i think?) instances of JUST a grass object that i have. It’s just a few planes with a really low resolution texture applied to it. Like i said, i was just going to have something that worked and then clean it up later. There were a few things that came with this # of foliage instances.

  • File Size: This many foliage instances made my scene file go from 1MB to ~1.2GB
  • Loading time: The scene now took anywhere from 17-33 seconds to load. Time did not change when built (This is what led me to think it was the initializing scripts)
  • Saving: With the foliage, saving took probably about the same time as loading, i did not check however.
  • Without the foliage: Loading time is under 150ms, size is ~1MB, save is back to minimal

Like I said, this is more of a “How does it work” question, so i can see if i can think of a workaround if possible.

Foliage is saved as raw bytes encoded into Base64 isndie json format of the scene file. This processing used to be rather fast but maybe we need to optimize it. I’ll add a task to the roadmap to investigate it

Okay, after looking at the numbers, i think my foliage was worse than what i listed.

at 68 bits (not bytes) per instance i would have had around 2mil. Whoops, that’s gross.

I’m not sure if this makes it something you can ignore now or not. Sorry, i should have taken the numbers down before deleting the foliage.

Ah that makes sense. I think we need some runtime-generated foliage over terrain/meshes via some shaders that would be a better fit for grass that’s more dense.

That would be awesome if it ever gets added. I’ve seen a lot of custom implementations in other engines and they always look so cool, but i for one do NOT know enough about shaders to do that