Masking and clipping textures in Unity 5.4, NGUI 3.9.8

Two and a half years ago I made http://nickithansen.dk/masking-and-clipping-textures-using-shaders-in-ngui/ 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

 

5 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.

Leave a Reply

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