Search Unity

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

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

  1. RazaTech

    RazaTech

    Joined:
    Feb 27, 2015
    Posts:
    178
    • I have moved Soft mask in a Folder named Extensions and then build and got this problem.
    • now I removed it and re-import it and it worked.
    • please add support for nested folders, so code repo could be clean.

      Thanx
      Abdul Hanan.
     
  2. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    I have tried to do the following:
    1. Moved Soft Mask to Extensions folder
    2. Switched platform to Android
    3. Run the build
    And got the error you showed in the previous post. After that, I right clicked on Extensions / Soft Mask / Shaders folder and selected Reimport. Then repeated the build and everything worked. Did it not work for you?

    I understand, it seems ugly, but, unfortunately, I can't fix this bug :(
     
  3. RazaTech

    RazaTech

    Joined:
    Feb 27, 2015
    Posts:
    178
    I can go with it.
    BTW Thanx for Tip , I did not try this method , now it worked .

    Thanx
    Abdul Hanan :)
     
  4. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    Hi, guys,

    News for TextMesh Pro integration users.

    TextMesh Pro has been updated to 56.0b3. This version introduces some changes that break Soft Mask's integration. Some shaders still work, but many of them don't. I will provide an updated integration package in 12 hours. It usually takes a day or two for Unity to review the update, but I will attach it here as soon as it's ready. Till this time I recommend you to not update TextMesh Pro (or just don't execute 'Update TextMesh Pro Integration', which make the previous shaders be used).
     
  5. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    Just submitted the update of 'SoftMask for TextMesh Pro' for review. For those who can't wait for approval, attached the updated package to this post. Don't forget to execute 'Tools / Soft Mask / Update TextMesh Pro Integration' after importing the new version.

    During the process, I've found that support of TMPro was partially broken by the previous update (56.0b1) though I had said the opposite :( Luckily, not all shaders were broken; the main ones (SDF and SDF Mobile) were working fine. My apologies to everyone who might have faced any troubles caused by this.
     
    Last edited: Feb 13, 2018
  6. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    Soft Mask for TextMesh Pro has been updated on Asset Store. Now, all supported TextMesh Pro shaders should work as expected.
     
  7. Freznosis

    Freznosis

    Joined:
    Jul 16, 2014
    Posts:
    298
    Is there a way to get SoftMask to work when starting on a disabled gameObject? If the object starts enabled it appears fine. Like this. But if the object starts disabled and then get's enabled, it completely hides everything and looks like this. I have to disable the gameObject then re-enable it (after already enabling it the first time from a disabled state) for it to work, but I have a lot of objects and re-enabling them all would be inefficient. Is there some kind of function I can call that will "wake up" SoftMask?

    Edit: Some extra info. There are no nested masks, or any complex setups. Just a simple image, a child image, and a softMask component on the main image. I wanted to inform you that just enabling and disabling the SoftMask script doesn't work and it has to be the whole object. Maybe it's related to the LayoutBuilder?
     
    Last edited: Mar 12, 2018
  8. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    Hello @ModularBuilds,

    It sounds like a bug. Unfortunately, I have been not able to reproduce it. Can you answer several questions?
    1. Do you enable a masked object or the mask itself?
    2. Is the object enabled from a script or via Inspector? If it's a script, the bug happens in the Editor or in the Build?
    3. What source type does the mask use (Graphic, Sprite or Texture)?
    I also would be very appreciated if you could provide a small example project.

    Answering your question, there is a method that probably would help — SoftMaskable::Invalidate(). SoftMaskable is a component that is attached to every masked object.
     
  9. Freznosis

    Freznosis

    Joined:
    Jul 16, 2014
    Posts:
    298
    I do not touch the mask or the masked object itself. I only set the main GameObject on or off.

    -Main Object <--- This object starts disabled, and is enabled on start.
    --Mask Image
    ---Masked Image

    The mask is using Sprite and the object is enabled from scripting. I was troubleshooting and if I disable the main object off and back on, the mask starts working again. I'll try and see if I can find anything else that might be causing this problem.
     
  10. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    Sorry, I still not able to reproduce. I've tried Unity 2017.2 and 5.4.5. What version are you using?

    I can say, that if the mask is enabled but the masked object is invisible, this may be caused by that the material properties aren't updated for some reason. You can check whether it's true or not using the Frame Debugger window. Select draw call corresponding to the invisible object and check properties in the Shader Properties tab (see the attached screenshot).

    Also, do you have some other IMaterialModifiers on the target object? Or, maybe you use standard Unity's Mask somewhere upper in the hierarchy? There is a known issue related to it.
     

    Attached Files:

    Last edited: Mar 13, 2018
  11. ligrew

    ligrew

    Joined:
    Mar 14, 2013
    Posts:
    3
    Is it working with Xbox One? While running our project in Editor everything is fine. Standalone build works but TextMeshProUGUI labels has default material preset like in TextMeshPro FontAsset, not the one created that adds shadow and selected as a material preset. Xbox build throws error every frame:

    (Filename: Project/Assets/SoftMask/Scripts/SoftMask.cs Line: 404)
    NullReferenceException: A null value was found where an object instance was required.
    at SoftMasking.SoftMask.SoftMasking.ISoftMask.GetReplacement (UnityEngine.Material original) [0x00013] in Project\Assets\SoftMask\Scripts\SoftMask.cs:404
    at SoftMasking.SoftMaskable.GetModifiedMaterial (UnityEngine.Material baseMaterial) [0x00014] in Project\Assets\SoftMask\Scripts\SoftMaskable.cs:44
    at UnityEngine.UI.Graphic.get_materialForRendering () [0x00000] in <filena
    unknown>:0
    at UnityEngine.UI.Graphic.UpdateMaterial () [0x00000] in <filename unknown>:0
    at UnityEngine.UI.Image.UpdateMaterial () [0x00000] in <filename unknown>:0
    at UnityEngine.UI.Graphic.Rebuild (CanvasUpdate update) [0x00000] in <filename unknown>:0
    at UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () [0x00000] in <filename unknown>:0
    UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
    UnityEngine.DebugLogHandler:LogException(Exception, Object)
    UnityEngine.Logger:Log
    ception(Exception, Object)
    UnityEngine.Debug:LogException(Exception, Object)
    UnityEngine.UI.CanvasUpdateRegistry:performUpdate()
    <Module>:invoke_void__this__()
    UnityEngine.Canvas:SendWillRenderCanvases()
     
  12. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    Hello,

    Unfortunately, I had no chance to test it on XBox. But I'm pretty sure we will be able to localize the issue working together.

    The information you provided suggests me that it may be caused by IL2CPP code stripping. The Soft Mask for TextMesh Pro package contains class MaterialReplacer. It is instantiated via reflection at the runtime but there is no one instance of this class is attached to a scene object or resource, therefore Unity could just remove it.

    Try to add the [Reserved] attribute to MaterialReplacer class. You can find more information on code stripping in IL2CPP here.

    If that will not help, please, answer the following questions:
    1. Is there any other kind of errors? Especially at the very beginning of execution?
    2. What version of Unity are you using?
     
  13. radek_oml

    radek_oml

    Joined:
    Apr 14, 2015
    Posts:
    36
    I have the same problem with Xone build and I'm using mono - it's like _materials field is always null and produces a bunch of NullReferenceExceptions. There's no [Reserved] attribute from what I see. It just might not work on consoles...
     
  14. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    _materials are initialized in the constructor. Can you check whether the constructor is called? Debug.Log() will not work here but you can, say, throw an Exception, which Unity should catch and report.

    That is the reason why I asked about any other kind of errors especially at the start: if some exception occurs in Soft Mask constructor, then _material field will be not initialized and everything will behave as you describe.

    Also, it would be great to know:
    • Unity version
    • Soft Mask version (can be found in the documentation PDF)
    • Is TMPro integration used?
    @ligrew, @radek_oml, if you don't want to spend your time on the issue, I can return the money. Just send me the invoice number to email or PM.
     
  15. radek_oml

    radek_oml

    Joined:
    Apr 14, 2015
    Posts:
    36
    SoftMask constructor is called bu never instanced - it's probably because of that:

    ExecutionEngineException: Attempting to JIT compile method 'System.Linq.Enumerable:Iterate<SoftMasking.IMaterialReplacer, int> (System.Collections.Generic.IEnumerable`1<SoftMasking.IMaterialReplacer>,int,System.Func`3<SoftMasking.IMaterialReplacer, int, int>)' while running with --aot-only.

    AOT Compile Options: nrgctx-trampolines=8192,nimt-trampolines=8192,ntrampolines=4096
    Compiler: mono
    Unity version: 2017.2.2f1

    Soft Mask version: 1.2.2
    TMPro version 1.0.56.2017.2.0b3
    latest SoftMask For TMPro integrated
     
  16. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    Yes, that is probably the cause. Is it the entire error message? Doesn't it contain a stack trace?

    In order to fix this, we need to localize from where this method is called. I guess it's MaterialReplacerChain.Initialize(), but I may be wrong. Try to replace this method with the following:

    void Initialize() {
    _replacers.Sort((a, b) => a.order.CompareTo(b.order));
    order = _replacers[0].order;
    }

    If after this ExecutionEngineException will still be here, try the following:
    1. Comment the body of MaterialReplacerChain.Initialize() entirely
    2. Replace the body of MaterialReplacer.CollectGlobalReplacers() with return new
      IMaterialReplacer[0];
    After each step check whether the error still exists.

    Thank you for helping with this bug!
     
    Last edited: Mar 29, 2018
  17. ElasticSea

    ElasticSea

    Joined:
    Aug 10, 2016
    Posts:
    10
    Hi, do you have any idea what is causing this issue ? A big white rectangle is blocking the image.

    I can simulate it on iphone and in safari webgl. Some users also reported it on webgl chrome.
     

    Attached Files:

  18. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    Hi, @ElasticSea

    Do you have access to logs? Are there any errors?

    Also, could you try a fix from the previous post? If the issue appears only on iPhone and WebGL, it may be caused by AOT compilation and the fix above is exactly about this (I'm planning to include it the next version).
     
  19. IntelligentDesign

    IntelligentDesign

    Joined:
    Jun 13, 2014
    Posts:
    51
    Does this package allow for inverse masking (having a UI Image, sprite, etc be visible outside of the masking object)?
     
  20. YD_JMysior

    YD_JMysior

    Joined:
    Aug 4, 2016
    Posts:
    60
    Hi, this package looks great. Does it work with Sprite Renderer too or only with Unity Canvas (Images, RawImages)?
     
  21. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    Hello! Sorry for such a long delay.

    Soft Mask doesn't support this feature out of the box. You can adapt shaders manually, if you want, though.

    Unfortunately, it works only with Canvas.

    Thanks for your interest in my package!
     
  22. Freznosis

    Freznosis

    Joined:
    Jul 16, 2014
    Posts:
    298
    Will there be an update to fix SoftMask for Unity 2018 when using TextMeshPro via the package manager?
     
  23. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    Hello! Sorry, I missed a TextMesh Pro update. I just checked it, as far as I understand, the majority of shaders is still working, the issue is with Bitmap shader? I currently working on it, this shouldn't take more than 6-8 hours. I will post an updated package here as soon as it will be ready.

    Again, sorry for inconveniences.
     
  24. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    I misunderstood the problem for the first time. The issue with Bitmap is actual only for the source version of TextMesh Pro. As for Package manager, this new way of using TMPro changes GUIDs of all assets, so Soft Mask for TextMesh Pro doesn't work with it at all. Anyway, I'm working on it and will report as soon as an update is ready.
     
  25. Freznosis

    Freznosis

    Joined:
    Jul 16, 2014
    Posts:
    298
    No worries, I'll just use the Asset Store version until then. :)
     
  26. Seto

    Seto

    Joined:
    Oct 10, 2010
    Posts:
    243
    It's working great. But it does not support to use with scroll rect.
    --------------------------------------------------------------------------------------
    UPDATED: OIC. It's working. It doesn't hide the mask graphic itselft. I should disable it myself.
    But then I can't scroll when dragging blank area.
    --------------------------------------------------------------------------------------
    UPDATD: OK. It's working now with mask image 0 alpha. But then it means the alpha of Color in Image component is not working. It's only working with the alpha of Source Image in Image component.
     
    Last edited: May 12, 2018
  27. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    Hello, @Seto

    Yes, you're right—alpha of Color in Image component doesn't affect masking as it's stated in Documentation, in the section Interaction with the Graphic component. If you don't want to draw the mask image itself, you can just choose Sprite or Texture mode on the Soft Mask component. In this case, the object with Soft Mask can contain no Graphic at all (or you can use dummy Graphic if you need it to make dragging work).

    Thank you for choosing Soft Mask, and have a good day!
     
  28. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    I've just finished with TextMesh Pro 1.2.2 and Package Manager support. The update is submitted to Asset Store. Usually, it takes a day or two for approve.

    UPGRADE NODE I recommend to remove the previous version before importing the new one. That is, just delete the "SoftMask for TextMesh Pro" folder entirely before importing the new version. This should not break anything because in normal usage there should be no references to this folder from your project. If you've referenced generated shaders somewhere... well, then you, probably, know what to do ;)

    As usual, you need to regenerate shaders by clicking "Tools / Soft Mask / Update TextMesh Pro integration". If you're using Package Manager version of TMPro, import TMPro essential resources before doing it.

    I've reworked the patching algorithm. The previous one was based on textual diffs (as in VCS). The new one is a bit more intellectual—it tries to determine the shader structure (how a V2F structure is named, what a pixel shader tries to return, etc). This should make the solution more robust. Hopefully, I didn't break anything :)

    For anyone who doesn't want to wait for Asset Store approval, I've attached the new version to this post. @CloudWeight, you probably can take a look at it.

    UPDATE Removed the attached package—please, use the version available on Asset Store.
     
    Last edited: May 17, 2018
    Freznosis likes this.
  29. NicoVar

    NicoVar

    Joined:
    Sep 21, 2012
    Posts:
    40
    Hi! I got the plugin and it's working great.

    I'm looking to do an animated (as in fade in) additive mask on an image. Is that something I can do with the plugin?

    I have an image and I'd like to start revealing part of such image, one by one.

    I have it working, but I created a mask for each step of the reveal sequence, and fade in / fade out as I move along. It works fine, the problem is since the masks are soft, there is a time during fade in / fade out that the mask's edge become twice as opaque.

    Thanks!
     
  30. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    Hi, @NicoVar!

    To avoid blending issues, it would be better to modify mask texture itself. There are two ways to do it:
    1. Use SetPixel()/SetPixels(). In this case, you modify (or regenerate entirely) the texture on the CPU. This solution may have bad performance, especially if the mask texture is large. An example of this approach you can see in the SoftMaskAndSetPixel package that is attached to this post.
    2. Use RenderTexture and update it on the GPU. There are several ways to do it depending on what the abstraction level you want to work with. You can rely on Unity's Canvases and/or Cameras to render the desired image to a RenderTexture. Or you can go deeper and use CommandBuffers or OpenGL code. The package SoftMaskTextScratchingDemo shows the high-level approach with Canvas. The current version of Soft Mask makes it inconvenient to work with RenderTexture—you either should modify Soft Mask code or copy RenderTexture to a regular Texture2D each frame (the example uses copying). Hopefully, I will improve this in the future versions.
    I'm attaching two examples. They both don't contain Soft Mask so you should import it manually. Also, the SoftMaskTextScratchingDemo uses TextMesh Pro so you need to import both it and the integration package. If you're using 2018.1 you can also get TextMesh Pro from Package Manager.
     

    Attached Files:

    Last edited: May 15, 2018
  31. ZeonIr

    ZeonIr

    Joined:
    Feb 23, 2014
    Posts:
    15
    im getting
    Assets/SoftMask for TextMesh Pro/Scripts/MaterialReplacer.cs(5,37): error CS0246: The type or namespace name `iMaterialReplacer' could not be found. Are you missing an assembly reference?

    on latest updates
    Unity 2017.2.2
     
  32. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    Hi, have you imported Soft Mask? "SoftMask for TextMesh Pro" is an integration plugin that requires both Soft Mask and TextMesh Pro in order to work.
     
  33. ZeonIr

    ZeonIr

    Joined:
    Feb 23, 2014
    Posts:
    15
    oh i se soy thes not full Softmask
     
  34. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    I've been reported an issue with Soft Mask and TextMesh Pro in builds. As far as I understand, it is applicable to any version of TextMesh Pro, Unity and Soft Mask.

    The issue: if you're using complicated TMPro materials (with bevels, glow, etc) on masked texts, these materials may degrade to simpler versions in a build. It's caused by that Unity removes unused shader variants from a build and Soft Mask generates his materials on the fly. So, patched TMPro materials actually never use any of its shader_features and, therefore, these features don't go into a build. I'm currently researching a way to instruct Unity which shader variants should be included in a build but I'm not sure that it's possible at all. For now, you can use the following workaround.

    The workaround: add required materials to the Included Shaders list in Graphics Settings (Edit / Project Settings / Graphics). In most cases, it will be "TMP_SDF - SoftMask.shader" but it actually depends on what features of TMPro are you using. It will increase the build size a little bit (adding a single shader increased .apk by ~1 Mb in my case).
     
    Nobi-Knobi and VadimWG like this.
  35. cmbellman

    cmbellman

    Joined:
    Sep 19, 2013
    Posts:
    20
    Hello! I have a small flickering problem in my lists, when reloading. I instantiate a list of elements, where I use the soft mask in a component in each element. To do this I first destroy all objects and then instantiate them again. If the source has not changed, list is re-built exactly as it looked before and user does not notice anything.

    However after switching from the built in UI mask to soft mask, I notice a slight flickering on the objects using the mask when the list is re-instantiated (It's like they are emptied or white for a frame). If I disable the soft mask or switch to unity mask, I don't see this flicker.

    Do you know if this can be avoided?
     
  36. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    Hello, @cmbellman

    First of all, thank you for using Soft Mask and sorry for inconveniences caused by it.

    I tried to reproduce this bug but had no success yet. Can you describe steps that your program performs more detailed? As I understand, you have a hierarchy like this:
    • Mask
      • Child1
      • Child2
      • ...
    And your code performs this:
    1. Destroy() all the child objects of the Mask (Child1, Child2, ...)
    2. Change the Mask.sprite property
    3. Instantiate() new objects into Mask
    I did those steps and saw no flickering. I guess, your scenario is actually a bit more complicated.

    Also, I would be very appreciated, if you could provide a repro project.
     
  37. cmbellman

    cmbellman

    Joined:
    Sep 19, 2013
    Posts:
    20
    @zxkne Hi again, yes it may be complicated to explain and I can't say 100% it's because of soft mask, but I see these difference if I put on a Unity mask and switch between them, everything else exactly the same. It looks like something like this:

    • Prefab (Layout Element)
      • Soft Mask (circle)
        • Avatar (raw image)
      • Other UI (name, stats etc)

    Prefabs are instantiated in a vertical layout group, so each prefab (I call them 'user card') is presented in a vertical list in a scroll rect.

    1. Instantiate prefabs (from an api call returning a list of data)
    2. Returning to this screen, will initialize a reload
    3. When api call returns data: Clear list by destroying each user card in a loop (foreach (var uc in GetComponentsInChildren<UserCard>())
    4. Iterate through data list and Instantiate all user cards again (same step as 1.)

    --- looks like one frame flicker only on the masked image, everything else stays static when list is replaced ---

    In user card instantiation I programmatically set the texture of the avatar. All textures are cached from the first load so no waiting times there, basically just (simplified):

    var userCard = Instantiate<UserCard>(userCardPrefab...);
    userCard.avatarImage.texture = getAvatarTextureFromCache();

    I'll try to strip the project and get you a repro.
     
  38. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    @cmbellman,

    Could you try to add the following line to SoftMask.OnEnable()?

    Canvas.willRenderCanvases += LateUpdate;

    And an according unsubscription to OnDisable():

    Canvas.willRenderCanvases -= LateUpdate;

    It's a hack, just for a hypothesis check.
     
  39. cmbellman

    cmbellman

    Joined:
    Sep 19, 2013
    Posts:
    20
    @zxkne That did the trick! Flickering is gone.
     
    zxkne likes this.
  40. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    @cmbellman, Great! I'm going to make a more robust solution. When it's ready, I'll post it here and then include it in the following update.

    And thank you for reporting and helping with this bug!
     
  41. cmbellman

    cmbellman

    Joined:
    Sep 19, 2013
    Posts:
    20
    @zxkne No problems, and thanks for a great asset and support! :)
     
  42. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    Soft Mask has been updated to 1.2.3. It's a minor release that fixes several known bugs.

    Bug fixes
    • Fixed a bug caused Soft Mask to not work on some AOT platforms.
    • Fixed an issue caused masked UI elements to flicker sometimes.
    Improvements
    • Improved compatibility of Soft Mask shaders with 2018 lineup. Now they support UV transformations as standard 2018’s UI shader do.
    • Removed a use of an obsolete name which caused Unity 2017.3 and later versions to run script upgrade on Soft Mask import.
     
  43. NolwennB

    NolwennB

    Joined:
    Mar 4, 2014
    Posts:
    15
    Hello,
    I've just bought your plugin, and I have a problem with the Separate Mask functionnality.
    I created a test scene with :
    - an empty viewport element
    - a mask root with a SoftMask component, and viewport as SeparateMask (it seems that if I put an image component directly here, the mask doesn't work. Am I right ?)
    - an image Component (child of mask root)​
    If both viewport and root mask RectTransforms are set to middle-center (anchor, pivot and position) everything work as expected. But if I set them to top-left or bottom-left for example, and that I change the width of my viewport, the image is not being shown or hided accordingly. However, if I refresh the view by disable/enable the soft mask for example, it is updated correctly.
    Can you reproduce this issue ? (Unity 2018.1.2f1)

    Edit : If the X pivot of my viewport is set to 0, and I change the width, the mask doesn't update. If the X pivot is 0.0001, it works.
     
    Last edited: Jun 7, 2018
  44. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    Hello, @NolwennB
    Sorry for such a long delay! I've reproduced the bug you reported. It seems that changing of RectTransform's dimensions doesn't set Transform.hasChanged flag. It will take me a few days to find a solution for this issue and submit a patch.

    Until that time, you can work around the issue as follow:
    1. Create a public method SetDirty() in SoftMask that sets _dirty field to true.
    2. Call this method each time you change dimensions of the RectTransform.
    Sorry for inconveniences. If you want to get your money back, send me invoice number by PM or email.
     
  45. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    I've fixed the bug and submitted the updated version for review. According to past experience, it should become available in a day or two.

    UPDATE Soft Mask 1.2.4 is available on Asset Store.
     
    Last edited: Jun 20, 2018
  46. startleworks

    startleworks

    Joined:
    Jun 8, 2013
    Posts:
    34
    Hi,

    I'm having difficulty making a UI shader for Blend Mode Shader 2D.
    I copy-pasted the required stuff from WaveWithSoftMask shader, but it doesn't work. my blended images are not masked, even though Soft Mask no longer shows a warning.
     
  47. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    226
    Hi, @startleworks

    Can you send me your patched shader in a private message? I'll look at it and let you know if it could be fixed and how.
     
  48. startleworks

    startleworks

    Joined:
    Jun 8, 2013
    Posts:
    34
    i just did
     
  49. Igualop

    Igualop

    Joined:
    Mar 1, 2017
    Posts:
    30
    Hello,

    This is not exactly a bug but might be something that could have a proper error message. So, here's the story:

    After updating to the latest version I've started getting the following errors:

    Assertion failed: Assertion failure. Value was False. Expected: True

    UnityEngine.Assertions.Assert:IsTrue(Boolean)
    SoftMasking.SoftMask:UpdateMaskParameters() (at Assets/Imported/SoftMask/Scripts/SoftMask.cs:467)
    SoftMasking.SoftMask:OnWillRenderCanvases() (at Assets/Imported/SoftMask/Scripts/SoftMask.cs:405)
    UnityEngine.Canvas:SendWillRenderCanvases()

    NullReferenceException: Object reference not set to an instance of an object

    SoftMasking.SoftMask.WorldToMask () (at Assets/Imported/SoftMask/Scripts/SoftMask.cs:633)
    SoftMasking.SoftMask.FillCommonParameters () (at Assets/Imported/SoftMask/Scripts/SoftMask.cs:622)
    SoftMasking.SoftMask.CalculateSpriteBased (UnityEngine.Sprite sprite, SoftMasking.SoftMask+BorderMode borderMode) (at Assets/Imported/SoftMask/Scripts/SoftMask.cs:569)
    SoftMasking.SoftMask.CalculateMaskParameters () (at Assets/Imported/SoftMask/Scripts/SoftMask.cs:519)
    SoftMasking.SoftMask.UpdateMaskParameters () (at Assets/Imported/SoftMask/Scripts/SoftMask.cs:468)
    SoftMasking.SoftMask.OnWillRenderCanvases () (at Assets/Imported/SoftMask/Scripts/SoftMask.cs:405)
    UnityEngine.Canvas.SendWillRenderCanvases () (at C:/buildslave/unity/build/artifacts/generated/bindings_old/common/UI/UICanvasBindings.gen.cs:240)


    After some investigation I've found out that the canvas in line 633 was not set. With some debugging I found out that some of my masked objects didn't had a parent canvas so I just had to add that. (These were gameObjects used to preload my scene assets so it was ok to me if they didn't had any).

    This error message didn't appear before the update so it might take someone else by surprise.
     
  50. ElasticSea

    ElasticSea

    Joined:
    Aug 10, 2016
    Posts:
    10
    Hi, finally got back to you. I upgraded to newest version yesterday and saw those fixes you proposed and tried it in Edge as webgl, but saw no change.... btw it works in chrome no problem.

    I found out that the culprit seems to be having "generating mipmaps" turned on for the mask texture. I am testing this with 2017.3.1f1. Do you want to send a build or can I assist you somehow ? I did not see anything in the log.