Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice
  4. Join us on Thursday, September 29, for a day with Unity's SRP teams here on the forum or on Reddit, and discuss topics around URP, HDRP, and the Scriptable Render Pipeline in general.
    Dismiss Notice

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

Discussion in 'Assets and Asset Store' started by zxkne, Feb 4, 2017.

  1. xharkx

    xharkx

    Joined:
    May 17, 2017
    Posts:
    26
    Hi.
    I try to use "Procedural UI Image" by Josh H and soft mask,but no luck.
    I found your ProceduralImageRuntime.patch,but it's not working.
    Can you make, new patch for "Procedural UI Image"?

    Thank you.
     
  2. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    Hi,

    I'm not sure, probably shader was changed in new versions of Procedural UI Image. I haven't checked it out, but prepared a fresh shader .patch instead. It seems to work fine. The updated patch is contained in the attached .zip. There you also find ProceduralUIImageMaterialReplacer.cs script—just put it in any folder in your project.

    Just in case if you have difficulties with using .patch file (I personally do :D), I'm sending you the entire example in PM (no patching required).
     

    Attached Files:

  3. xharkx

    xharkx

    Joined:
    May 17, 2017
    Posts:
    26
    Thank you. It's working.
    But it's not what I expected. I'm really sorry,my bad.

    I want mask like left image of attach file.
    Thank you for your support.
     

    Attached Files:

    • mask.jpg
      mask.jpg
      File size:
      170.8 KB
      Views:
      266
    Last edited: Feb 5, 2021
    zxkne likes this.
  4. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    So, you want to use Procedural Image as a mask. Unfortunately, that's not possible with my patch, as I've written in the original post :( It's possible in theory, there are at least two ways to achieve this. But they both are pretty complicated and require a lot of programming.
     
  5. xharkx

    xharkx

    Joined:
    May 17, 2017
    Posts:
    26
    Ok, Thank you.
     
  6. Dan_Kodable

    Dan_Kodable

    Joined:
    May 12, 2020
    Posts:
    30
    Hey there, great asset!

    Just wanted to let you know, that is, if you're not already aware, there is a small chance for an error to occur when using the asset with animation events/physics events.

    Code (CSharp):
    1. Destroying components immediately is not permitted during physics trigger/contact, animation event callbacks, rendering callbacks or OnValidate. You must use Destroy instead.
    2. UnityEngine.Object:DestroyImmediate (UnityEngine.Object)
    3. SoftMasking.SoftMaskable:FindMaskOrDie () (at Assets/Plugins/SoftMask/Scripts/SoftMaskable.cs:136)
    I have a prefab with the soft mask on it, and it gets used as the result of an animation event. Not a common case probably, but it's possible.
    Swapping to just regular Destroy() works fine.
     
  7. Dan_Kodable

    Dan_Kodable

    Joined:
    May 12, 2020
    Posts:
    30
    Interesting follow up... I also noticed that it complains about the opposite if doing something during edit-time, as in running a build script. I modified it to check if Application.IsPlaying is true to do the appropriate thing, but I noticed in a lot of my soft masks, they stopped working in several cases....

    I have restored it to normal for now, and I'll have to figure out a way to get around the issue regarding callbacks from animation events/physics events.
     
    zxkne likes this.
  8. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    Hi, @Dan_Kodable

    Sorry for such a long delay, email notifications was broken again. Still can't remember to not rely on them :(

    Yes, most of Soft Mask scripts works in Edit Mode too. And you're right, if something is changed in the UI as a result of physics or animation event, Soft Mask may behave incorrectly. I missed this point.

    Did you found some solution for this issue?

    I marked this issue for investigation for the next version. I'll let you know as soon as I figure out something.
     
  9. Dan_Kodable

    Dan_Kodable

    Joined:
    May 12, 2020
    Posts:
    30
    I have not figured out a solution yet, but I haven't really had any time to look into it.
     
  10. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    Hey, just wanted to say, that I've reproduced the issue and currently I'm working on a solution. Naive if (Application.isPlaying) isn't quite work because it introduces some issues in other test cases. I'll keep you posted.
     
  11. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,356
    Is there an example of how this works when masking using a simple black and white texture (with no alpha)? And can that texture be changed at runtime?
     
  12. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    To accomplish this, you can specify Gray as Channel Weights value in the Soft Mask Inspector. An example of this could be seen in 01-TextVanishing scene that's provided with Soft Mask.

    Texture can be changed at runtime. You can switch texture to another at runtime, use SoftMask.texture (or sprite) property for this. You also can change the content of the texture. There are two ways to do this: you can either modify texture on CPU or GPU. An example of a GPU (RenderTexture)-based approach you can see in 06-RenderTexture example scene.
     
    ROBYER1 likes this.
  13. t1ny_bear

    t1ny_bear

    Joined:
    Oct 2, 2020
    Posts:
    15
    Hello, @zxkne!
    I glad to say thank you for such useful extension!
    I have encountered problem with using TextMeshPro's font sprite assets:


    I'd like to remind that by using <sprite name=some_sprite> TMP automatically inserts icon that preset in TMP_Sprite Asset by creating SubMesh:


    SoftMask itself warns me:
    "SoftMask will not work on TMP SubMeshUI [TextMeshPro/Sprite] (TMPro.TMP_SubMeshUI) because material TextMeshPro/Sprite (UnityEngine.Material) doesn't support masking. Add masking support to your material or set Graphic's material to None to use a default one."
    Firstly I tried to add SoftMask support in shader TMP_Sprite.shader, but it didn't work.
    Content of the text field used dynamically, i.e. GameObject with SubMesh could exist or not during game session.
    Please, could you suggest how to handle this issue? Thank you!
     
  14. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    Hello!
    Thank you for the kind words!

    What's about the issue, it looks very similar to a known issue with TMPro submeshes. I've attached a .patch file to this post. But just in case if you have difficulties with applying patches I also sent you modified files in PM, so you can just replace them in the project.

    Please, let me know if this doesn't help.

    The fix will be included in the next version of Soft Mask which is almost ready and, hopefully, will be sent to approval this weekend. Besides this fix it will also contain some other compatibility improvements.
     
  15. t1ny_bear

    t1ny_bear

    Joined:
    Oct 2, 2020
    Posts:
    15
    Hello again!
    Thanks for such fast responce.
    Firstly I tried to apply patch file you've attached in one of previous post. It seems there was no effect for my issue.
    Then, I tried to apply .cs file you've sent me in direct message. This attempt didn't help me either.
    Maybe I missed something, but my reproduction case is very simple:
    Root Object (Canvas, Image, SoftMask)
    Maskable Text (Text UI(TMP): e.g.: "Some Text <sprite name=some_sprite>)
     
  16. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    Just to be sure: have you run the Tools / Soft Mask / Update TextMesh Pro Integration menu?

    I didn't reproduced the issue (even without a patch) yet. Could you answer the following questions to help me localise the issue?
    1. Which versions of Unity and TextMesh Pro are you using?
    2. Does Soft Mask work on TextMesh Pro text, not sprites?
    3. Do you enter <sprite ...> into TextMesh Pro in Editor or assign it at runtime?
     
  17. t1ny_bear

    t1ny_bear

    Joined:
    Oct 2, 2020
    Posts:
    15
    I totally forgot about that menu, my apologies!
    After applying your new .cs script and reintegration problem was fixed!
    Thanks a lot again and waiting for SM update! :)
     
    Last edited: Apr 19, 2021
    zxkne likes this.
  18. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    Soft Mask 1.6 is available now!

    IMPORTANT If you're updating from a previous version, remove Soft Mask entirely from the project and then re-import it from scratch. If you're using TextMesh Pro, re-run the Tools / Soft Mask / Update TextMesh Pro Integration menu.

    It still will work if you apply update on top of the previous version, but you will have redundant shaders in the project which may (probably) cause some issues in the future.

    Release Notes

    Important Notes
    • Since 1.6 Soft Mask requires Unity 2017.1 or higher
    Breaking API Changes
    • Properties SoftMask.defaultShader and SoftMask.defaultETC1Shader are removed. Now Soft Mask uses Resources to dynamically load shaders it needs. You don’t have to specify shaders when instantiating Soft Mask objects from code any more, so, any assignments to these properties that you’ve done before may be safely removed and any reads of there properties may be replaced by Resources.Load<Shader>(“SoftMask”) and Resources.Load<Shader>(“SoftMaskETC1”) respectively.
    Improvements
    • Added support for Preserve Aspect Ratio option of Image component that’s available in Simple mode.
    • Added support for the Maskable option of Maskable Graphic component that was added in Unity 2020.
    • All the Soft Mask code moved into a separate assembly.
    • Improved compatibility of Soft Mask replacement shader with Unity 2021 Default UI shader.
    Bug fixes
    • Fixed a bug caused errors to appear in Console when an object got out of Soft Mask effect in a physics callback.
    • Fixed a bug caused multifont TextMesh Pro texts to be not masked under a Soft Mask.

    Many thanks to everyone who helped me with this update by providing feedback, reporting issues and pointing on lack of some essential features from newer versions of Unity!
     
    t1ny_bear likes this.
  19. Drsoul

    Drsoul

    Joined:
    Jun 11, 2015
    Posts:
    3
    Hi, I am trying to use it on a HDRP project which use HLSL for its shader.
    After I added the SoftMask support code in my shader as the document, it didn't work. There is no compile error, just this warning:
    SoftMask will not work on Overlay-SoftMask (UnityEngine.UI.Image) because material UI_Overlay (UnityEngine.Material) doesn't support masking.

    Can someone help we with it?
     

    Attached Files:

  20. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    Hi!
    The shader does not compile in my project:
    Screenshot 2021-05-09 at 10.13.18.png
    I'm not sure that UI shader can use HLSL instead of CG: default Unity's UI shader still use CG in 2021. Do you really have to use HLSL for UI shader? I also saw that you include SoftMaskHLSL.cginc, I suppose you adapted it somehow for HLSL... can you send me the modified version in PM?
     
  21. Drsoul

    Drsoul

    Joined:
    Jun 11, 2015
    Posts:
    3
    Using HLSL because I need to sample camera color in UI shader to achieve something similar to "grab pass" in HDRP. And I just found the SampleCameraColor() function in HDRP HLSL include.

    #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"

    Maybe there is other way in CG to do the samething for UI in HDRP?

    Oh the SoftMaskHLSL.cginc is just a renaming for my attempt to adapted. But I really don't now how to. Just send you anyway.
     
  22. Liliannismo33

    Liliannismo33

    Joined:
    May 2, 2019
    Posts:
    3
    Hello,

    I bought your product a few months ago and I am very happy with it!

    However, I now want to use it as a mask for Text Mesh Pro.

    I would like to do this, however, when I add Soft Mask in the parent, which is TMP, it does not work and only cuts the image.

    What I want :
    upload_2021-5-13_15-9-30.png

    Without Soft Mask :
    upload_2021-5-13_15-10-54.png

    With Soft Mask :
    upload_2021-5-13_15-10-32.png

    Thanks in advance for your help :)

    (I have try to update at the newest version of Soft Mask, and Go on Tools / Soft Mask / Update TMP Integrations, but that made nothing.)
     

    Attached Files:

  23. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    Hello, @Liliannismo33

    Thank you for the kind words!

    I understood right that you have an hierarchy like this?
    • Parent (Soft Mask)
      • Child (TextMesh Pro UGUI)
    And Child is not masked? That's strange, it should work :) Let's figure out what's going wrong.

    Can you answer the following questions to help me localise the issue?
    • Do any warnings appear in Console window?
    • Which TextMesh Pro shader are you using?
    • If you replace TMPro with a standard Text, is it masked?
     
  24. Liliannismo33

    Liliannismo33

    Joined:
    May 2, 2019
    Posts:
    3
    Hello, thank you for your quick answer!

    No, my hierarchy is composed like this:
    • Parent (TextMesh Pro UGUI)
      • Child (Image w/ Soft Mask)
    I want to have the image in the Text.

    To answer your questions:
    • Do any warnings appear in Console window?
      • No, I don't have any error or warning
    • Which TextMesh Pro shader are you using?
      • I use the default one: TextMeshPro / Distance Field (I also tried with SoftMask/TextMeshPro/Distance Field but it does the same thing)
    • If you replace TMPro with a standard Text, is it masked?
      • When I use a standard text, it does the same thing.
        However, when I use the default Unity mask system, it works (but the edges are not smooth, that's why I want to use Soft mask).
     
  25. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    Thank you for the information!

    So you put standard Unity mask on Child or Parent to achieve the desired effect? I suppose that it's Parent, not Child. I even tried it just now: if I put standard Mask on Parent text, it actually cuts the image, but if I put the mask on Child, nothing happen. May be I missed something?

    Standard Mask masks the object itself and all its children. So does Soft Mask. So, theoretically, you have to put it on Parent to make Child image to be cut off by the text. BUT. Soft Mask cannot have a non-sprite (i.e. non-texture) mask. The only way to use TMPro (or any other text) is to render it into a Render Texture and then use it as a mask. To do so you may need some scripting, an example of this may be for found in example scene 06.

    Sorry for disappointing :( It would be great to have something like dynamic mode in Soft Mask in which it automatically switches to RenderTexture-based approach. But this is not implemented yet and I can't tell any specific deadlines for this for now.
     
  26. Morphus74

    Morphus74

    Joined:
    Jun 12, 2018
    Posts:
    160
    Hi

    Trying to do the "cut the hole" tutorial, it work well, but the event are not going through
    upload_2021-5-14_17-31-7.png


    If I click inside the frame, nothing happen...

    If I invert mask and click in the "hole" area still nothing happen
    upload_2021-5-14_17-31-56.png

    the only think that will work is if I remove the Invert Outside, and I click anywhere outside of what "mask frame" cover
    upload_2021-5-14_17-32-39.png
    upload_2021-5-14_17-32-45.png

    As you see setup seem simple

    if I disable those object, all UI event work as usual

    Any idea why?
    Thank
     
  27. Morphus74

    Morphus74

    Joined:
    Jun 12, 2018
    Posts:
    160
    Just try in your demo and same issue
    upload_2021-5-14_17-42-9.png
    upload_2021-5-14_17-42-15.png
    I create an Input field... and remove the draggable mask because it was the hole

    I also tried to put the input field in a different canvas, same issue.

    If you have an idea it would be appreciate
     
  28. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    Hello!
    To make it work as you expected, you have to set the Raycast Threshold slider to a value greater than zero. 0.1, for example:
    Screenshot 2021-05-15 at 09.54.21.png
    You also have to use a readable texture as a mask source (to let Soft Mask sample it on CPU). Do to so, go to the texture (or sprite) import settings and set the Read/Write Enabled flag.
    Screenshot 2021-05-15 at 09.51.07.png
     
  29. Morphus74

    Morphus74

    Joined:
    Jun 12, 2018
    Posts:
    160
    Thank, I did try the read/write and Raycast threshold before... but it was not working
    Try it on the demo and it work
    Figure out that on my scene, since I have a "border" over the mask, I also need to allow that one to let event pass, so need to allow raycast both on the maks and use Image Transparency on the border image
    upload_2021-5-15_7-17-46.png
    Thank it work great now :)

    Thank for the great asset and quick support, much appreciated
     
    zxkne likes this.
  30. Morphus74

    Morphus74

    Joined:
    Jun 12, 2018
    Posts:
    160
    And is there anyway if you set the MaskFrame scale to 0,0 to still see the "image", that way you could make the hole "appear" by animating scaling. (at the moment I put scaling at 0.01 to prevent the mask from going away but hiding the hole)

    Thank
     
  31. t1ny_bear

    t1ny_bear

    Joined:
    Oct 2, 2020
    Posts:
    15
    Hello everyone!
    I have some strange behaviour while I'm using SoftMask, just want to be sure using I them right or not.
    Here's the case:
    I want to mask TMP label by alpha with the next gradient:

    The hierarchy of objects:
    -SoftMask
    |--TMP Label(using SoftMask/TextMeshPro/BitmapShader).
    As result I have the next:

    In the right part of the given picture text fades from white color to the black one, but I expected it would fade to the transparent color.

    Thanks for your time.
     
  32. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    Hello!

    I've reproduced the issue. It's actually a bug in Soft Mask's TMPro integration. I don't know yet if it was added recently by migration to premultiplied alpha or it was here since the very first version. But I'm going to figure it out and release an update soon.

    Meanwhile, I can suggest a quick fix to make the shader work as you expect. Change line 150 in the shader TMP_Bitmap - SoftMask.shader with the following line:

    result_SoftMask.a *= SOFTMASK_GET_MASK(IN);

    Some details just in case if you're interested: unlike SDF shader, TMPro's Bitmap shader does not use premultiplied alpha for some reason. But modifications that Soft Mask automatically applies to TMPro's shaders suppose that shaders are blended in premultiplied alpha mode (One OneMinusSrcAlpha). So we remove pre-multiplication of the resulting color by the alpha to make the resulting color have a correct value for (SrcAlpha OneMinusSrcAlpha) blending.

    Thank you for reporting!
     
  33. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    399
    In the manual section with name "Tutorial: Adding the Soft Mask support to your own shader"
    You have an error
    Code (CSharp):
    1. #include "Assets/SoftMask/Shaders/SoftMask.cginc"
    but correct path is
    Code (CSharp):
    1. #include "Assets/SoftMask/Shaders/Resources/SoftMask.cginc"
     
    zxkne likes this.
  34. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    Thank you! I've forgot to update it after moving shaders to Resources subfolder. Now fixed it.
     
  35. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    399
    Hi there zxkne! Does it possible to prevent Soft Mask from being excluded from the build if i set the "Strip Engine Code" level higher than "Low"?
    I've added
    <assembly fullname="SoftMask" preserve="all"/> to the "link.xml", but maybe it should be automatized.
     
    Last edited: Jun 7, 2021
    zxkne likes this.
  36. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    Hi!

    You are right, Soft Mask should work without any additional setup in any Strip Engine Code level. There's actually a bug in Soft Mask and I just reproduced it. So thank you for reporting! The fix will be included in the upcoming 1.6.1 patch.

    Just one more question: how exactly does the bug show itself in your case? I reproduced an issue in TextMesh Pro integration—Soft Mask doesn't mask TMPro texts when Strip Engine Code is set to High. But may be you've seen other symptoms? It will help me to be sure that I localised the issue right.
     
  37. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    399
    Same here - "Soft Mask doesn't mask TMPro texts" and also custom shader didn't work(Procedural UI Image asset) and both cases happened with Medium level of Strip Engine Code.
     
    zxkne likes this.
  38. LeventP

    LeventP

    Joined:
    Jul 17, 2020
    Posts:
    22
    Having the same problem here. It works fine on Android and iOS, but on WebGL the mask fails with "Strip Engine Code" enabled and "Managed Stripping Level" set to Low. When can we expect the patch?
     
  39. unifiedJed

    unifiedJed

    Joined:
    Mar 20, 2015
    Posts:
    9
    Hello, I'm getting an error that soft mask doesn't support custom shaders in my scroll rect. However, I'm not using custom shaders, it appears that my TMP objects are not being masked because they're being treated as a custom shader. Could you help me debug / fix this, as I see the asset says it has TMP support
     
  40. unifiedJed

    unifiedJed

    Joined:
    Mar 20, 2015
    Posts:
    9
    This is the text shader that is failing: upload_2021-6-16_9-13-12.png
     
  41. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    I submitted the version to review the last week, but it was rejected because Asset Store does not want to support assets for Unity 2017 anymore. I haven't decided yet what to do with this, but I'm sure, that I'll be able to re-submit patch this weekend.

    Until then, you can add [UnityEngine.Scripting.Preserve] attribute to SoftMasking.TextMeshPro.MaterialReplacer class (file SoftMask/Scripts/TextMeshPro/MaterialReplacer.cs):
    Code (CSharp):
    1. namespace SoftMasking.TextMeshPro {
    2.     [Preserve]
    3.     [GlobalMaterialReplacer]
    4.     public class MaterialReplacer : IMaterialReplacer {
    5.         ...
     
  42. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    Did you run Tools / Soft Mask / Update TextMesh Pro Integration menu? If yes, did any error appear in Console during this process?
     
  43. unifiedJed

    unifiedJed

    Joined:
    Mar 20, 2015
    Posts:
    9
    I totally did not do that, this fixed my issue. Thanks for getting back to me so quickly, you are awesome!
     
    zxkne likes this.
  44. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    Soft Mask 1.6.1 is out!

    IMPORTANT The minimum Unity version was bumped up to 2018.4. Unity Technologies now requires all the updates to be submitted from an LTS version, so I decided to not support old versions and not submit multiple package variants.

    It's a minor bug fixing release. Here are full release notes:

    Improvements
    • Added support for Bitmap-Mobile-Custom-Atlas TextMesh Pro’s shader.
    Bug fixes
    • Fixed a bug in TextMesh Pro integration caused Bitmap and Sprite shaders to appear black on the borders of a mask.
    • Fixed a bug caused TextMesh Pro integration-related scripts to be stripped out from a build when Managed Strip Level was set to a level higher than Low.
    • Fixed a wrong #include path in an example shader that is used in example 04-CustomShader.
    • Fixed a compilation warning on an unused variable.
    Most of the problems were reported by you, so, thank you all for the feedback!
     
    t1ny_bear likes this.
  45. Houp

    Houp

    Joined:
    Sep 8, 2014
    Posts:
    6
    Hi,

    is it possible to have mask made up from several images?

    Masked element's pixel should be visible if it is under at least one of the mask images.
     
  46. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    Hi,

    The only way to mask an element by several masks with Soft Mask is to use Render Textures. You need to render several elements to a render texture (with additive blending, if you want the pixel be visible under at least one of the mask images) and then assign this texture as a mask source in Soft Mask. Of course, it will cost you some memory.

    Soft Mask contains an example of how to work with render textures—06-RenderTexture. But you need to write/understand some code in order to make it work.
     
  47. pfay

    pfay

    Joined:
    Mar 2, 2020
    Posts:
    7
    I think there is a bug (or just unsupported case) with preserve aspect on simple images. If the image being used as a mask has a transparent padding around it that isn't the same aspect ratio (i.e. it has 100 transparent pixels on the sides but only 10 on the top), then it won't be resized correctly as per the "preserve aspect ratio" in SoftMask 1.6.1. I was able to fix this by trimming all the excess transparent pixels from my source images. I think maybe this happens because of a discrepancy between how the UV rect ignores transparent pixels but the sprite size does not.
     
  48. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    Hi,

    Does the bug reproduces only on sprites having the Mesh Type set to Tight? If yes, then I've reproduced the issue. I need some time to think about it and figure out if that could be fixed. I'll come back tomorrow with more information.

    But if the bug reproduces even with Full Rect Mesh Type, can I ask you for some more details? Can you send me settings of a Soft Mask and Sprite Importer? A screenshot of the Inspector window would be fine. A simple reproduction scene would be even greater, if it's no trouble.

    Thank you for reporting!
     
  49. pfay

    pfay

    Joined:
    Mar 2, 2020
    Posts:
    7
    Ah yes, this only happens on mesh type tight. Switching the mesh types to full rect also fixes the issue for me, which is a totally fine workaround for my use case.
     
    zxkne likes this.
  50. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    221
    That's great!

    I've find and (supposed) fixed the bug. In case you're interested in trying the fixed version, I'm attaching a .patch file. To simplify things I also send you the full SoftMask.cs file in PM. So you can just replace SoftMask/Scripts/SoftMask.cs file with the new one and don't bother with applying a patch.

    The fix will be included in the next version. Again, thank you for reporting!
     

    Attached Files:

    pfay likes this.
unityunity