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

 

12 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
        to
        Blend OneMinusSrcAlpha SrcAlpha
        It kinda work. But it’s messing with my shadow on another image. Removing it and placing hard black border:)

  3. My name is Angelina. And I am a professional Content writer with many years of experience in writing.

    My interest is to solve problems related to writing. And I have been doing it for many years. I have been with several organizations as a volunteer and have assisted clients in many ways.
    My love for writing has no end. It is like the air we breathe, something I cherish with all my being. I am a full-time writer who started at an early age.
    I’m happy that I`ve already sold several copies of my books in different countries like USA, Russia and others too numerous to mention.
    I also work in a company that provides assistance to many students from different parts of the world. Clients always come to me because I work no matter how hard their projects are. I help them to save money, because I feel happy when people come to me for professional help.

    Professional academic Writer – Angelina – How to Teach Students to Write an Essay Confederation

  4. Hi and welcome to my website . I’m Jeanne Denton.
    I have always dreamed of being a novelist but never dreamed I’d make a career of it. In college, though, I aided a fellow student who needed help. She could not stop complimenting me . Word got around and someone asked me for writing help just a week later. This time they would pay me for my work.
    During the summer, I started doing research paper writing for students at the local college. It helped me have fun that summer and even funded some of my college tuition. Today, I still offer my writing services to students.

    Professional Writer – Jeanne – http://www.thunderbirdresearch.org Company

Leave a Reply

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