Search Unity

Alpha Mask: UI, Sprites, Tilemaps, Particles, 3D

Discussion in 'Assets and Asset Store' started by DominoOne, Feb 16, 2015.

  1. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Hi! :) I have checked the situation you've described, and after further investigation, it became obvious that it's an issue with Unity :/ I've found multiple threads, where people are experiencing this issue (unrelated to Alpha Mask, but related to Unity UI): when you move the camera, Unity automatically moves all the Canvas, but it lags one frame – and there's nothing we can do on our side... However, I've found a workaround that you could use: can you try attaching the Canvas to your UI Camera (so that the Canvas is its child)? That seems to help, but let me know if it works in your project.
     
  2. OreoSplitter

    OreoSplitter

    Joined:
    Oct 21, 2017
    Posts:
    33
    Thank you for the solution. This asset is so easy to use.
     
  3. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Thanks! That's very good to know :) You can leave us a review on the store, too – it would help a lot!
     
  4. SirLaur

    SirLaur

    Joined:
    Jan 24, 2014
    Posts:
    22
    I was wondering, is it possible to mask a custom generated quad at the beginning of the game, and then, over time, unmask it ? https://ibb.co/cvmpyy this is my mesh. If yes, could you guide me ?
     
  5. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Hi! It depends on how you're generating and rendering the mesh, but if it uses the regular Mesh Renderer, you should be fine. I think you should be able to apply the Mask in the editor (white the mesh isn't generated yet, but the Mesh Renderer is already there), and then when you generate the mesh, it will mask automatically. Would that work?
     
  6. aokdigitalmedia

    aokdigitalmedia

    Joined:
    May 23, 2018
    Posts:
    1
    Is it possible to use this with animated sprites? Like have an sprite animated with unity 2d and use its alpha as a mask?
     
  7. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    You mean use an animated Sprite as the Mask itself? Or mask an animated Sprite with a static Mask?
     
  8. mrkarate

    mrkarate

    Joined:
    Dec 4, 2012
    Posts:
    7
    Is it possible to mask a whole camera with this plugin?. I want to create a "fade in" effect for the guitar and notes in this game. I will have the guitar and notes on a camera and the background in other, so I want to use an alpha mask to create a fade in effect.

    Is is possible?
    upload_2018-6-16_21-58-46.png
     
  9. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Well, you can surely mask all of the needed elements (guitar and notes) with our plugin, and you will probably have the effect you're looking for :) Although, you'll have to use a RenderTexture to generate the Mask (and fade it from black to white over time). Hope that helps!
     
  10. kaji_unity

    kaji_unity

    Joined:
    May 21, 2018
    Posts:
    2
    Can I work with TextMeshPro?
     
  11. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    There is a non-released version that supports any shader, including TextMeshPro shaders. There will be a few additional steps needed to set it up, but they're not very complex :) So, you can buy the plugin and then send me a message with your invoice number, and I'll send you the non-released version with custom shader support.
     
  12. lordzeon

    lordzeon

    Joined:
    Jun 1, 2018
    Posts:
    44
    Sorry if this has been asked before, but This Component work with TileMaps?
     
  13. kaji_unity

    kaji_unity

    Joined:
    May 21, 2018
    Posts:
    2
    Wow, Thank you for reply. I'll consider buy it.
     
  14. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Great! :)
     
  15. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    I just chacked, and yes, it does :) However, it wasn't specifically adapted for Tilemaps, so you'll need a couple of additional steps:

    1. Create a new material in the Assets (anywhere within the assets folders). Name it whatever you want (eg. Tilemap-Default) and choose Unlit/Transparent as its shader (no need to assign a texture or anything).
    2. Assign this new material to your Tilemap.

    That's it – if you try to apply a mask to this tilemap now, it will work as intended :)
     
  16. lordzeon

    lordzeon

    Joined:
    Jun 1, 2018
    Posts:
    44
    Sorry for asking again, i bought the plugin and can´t make it work as i want
    i have 2 TileMaps, one would have alpha tiles to "shape" the other tilemap with textures, one thing to consider is that the tilemap with the textures already have a material with normal mapping to have lighting in it, is not standar sprite material.

    i cannot add the AlphaTexture Script to the tilemap because it need a mesh renderer that make conflict with the tile renderer so i tried a Workaround using 3 cameras:
    - one for the Alpha Tilemap only to a texture, i use this texture in a quad with the Alpha Mask script
    - one for the Texture Tilemap only, this texture is used in a unlit material used by the same quad.
    - one main for the Scene which don´t render the Alpha Tilemap or the Texture Tilemap

    this dont work for me, maybe im making a mistake, but the cameras render correctly and the Alpha Mask Script make the quad completely black.

    Of course, i would prefer to use tilemaps directly instead of rendering 2 textures. It is possible to do this with this script?
     
  17. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    You don't need to add the Alpha Mask script to the Tilemap that you're masking. You need to add it to a separate object that works as a Mask (and uses the RenderTexture that you generate from your Alpha Tilemap). However, since you're using a custom shader, your situation sounds more complex that usual. But we will, of course, find a solution for it, too :) Send me a private message, and let's continue there. In the private message please elaborate where you're using the custom shader (because you've mentioned that you're using a custom shader with a normal map, but then you say that you're using an unlit shader on your main Tilemap. So, I'm not sure what shader you're using anymore – an explanation would be very useful).
     
  18. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    HI.

    I can't seem to make this asset to work. Using Unity 2017.4.7

    clicking Apply Mask results in the error :
    Mask applied.

    UnityEngine.Debug:Log(Object)
    ToJ.MaskEditor:ApplyMask() (at Assets/Standard Assets/Alpha Masking/Editor/MaskEditor.cs:440)
    ToJ.MaskEditor:OnInspectorGUI() (at Assets/Standard Assets/Alpha Masking/Editor/MaskEditor.cs:174)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    Error assigning cubemap texture to 2D texture property '_AlphaTex': Dimensions must match
    UnityEngine.Material:SetTexture(String, Texture)
    UIMaterialModifier:ApplyMaterialProperties(Material) (at Assets/Standard Assets/Alpha Masking/UIMaterialModifier.cs:63)
    ToJ.Mask:UpdateUIMaterials(List`1, Matrix4x4, Vector4) (at Assets/Standard Assets/Alpha Masking/Mask.cs:474)
    ToJ.Mask:UpdateMasking() (at Assets/Standard Assets/Alpha Masking/Mask.cs:597)
    ToJ.Mask:LateUpdate() (at Assets/Standard Assets/Alpha Masking/Mask.cs:390)

    It does changes the child's material to "Sprites-Alpha-Mask_WorldCoords"
    but there is no masking happening.
     
  19. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Hi there! From the error it looks like you're assigning a cubemap as the Mask texture. You should use a regular texture (it can be the usual 2D Texture or a RenderTexture, but not a cube map or something like that) :)
     
  20. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Sorry, the cubemap error was my bad.

    But when I got everything set up with no errors, I still don't get any masking happening

    Is this runtime only?

    I am trying to mask Raw Image in UI.
     
  21. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Now that's strange :) Could you try running the game, just in case the Mask didn't update properly?
     
  22. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    oh... it looks like the masking texture doesn't like the sprite.. I put in some non sprite texture and it is doing something now.
     
  23. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    That's interesting. You should be able to assign a Sprite (although, it would be used as a regular texture in the end, and not packed into a sprite sheet), but normally, yes, you should use a regular texture :)
     
  24. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    how strange... when I click on apply... it applies the material changes to the parent of the mask object as well..
     
  25. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    That's a good catch! It seems to be a bug in our plugin – haven't noticed this before, because we usually recommend creating an empty object for the parent of the Mask. Could you do the same on your side? We'll fix this for the next version.
     
  26. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    One more thing. Do I need to attach UIMaterialModifier component to the objects being masked?
    I have my own material made from the masking shader but the doc didn't mention anything about having to attach that component manually as well.
     
  27. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Also, I made my own custom shader from the mask shader ( it's exactly the same , just the name difference for now) but when I use my own custom material, with custom shader, it doesn't seem to work...
     
  28. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    You shouldn't have to do anything manually. We're using UIMaterialModifier for UI elements, so that there wouldn't be any custom materials on the UI. But it's attached automatically. For other type of objects (not UI), this is not used.

    As for making a custom shader, you can do that, but you need to find and change the name in the Mask.cs script, too.
     
  29. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Ugh.. static references.. which means I can only have one masked shader at a time??? Garhh... :(
     
  30. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Well, kind of :) But you can edit the Mask.cs script to check for more shaders (you can even make a public array for that). It should be an easy change! Let me know if you need help with that.
     
  31. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Yeah, I think the plugin will benefit much more by able to support more custom shaders at the same time.
    I have some ui that does multi-pass additive rendering and then normal ones etc..
     
  32. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Will you be able to make this change yourself or do you need help with that? :)
     
  33. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I think you should make the changes and update the plugin along with the bug fix. That way the others can benefit too!
     
  34. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    by the way fragment shader needs to be SV_Target not Color.. This is strict requirement for PS4.
     
  35. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Thanks, we'll edit this. As for supporting multiple shaders, we'll see if we can think of some universally useful way to do this. The vast majority of users don't need this feature (most probably because most of them just don't write custom shaders), so we don't want to clutter the UI. But it's a good idea, so we'll definitely look into this :)
     
  36. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I will test the plugin on consoles and let you know if they work or not.
     
  37. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    That would be super useful, thanks! :)
     
  38. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I can confirm that this asset does indeed work on Switch and PS4. I am still to test on XboxOne. It's pretty cool, we just need the way to add more of our own custom shaders then it is almost as good as it needs to be.
     
  39. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    That's great, thanks for confirming! :) We'll see what we can do about the shaders and let you know.
     
  40. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Hi again! We started looking into this and realized that we already have multiple shader support (including custom shaders)! It's not released, though, because we wanted a confirmation that it actually works and haven't received one yet :) Can you send me a private message with your order number, and I'll send you the updated (non-released) version to test.
     
  41. YardenSG

    YardenSG

    Joined:
    Jun 10, 2018
    Posts:
    3
    Hi DominoOne,
    I have a question to see if your add on will fit our scenario. We have a large list of scrollable objects that we want to fade mask. To avoid performance issues from instantiation all objects are pooled. When objects are outside of the screen they return to the pool and vice versa(meaning their parents change).

    We have tried using another addon for this scenario and this resulted in performance issues. Will AlphaMask fit this scenario? Does it dynamically manage the maskable elements in the hierarchy or do i need to manage them with code?
     
  42. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    I'm not 100% sure that I understand what you mean, but there shouldn't be any problems with moving/enabling/disabling objects :) P. S. Sorry for such a late reply!
     
  43. fmelogno

    fmelogno

    Joined:
    Oct 2, 2016
    Posts:
    24
    Hello and sorry if this question was replied before but I would want to know if right now the asset support TextMesh pro. Thank you.
     
  44. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Hi. The public version doesn't, but we have a version that we're planning to publish soon, which supports any shader (not specific to TextMeshPro). There are a few manual steps involved to make the shaders work, but it's described in the manual. If you want to try it out, send me your invoice/purchase number to a private message, and I'll give you the new version. If you don't have the asset yet, you'll have to buy it first :)
     
  45. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Good news – a new version has just been approved! Alpha Mask 2.5 is here.

    What's new in this version:
    - Supports any shader (including TextMesh Pro) by simply copying a few lines of code (thoroughly described in the documentation)!
    - Tilemap support added.

    Buy it here
     
  46. daniellllll

    daniellllll

    Joined:
    Sep 21, 2015
    Posts:
    2
    hello,I imply copying a few lines of code (thoroughly described in the documentation)! ,so My mask can not mask the TextMeshProUGUI text why????
     

    Attached Files:

  47. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Could you send us the cginc and shader files that you are trying to update over e-mail? We'll check them out and see if you have missed something :)
     
  48. Betzalel

    Betzalel

    Joined:
    Dec 3, 2017
    Posts:
    22
    hi! i love this asset! im having trouble making a mask occur in more than one area in a side scroll scene. im an absolute novice. can you point me in the right direction so i can solve this issue? im ataching an image of what im trying to accomplish. it seems that the alpha render camera can only make the mask happen in one area. when i tried making another alpha quad and mask elswhere it would send the alpha masked circle far away.
     

    Attached Files:

  49. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Hehe, nice drawing! ;D I'm not sure I fully understand your use-case, though. Do I understand correctly that you need multiple masks? If so, where/when do you need them? When/how do you uncover the caves?
     
  50. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Hello,
    I ran into a problem: my masked UI Image was fading in via code. Alpha Mask obviously stored the first state of the color and multiplied it with the vertex color (so the vertex color is multiplied with the initial-state-vertex-color...). That was keeping my image invisible.

    I compared it with shaders I wrote and I fixed it. A side effekt: The alpha value of the masked image is always correct now.

    To fix it, open Sprites-Alpha-Mask-WorldCoords. Then remove the following line:
               float4 _Color; //from properties
    <- remove
    and replace in the vertex shader the following line:
                   o.color = v.color * _Color;
    <- replace ...
    with:
                   o.color = v.color;
    <- ... with this