Search Unity

[Released] Sprite Mask - masking system for Unity Sprite

Discussion in 'Assets and Asset Store' started by PoL231, Jan 21, 2015.

  1. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    Hi pep_dj,

    Yes, it is possible to achieve that. Just use your character sprite as a mask for shadow sprite.
     
    pep_dj likes this.
  2. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    537
    is it possible to use your tool to blur actual game part wherever I have a sprite in front?
     
  3. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    Hi rahuxx,

    SpriteMask can be used only for masking Renderers, without any extra pixel effects. You can only cut out pixels (just like UI Mask).
     
  4. pep_dj

    pep_dj

    Joined:
    Nov 7, 2014
    Posts:
    179
    Thanks. I've just bought your plugin. To achieve the effect I said, I'll need to invert the mask, right? I can't find that option. I read in previous posts in this thread that you have a version with it. Can I send you in a private message my invoice number so you can send me the version with the invert option?
     
  5. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    Yes, just send my your Invoice number.
     
    pep_dj likes this.
  6. pep_dj

    pep_dj

    Joined:
    Nov 7, 2014
    Posts:
    179
    Thanks, I've just sent you a message
     
  7. CoderPro

    CoderPro

    Joined:
    Feb 21, 2014
    Posts:
    327
    I am using Unity 5.1.x to import your package. But after import it, shader: SpriteDefault and SpriteMash show warning message: "No subshaders can run on this graphics card". In the Unity Editor, i am using Android mode. How can i fix it ?
     
  8. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    Hi, it works perfect in Unity 5.1.1 (Android) on my side:



    Do you have still any problems with SpriteMask?
     
  9. pep_dj

    pep_dj

    Joined:
    Nov 7, 2014
    Posts:
    179
    Thanks. It works as expected :)

    The only thing is I had to increment "order in layer" for the masked sprite in order to get it working. I have: Character (Sprite) -> Mask (Inverted, Type = Sprite) -> Shadow (Sprite). To get it working I need to set Shadow order > Mask order. Even in your inverted scene example, I had to increment order in layer to get it working.

    Because I need the sprite I use for masking to be the same as the character object has, in Update method of character script, I'm doing: spriteMask.sprite = spriteRenderer.sprite; and as I said, it works like a charm! :D

    I'm going now to rate it at Unity Store, thanks :)
     
  10. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    I'm happy to hear that it works for you. Thanks for rating and just let me know if you need more help:).
     
    pep_dj likes this.
  11. Deleted User

    Deleted User

    Guest

    We are adding sprite renderers to mask on runtime. But we could not figure out how to remove sprite renderer from being masked without disabling the mask.

    How we add is:
    teleportFrom.TeleportMask.updateSprites(blockUi.BlockSprite.transform);

    Our current solution (we are not sure if it will cause a memory leak)
    blockUi.BlockSprite.material = defaultSpriteMaterial;
     
    Last edited by a moderator: Jun 24, 2015
  12. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    Hi Kaan Yy,

    Just set default sprite material to SprieRenderer and that's it.
     
  13. Deleted User

    Deleted User

    Guest

    Hi PoL,

    Thank for your reply. I have one more question; if I set the material back to original; draw call increases: (it looks like unity creates a new material). How can I do it with using same instance?

    var defaultMaterial = blockUi.BlockSprite.material ;
    teleportFrom.TeleportMask.updateSprites(blockUi.BlockSprite.transform);
    teleportFrom.TeleportMask.updateSprites(blockUi.HintDecor.transform);
    ...
    ...
    //now set back to original
    blockUi.BlockSprite.material = def;
    blockUi.HintDecor.material = def;
     
  14. Deleted User

    Deleted User

    Guest

    ------

    Ok I found it. You should keep reference to sharedMaterial. I'm replying here for those who may encounter with the same problem:

    originalMaterial = BlockSprite.sharedMaterial;
     
  15. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    Hi, the only way to set the same material is to cache 'default sprite material' before masking the sprite:
    Code (CSharp):
    1. // Cache material
    2. Material def = spriteRenderer.sharedMaterial;
    3.  
    4. // Masking
    5. spriteRenderer.transform.SetParent(spriteMask);
    6. spriteMask.updateSprites(spriteRenderer.transform);
    7.  
    8. // Unmasking
    9. spriteRenderer.transform.SetParent(null);
    10. spriteRenderer.sharedMaterial = def;
     
  16. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    Yep that's it! :)
     
  17. liamjpeth

    liamjpeth

    Joined:
    Jul 24, 2014
    Posts:
    1
  18. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    Hi, no problem...

    Mask consist of many parts. Each part is a regular SpriteRenderer (it can be any Renderer), and all parts have the same Material. That makes possible to set Stencil buffer value from many object at the same time. Further more, the whole mask "costs" only 1 draw call, because all parts (SpriteRenderer) are batched by Unity.

    Blood effect is a regular SpriteRenderer. All sprites have the same Material so they also are batched by Unity.

    To get that effect you need a beta version of SpriteMask.
     
  19. turndapage

    turndapage

    Joined:
    Jun 25, 2015
    Posts:
    12
    Hi. I recently purchased your sprite mask script, and am having trouble solving an issue. I am using a circular mask and am dynamically adding a sprite under it during the game. The spite and position under the mask can vary a lot.

    I want to create a polygon collider around the clipped sprite. How can I get a path for the SetPath function? Creating one around the sprite uses that parts that are hidden as well.

    Thank you for the help!
     
  20. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    Correct me if I'm wrong, but you are asking me how to create a path around a circle sprite. Unfortunately I don't know anything about creating paths based on sprite pixels. My suggestion would be to create a circle mesh and use it for masking. Next you could use something like mesh collider to create a circle collider. But that's just my loose thought.
     
  21. Kappe

    Kappe

    Joined:
    May 2, 2014
    Posts:
    5
    Hi. I was wondering if it's possible to mask a MeshRenderer with this system?
     
  22. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    Hi Kappe,

    No problem, you can mask any renderer, but keep in mind that material shader associated with given renderer must support Stencil buffer operations. If given shader doesn't do that, you can add support with few lines of code.
     
  23. vinodvijayan

    vinodvijayan

    Joined:
    Mar 7, 2013
    Posts:
    10
    Hi, I have specific requirement for my project. After seeing your demo scene i was thinking whether i could buy your asset.
    My requirement is that i have a large sprite and a small sprite, the small sprite have to be on top of the larger sprite, and i need to mask my small sprite so that the small sprite will not be visible outside of the large sprite. I will be restricting the movement of the small sprite inside the large sprite boundaries. Also after going through the discussion i could see that the shader i use must support stencil buffer operations. Now i must have the standard shader of unity 5 to be on the larger sprite, small sprite could have any shader. Can i achieve this with your asset.
    Attaching a image which i would like to achive, I will use only sprites alphamask.png
    The green and red are the small sprites with same dimensions and the greens effect is what i want to achieve
     
  24. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    Hi vinodvijayan,

    Yes SpriteMask will help you. Just create Rectangle mask with size of red rectangle and all small sprites will by masked (see example '01 - Rectangle mask' in SpriteMask package). Only on small sprite shader will be changed.

    If you need more help just let me know.
     
  25. vinodvijayan

    vinodvijayan

    Joined:
    Mar 7, 2013
    Posts:
    10

    Did you refer the red rectangle as the large rectangle or the small one, Also can i use this for irregular shapes like a texture of a dress sprite
    Thanks
    Vinod
     
  26. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    I mean the big one. You can have mask of any shape by using texture or sprite. In this DEMO you have a mask in the shape of a star.
     
  27. vinodvijayan

    vinodvijayan

    Joined:
    Mar 7, 2013
    Posts:
    10
    I purchased SpriteMask today and it worked as per my requirement. Thanks PoL
     
  28. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    You are welcome :).
     
  29. vinodvijayan

    vinodvijayan

    Joined:
    Mar 7, 2013
    Posts:
    10
    Hi PoL,
    How many discrete masks can i create in a scene, is it limited to 127. If we can create more than that could you please explain how?
     
  30. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    The limitation is the size of Stencil buffer cell - 8 bits. If you have 1-level masking so you can have 127 individual masks. Theoretical you can have unlimited number of mask by clearing Stencil buffer. For example you have 127 individual mask, next you clear Stencil buffer and you can have another 127 masks, than you can clear Stencil buffer again and so on...

    Very important in this scenario is to set proper sorting order. For example first 127 masks have sorting order from 0 to 1000, the clearing Stencil buffer draw call should have sorting order set to e.g. 1001, next 127 masks should have sorting order e.g. from 1002 to 2000, and so on...

    Current release of Sprite Mask doesn't have that kind of functionality, but if you are interested we can make a deal by creating a extended version.
     
  31. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    Maybe just describe me your use case. Maybe there is no need to have so many mask at the same time.
     
  32. vinodvijayan

    vinodvijayan

    Joined:
    Mar 7, 2013
    Posts:
    10

    I have a bunch of dress textures which can be combined together to form a dress model. Now I have options to apply different textures and colors as details on the dress textures. Now I am adding some kind of small designs which should be masked inside the sprite boundaries which i am able to achieve with your SpriteMask component. These designs can be saved for future references. Now the user when launches and looks for all the edited or modeled dresses, this draws the scene with all the dresses where the user can scroll and select each dress for further editing. Each dress might have 1 - 5 pieces. So if a design is added to a dress piece, I have to have a mask for the piece. In that case , I may require a maximam of 5 masks per dress.

    In the Images you could see that there are two designs in a single dress type. Now i can have n number of designs for each dress which needs to be displayed in the first layout image.

    Can i reset the bool[] for stencilids if it reaches the limit.
     
    Last edited: Jul 18, 2015
  33. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    In my opinion you can use (theoretical) only one mask that consist of many parts, just like in this DEMO. In the demo scene there is only one SpriteMask component but all tree take a part i masking.

    To get that example working you need beta release of SpriteMask with I can send you after you send me your Invoice number via private message.
     
  34. vinodvijayan

    vinodvijayan

    Joined:
    Mar 7, 2013
    Posts:
    10


    How can i send you a private message ?
     
  35. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    Check your Inbox on your account.
     
  36. vinodvijayan

    vinodvijayan

    Joined:
    Mar 7, 2013
    Posts:
    10

    Sorry that i couldn't find any contact info in my mail inbox. And i could not find the Inbox in my unity account. Could you pls send ur contact to my personal mailid (vijvin57@gmail.com) so that i can forward the invoice number.
     
  37. Aladine

    Aladine

    Joined:
    Jul 31, 2013
    Posts:
    195
    Hi i have two questions :

    1) is it possible to mask from the inside out ?
    2) can we use the mask opacity to create transparent mask effect ?

    like this :



    A useful example for this is making "darkness" effect in 2d top-down game :


    Thank you
     
  38. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    Hi Aladine,

    Somthing like THIS ? I'm using 2x Inverted mask.
     
  39. vinodvijayan

    vinodvijayan

    Joined:
    Mar 7, 2013
    Posts:
    10
    Hi

    I came across another issue. could u please see to this example project, where if u add more than 1 child to any color and then drag one child to another color, all other children disappears.
    As i am dragging the child i am changing the mask parent of the child to the next colors mask parent. As the mask parent is updated to a new one , i call the UpdateTransform on that mask with the childs transform. At this point all the children of the mask parent on which the child was initially created disappears. May be i am not explaining this correctly, So uploading a package with the above functionality. Please add the Spritemask package to the project. and Just add 2 child to any one color and drag one of the children to the next color
     

    Attached Files:

  40. Aladine

    Aladine

    Joined:
    Jul 31, 2013
    Posts:
    195
    will buy your package as soon as possible !!

    And thank you for the great support :)
     
  41. vinodvijayan

    vinodvijayan

    Joined:
    Mar 7, 2013
    Posts:
    10

    Hi PoL
    Could you please reply on this problem i am facing when i am moving a child from a MaskA to MaskB all the children of MaskA are masked by MaskB. When i am changing the parent of child from MaskA to MaskB i am calling MaskB.UpdateSprites(child.transform).
     
  42. Goodev

    Goodev

    Joined:
    Feb 19, 2013
    Posts:
    25
    I sent e-mail to support@truesoft.pl,

    because I want to get custom assets that can mask 'Spine' object.

    Please check e-mail.
     
  43. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    I've just sent an answer...
     
  44. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    To get Inverted masking you need beta release of SpriteMask. Send me your Invoice number via PM and I will send you your package.
     
  45. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    Hi, the problem is that when you move your sprite to another SpriteMask parent, the new parent is changing moved sprite material properties. I will send you an updated SpriteMask package soon.
     
  46. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    Check your e-mail.
     
  47. vinodvijayan

    vinodvijayan

    Joined:
    Mar 7, 2013
    Posts:
    10

    Will make changes as you suggested. thanks for your continued support.
     
  48. stevelie

    stevelie

    Joined:
    Feb 6, 2015
    Posts:
    15
    Hi There,

    Is there a way to make sprite mask only working on each its parent gameobject? lets say I have 2 gameobject with sprite mask in it. I want the masking only affect the sprite inside each gameobject and not with the sprite inside another gameobject.
     
  49. PoL231

    PoL231

    Joined:
    Jun 27, 2014
    Posts:
    148
    Hi stevelie,

    Such functionality is implemented already in the beta release of SpriteMask. You just have to add component SkipMasking to a game object, and that game object and all its childs will be ignored by the SpriteMask component. If you have already beta release of SpriteMask just use it, and if not send my you Invoice number via PM and I will send you a copy of beta release.
     
  50. stevelie

    stevelie

    Joined:
    Feb 6, 2015
    Posts:
    15
    dropped you a PM via conversation! :)