Masking and clipping textures in Unity 5.4, NGUI 3.9.8

Two and a half years ago I made which in the mean time has broken in various ways. Ankh, in the comments, was kind enough to remind me to do something about that, so here is a new version that works in the newest versions of Unity3D and NGUI.

To use it, you create a custom material for your texture and assign it to a UITexture inside your clipping panel as you would a normal texture or sprite. Be sure to use the “Custom/MaskClipShader” shader for the material, and there you go. It accounts for soft clipped edges as well.

uitexture custommaterial

And here’s the unclipped version, which only masks a UITexture


10 thoughts on “Masking and clipping textures in Unity 5.4, NGUI 3.9.8

  1. Thank you very much Nicki.
    If you have a syntax error line 21, pay attention to the minus sign “-“, I replaced it with the one on my keyboard and the unclipped version works fine.

  2. ditto for unclipped version. With clipped version get this compile error
    Failed to create DX11 vertex declaration; something wrong with vertex shader input data? (hr=80070057)

    1. Ok so it seems when you copy/paste the code, it inserts a space between the ‘-‘ and the 1. That’s all that happens. Otherwise, it still works in Unity 5.5.1 and NGUI 3.11.

      1. Yes, it is. But not an option. I have 4k pics, and they must remain this way. Doubling it to 8k in app is crazy:)
        I have made a trick though, changed:
        Blend SrcAlpha OneMinusSrcAlpha
        Blend OneMinusSrcAlpha SrcAlpha
        It kinda work. But it’s messing with my shadow on another image. Removing it and placing hard black border:)

Leave a Reply to Nicki Cancel reply

Your email address will not be published. Required fields are marked *