NcStudios / NcEngine

NcEngine: 3D game engine written in modern C++ and Vulkan
https://ncstudios.itch.io/
MIT License
36 stars 2 forks source link

Particle instancing and alpha sorting #645

Closed McCallisterRomer closed 1 month ago

McCallisterRomer commented 1 month ago

Requires a ~1 line change once #644 is merged.

resolves #619

Adding instancing for particles

I followed the existing convention of preallocating based on a config value, however I didn't really want to throw if we exceed that size. Instead, I'm just not rendering particles beyond the specified maximum - might be worth revisiting in the future. It would be nice to be able to reallocate the buffer for the current frame without blocking on other frames in flight, but I'm not sure we have that capability.

Adding approximate sorting for particles

I tried doing a full sort, but its too expensive. We either need to have more material options so we can skip sorting some things or move everything to the gpu. I'm down to dig into either.

Instead, we sort each system back to front based on its position the last time it emitted any particles. There are cases where this gets weird, but is good enough a lot of the time. Thanks for the suggestion!

I also disabled depth writes in ParticleTechnique so particles don't occlude other particles. This greatly hides the fact that the sort isn't perfect. Some particles can still be rendered in the wrong order, but you don't get giant, blocky artifacts.