mob-sakai / SoftMaskForUGUI

Enhance Unity UI (uGUI) with advanced soft-masking features to create more visually appealing effects!
https://github.com/mob-sakai/SoftMaskForUGUI
MIT License
1.97k stars 261 forks source link

UI batching is broken for SoftMaskable elements #76

Closed Arkarit closed 4 years ago

Arkarit commented 4 years ago

Describe the bug SoftMaskable applies a cloned, modified unique material to each Graphic it belongs to. This breaks UI batching for all SoftMaskable elements completely.

To Reproduce Steps to reproduce the behavior:

  1. Create a parent container with a SoftMask
  2. Add ~20 of TextMeshPro child elements with SoftMaskable
  3. Play
  4. Open and enable the Frame Debugger
  5. In the frame debugger, examine the draw calls: Each SoftMaskable child element issues an own draw call!

Also, the issue can be examined in the Profiler (UI/Render, "Batch breaking reason: Different material instance")

Environment (please complete the following information):

Additional context The reason seems to be in SoftMaskable.GetModifiedMaterial(). For testing purposes, I simply added a dict to store already modified materials, which seems to fix the issue at first glance (but as I am not too deep into it, some additional checks might be necessary). See attached patch. SoftMaskForUGUI-test-fix-batching.txt

Arkarit commented 4 years ago

As more or less expected, the preliminary fix was not sufficient; an additional hash by SoftMask is necessary (see pull request)

mob-sakai commented 4 years ago

@Arkarit Thank you for reporting! I'm planning to introduce the material cache used by UIEffect.

github-actions[bot] commented 4 years ago

:tada: This issue has been resolved in version 1.0.0-preview.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: