Best way to mask an image (PNG, etc) in Unity...

This is one of those annoying things that is so trivial (and fast) when native programming and so ad-hoc (and slow!) in Unity

24699-maskexamp.png

24700-final.png

Now 2014 what’s the best way to do this?

A really common method on the wiki?

Some new function in Unity I don’t know about as usual?

Wait until Apportable ports CGImageCreateWithMask to Unity?

Any ideas?

BTW you’ve got to love the dog image - it’s the classic image for this when people are discussing how to do it on native QA boards! :slight_smile:

Masks can be made with a simple shader which then gets applied to some geometry. I stick that above want I want to mask and use a camera set to “Depth only”. Anything below that geometry is not rendered.

as described here…

http://pixelplacement.com/2011/02/15/masking-in-unity/

so the shader code is

Shader "Depth Mask" {
    SubShader {
        Tags {"Queue" = "Geometry-10" }       
        Lighting Off
        ZTest LEqual
        ZWrite On
        ColorMask 0
        Pass {}
    }
}