Masking is a fundamental technique that has hundreds of usages. Just take a look through some of the Flash work in my portfolio and you’ll see where masking really shines with respect to animating the introducing of visual elements. Coming from a Flash background, I was dumbfounded when I realized Unity didn’t have any technique for masking geometry and images. Luckily I finally found the answer in the “Depth Mask” shader.Though the “Depth Mask” shader is Unity’s answer to masking its not without it quirks if you are looking for a 1:1 comparison with the traditional 2D mask. The way this shader works is whatever geometry is utilizing it will essentially hide whatever is behind it. This means EVERYTHING behind it. The best way to constrain the effects of this is by layering cameras that specifically render masked “scenarios”.
The actual code for the a depth mask shader is short and sweet:
复制代码
The actual code for the a depth mask shader is short and sweet:
- Shader "Depth Mask" {
- SubShader {
- Tags {"Queue" = "Geometry-10" }
- Lighting Off
- ZTest LEqual
- ZWrite On
- ColorMask 0
- Pass {}
- }
- }
工程下载:http://pixelplacement.com/wp-content/uploads/2011/02/Masking.zip
原文来自
http://pixelplacement.com/2011/02/15/masking-in-unity/
转自移动终端开发网www.yeehot.com