注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Faye Euler's blog

技術交流歡迎留言

 
 
 

日志

 
 

Unity3d 遮罩技术 Masking in Unity  

2011-08-07 19:11:21|  分类: Unity3D |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
Unity3d 遮罩技术 Masking in Unity - Faye - Fayes blog

 

遮罩技术是一个基本的技术方法,有很多很多中用法.你可以在Flash中经常看到遮罩的使用,它可以另一些视觉元素更加惊艳.当我看到Unity中没有包含任何几何体和图片的遮罩技术很不爽,不过,幸运的我找到了解决方案,就是"Depth Mask"着色器.

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”.

先看看着色器的代码,没错,非常短.
Shader "Depth Mask" {
    SubShader{
        ColorMask 0
        Pass {}
    }
}
如果用了多维材质,你需要像下面这样写:
Shader "Depth Mask Complex"
{
    SubShader
    {
        Tags {"Queue" = "Background"}
        Blend SrcAlpha OneMinusSrcAlpha
        Lighting Off
        ZWrite On
        ZTest Always
        Pass
        {
            Color(0,0,0,0)
        }
    }
}

Unity3d 遮罩技术 Masking in Unity - Faye - Fayes blog

 
如果你想更改任何一个物体材质的特性座遮罩(纹理,颜色等等)将是失败的,除非你用SetPass()去设置着色器,关于这个方法的文档在这(http://unity3d.com/support/documentation/ScriptReference/Material.SetPass.html).

If you change any aspects of the material of an object you are trying to mask (texture, colors, etc…) the “Depth Mask” will fail unless you run the SetPass() of the object that is carrying the actual “Depth Mask” shader. This method is documented here.

You can grab the example project shown in this post here.

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


 

  评论这张
 
阅读(3750)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018