mkwozniak / mangofogunity

MangoFog is a 2D/3D mesh rendered fog of war system for the Unity Engine. It's based off TasharenFogOfWar except it can use a MeshRenderer, SpriteRenderer, or render directly to the GPU. Plus several other features.
MIT License
66 stars 4 forks source link

[PERFORMANCE] It's not optimized for RTS mobile games?! #2

Open CODEHUBHQ opened 1 month ago

CODEHUBHQ commented 1 month ago

If you try using this package for rts units and buildings, in a 2D unity game. You'll get performance issue where cpu usage is very high, and sometime the game will terminate process due to cpu high usage.

any ideas how to optimize this package for mobile?!!

mkwozniak commented 1 month ago

Unfortunately, out of the box, I don't see this package being very fit for mobile usage. I'm not sure what exactly is causing the performance drawback on mobile devices. It might be the shader, or it might be the actual fog thread. I don't have a chance at the moment to do any bench-marking or profiling for mobile devices. If you have any data on what's eating the CPU, I would greatly appreciate it, and I will update the package to optimize for that.

In general, there are many things in mango fog that are done a bit sloppy in terms of optimization.

I was planning to write a lightweight 2D only version of mango fog eventually. Seeing as there are use cases for mobile, I think I'll get on that sooner rather than later. In all honesty, I've even been wanting to do a full re-write of mango fog overall. I just haven't had the time nor the motivation.

Apologies for the disappointment. When I find the time, I'll release a 2D (hopefully much less resource intensive) package for mango fog.

For now, all I can do is maybe suggest a few things that might help. If not, you may have to find another solution to your FoW system for mobile devices.

  1. Mango fog manually iterates each revealer, then updates them. If you're dealing with hundreds of units, like in an RTS, this may prove to be slow. MangoFogInstance -> UpdateRevealers (ms)

  2. The same process happens when updating the buffer. MangoFogChunk -> UpdateBuffer()

  3. At a quick glance, there are a few micro optimizations that can be done from what I can see. For example in UpdateBuffer(), float worldToTex is calculated every time the buffer updates, but doesn't need to be.

  4. There is some logic that checks what perspective you're using (2D or 3D). If you're using 2D only, there's no need for those checks.