unity3d 实现遮罩效果

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:
  1. Shader "Depth Mask" {
  2.     SubShader {
  3.         Tags {"Queue" = "Geometry-10" }
  4.         Lighting Off
  5.         ZTest LEqual
  6.         ZWrite On
  7.         ColorMask 0
  8.         Pass {}
  9.     }
  10. }
复制代码

工程下载:http://pixelplacement.com/wp-content/uploads/2011/02/Masking.zip
原文来自
http://pixelplacement.com/2011/02/15/masking-in-unity/

 

转自移动终端开发网www.yeehot.com

你可能感兴趣的:(unity3d 实现遮罩效果)