Soft Mask - A replacement of Unity UI Mask with alpha support

Hello! My package Soft Mask has just been published on Asset Store. In this thread I will answer your questions about it and provide support.

What is Soft Mask?

Soft Mask is an UI component that masks child elements. It works in a very similar way to standard Unity’s UI Mask but supports gradients and semi-transparency. Non-intrusive usage is the key feature of Soft Mask. You don’t have to assign any materials or shaders to GameObjects nor modify the scene in any other way.

This video shows how to use Soft Mask in Editor:

Features

  • Easy to use: just drop it on the Game Object in the same way as Unity’s standard Mask.

  • Support of Image, RawImage, Sprite or Texture.

  • Raycast filtering: a rectangular or per-pixel test of input events.

  • Separation of a mask from the masked hierarchy.

  • Flexible adjustment of mask color channels: black and white images, images with transparency or fine-tuned weights for each color channel.

  • Can be easily supported by custom shaders.

  • Real-time updates: move, scale, rotate and change the image of the mask in realtime.

Links

Asset Store | WebGL Demo | Documentation

4 Likes

$30? No way.

8 Likes

DawidMoza
Thanks for your interest! Sorry that the price isn’t acceptable for you. And good luck with your asset!

1 Like

Does it support sprite atlases?

Yes, but with some limitations. The mask’s sprite can be placed into an atlas, but it should be rectangle packed. Tight meshes aren’t supported for the mask. As to masked elements, they can use any sprites you can with regular Unity UI. Also, you can check out the section Limitations in the documentation, which lists all such points.

I recently found that there is an old bug in Unity due to which the InputField selection and the caret aren’t masked by Mask and Rect Mask 2D. Soft Mask doesn’t work in such case too.

The bug attracted me because I have been studying Unity UI code for some time. After some research of how InputField draws the selection and the caret, I’ve come up with a workaround. It seems that it works, but I’m not 100% sure that is ‘production-ready’. The workaround works for Mask, Rect Mask 2D and, of course, Soft Mask :slight_smile:

hi
in my project,mask not work in my mobile(htc one) correctly
but works correctly in my another devices and editor
i can’t find a solution for this…
your asset can help me?
thanks

@mahdijj
Hi!
If the issue is related to the stencil buffer then, yes, Soft Mask may help here. But I can’t say surely because I don’t know what is the cause of the problem.

You can try this demo APK. It’s the same demo as I provide on the Asset Store page. It has a toggle to switch between standard Mask and Soft Mask. You can check whether this demo a) has the issue on your device with a standard Mask and b) has no such issue with a Soft Mask.

Anyway, if you purchase Soft Mask and it will not help with your problem, I’ll refund you without questions.

Please note that the demo isn’t adopted for mobile, for example, there is no convenient way to close it (you should use the task manager), and everything may be too small for a mobile screen.

i don’t know why , but your demo apk is not installed in my htc one

Do you have the option ‘Unknown sources’ enabled on your device? On my phone, it’s located in Settings / Security / Unknown sources. Also, it’s possible that new Android versions have other options that block installing of an unknown APKs.

If this doesn’t help, I can try to build an APK for the API version of your phone, if you tell me it.

api version is 21

Ok, here is the demo built in Unity 5.5.1 (the previous one was 5.3.x) and with the minimum API level 21.

thanks for your good asset, my problem is solved with your asset.

1 Like

That’s great that you solved your problem! And thanks for a good feedback!

I’m very pleased to say that version 1.1 has just been submitted to review! This update introduces separated mask mode, significant CPU performance improvement, and several bug fixes. Also, samples have been reworked a bit.

The updated documentation and demo are already available. The updated package should become available soon.

Here are full release notes:

Improvements

  • Added the Separate Mask parameter that allows to separate mask from the masked elements. The sample 04-CustomShaders has been reworked to show this feature in use.
  • Optimized real-time performance, especially on huge hierarchies. Soft Mask now has almost the same performance cost on CPU as standard Unity Mask (which is very close to zero).
  • Improved mapping of Sliced and Tiled masks in the case when the central part is collapsed.
  • Reworked samples: they now demonstrate more features of Soft Mask and also look better.

Bug fixes

  • Fixed a bug causing Soft Mask to work incorrectly on nested canvases. The partial consequence of this was the inability to use Soft Mask in a standard Dropdown control which uses nested canvas for the drop down list. Now it is possible.
  • Fixed a bug preventing Soft Mask from updating after moving it from one canvas to another.
  • Fixed a bug preventing rendering of the child elements when a mask used a sprite with one of its borders set to zero in Sliced or Tiled mode.

UPDATE Soft Mask 1.1 is already available on Asset Store.

1 Like

Working on update 1.1, I’ve found some bugs in Unity. I want to inform you about them because you can encounter them while using Soft Mask too.

  • An Image is displayed incorrectly in the Tiled mode when in uses Sprite with Tight mesh type. Sprite’s borders are drawn a bit stretched. Here is how it looks like:
    2976695--221256--TiledSpritesBug.png
    The left image is Sliced, the right one is Tiled. As you see, the content is masked equally on the left and on the right sides, but backgrounds are drawn differently. When I found it, I, of course, thought that it’s my bug, but, surprisingly, that was not the case :slight_smile: The bug is published on Issue Tracker.

  • The following warning is shown even when the shader code is disabled by preprocessor:

  • Use of UNITY_MATRIX_MVP is detected. To transform a vertex into clip space, consider using UnityObjectToClipPos for better performance.*
    This warning is added in Unity 5.6, so, if you use Soft Mask in 5.6, you may see this message. It’s bad when a paid package pop ups some warnings on import, but in this case, I think it doesn’t cost effort to work around it (a workaround would be to publish separate packages for 5.3 and 5.4+ which leads to unnecessary duplication on my side). The bug is submitted but it’s not accepted yet. And, honestly, I doubt it will. The major case when this causes real issues is just support of 5.3 and Unity planned to abandon support of 5.3 in March 2017. Probably I’ll do so too in some next version of Soft Mask.

UPDATE As I thought, UT aren’t planning to fix the warning. But it’s great that they took the time to answer me :slight_smile:

Is it work on 5.2.4?

@ganquan109
I’m currently downloading this version for test. I’ll tell you the results.

@ganquan109
Sorry, it doesn’t work on 5.2 out of the box and I don’t plan to add support of it to the package.

But I managed to get it work on 5.2 with some modifications. The main issue is that 5.3 changed the way UI system controls the rectangle and alpha clipping in the default UI shader. Also, there were some compilation issues related to features that were added in 5.3. The simplest way to get Soft Mask to work on 5.2 is:

  • Remove samples (you can see them in a newer version of Unity).
  • Comment access to .rootCanvas in SoftMask.cs. It breaks Soft Mask functioning on nested canvases. If you don’t need this feature, that’s fine. If you need nested canvases, you can reimplement rootCanvas logic by yourself.
  • Rewrite rectangle and alpha clipping portions of SoftMaskTemplate.cginc in 5.2-style.

If you have some programming knowledge and ready to take risks, I can send my modifications to you. They make Soft Mask to work in a simple scenario but I haven’t tested it thoroughly, so, you should be ready to deal with issues.

i can handle 1 and 2, but i do not know about the .cginc , i write a email to you , please send me your modifications