mob-sakai / UIEffect

UIEffect is an effect component for uGUI element in Unity. Let's decorate your UI with effects!
https://github.com/mob-sakai/UIEffect
MIT License
5.62k stars 773 forks source link

Advanced Detailed Blur on Android : low framerate #196

Open FXI-UCL opened 4 years ago

FXI-UCL commented 4 years ago

Describe the bug Using Advanced Blur and Detail Blur mode on an Android device makes the game really slow. Updates takes several seconds.

To Reproduce Steps to reproduce the behavior:

  1. Create a basic 2D UI project
  2. Add a Button, configure it so it changes color when clicked and released
  3. Add UI Effect and UI Shadow to configure a "Soft shadow" usage. Use "Detail blur" mode and tick "Advanced Blur".
  4. Build and Run on an Android Device. See refresh rate when clicking on the button.

Environment

Additional context I was told it was working fine some months ago, then an Android update occurred, and suddenly the app was awfully slow when run. It seems the app was not rebuilt in the meantime. Only an Android update was done between the time it was working fine and smooth and now that it is too slow.

I've tried building a single project, like indicated in the "Reproduce" section, and indeed it is desperately slow with these settings. Cannot personally confirm it was working "before", only was told by a colleague.

Edit : it seems the issue comes from the "Advanced Blur" option, as it is also very slow in Advanced, Medium Blur, but runs fine in Detail no-Advanced Blur.

FXI-UCL commented 4 years ago

I dug into the Shaders. Bottleneck comes from the function fixed4 Tex2DBlurring (sampler2D tex, half2 texcood, half2 blur, half4 mask) line 75 in file UI-Effect.cginc (when not using TextMeshPro).

Computation differs whether the Advanced Blur option is used or not, but it makes no real difference in term of performance. Instead, the size of the array used to compute the blur increases when the Advanced Blur is used. When the size of the array is too big (9 on my Samsung Galaxy Note 3), the app gets unresponsive, even when using the non-Advanced computation (tests done by c/p Advanced option arrays to non-Advanced Define).

So I suppose the only way of improving that is to use a computation with a complexity less than n². And declare _KERNELSIZE/2 as a variable outside the loops to avoid computing it each time, but that's not a big gain.

mob-sakai commented 4 years ago

Hi @FXI-UCL

Thank you for your reporting! This issue is very difficult... X(

mob-sakai commented 4 years ago

Hmm, This issue may be solved by using the pre-write buffer used in SoftMaskForUGUI. Not yet tested.

flarive commented 4 years ago

Hi... I have the same issue, on quite big UI Image (such as 256x256 or more), the framerate (FPS) is divided by two when UI-Effect (Fill, Detail Blur, Advanced shadow) + UIShadow is drawn... On little images (less than 128x128) the framerate is not impacted when the glow is displayed...

Can you try if the usage of pre-write buffer you told above can fix this performance issue ?

Your glow effect is one of the best i was able to find in Unity, really great work :)

fuatcoskun commented 3 years ago

Any update on that?