unitycoder / UnityMobilePaint

Public repository for MobilePaint issues & requests
https://www.assetstore.unity3d.com/en/#!/content/19803?aid=1101lGti
MIT License
49 stars 16 forks source link

flood fill should be optimized #41

Open unitycoder opened 4 years ago

unitycoder commented 4 years ago

doesnt look good: image

jaelacaxa commented 4 years ago

Hi ! any idea what to do to improve ?

unitycoder commented 4 years ago

some ideas: CompareThreshold can be probably improved (and inlined) to something simpler and branchless, https://github.com/unitycoder/UnityMobilePaint/blob/master/Assets/MobilePaint/Scripts/MobilePaint.cs#L1813

looks like queue generates garbage, should use something faster. see comments here for possibly faster flood fills https://unitycoder.com/blog/2012/10/10/flood-fill-algorithm/ or maybe queue without allocations https://forum.unity.com/threads/thread-safe-queue-with-no-allocations.308842/#post-2686958

or whole floodfill operation could be done in another thread (pure thread or unity jobs..) to fill the array, then just trigger texture update on mainthread once calculation is done.