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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值