Unity的遮罩技術簡述

來源:互聯網
上載者:User

遮罩技術是一個基本的技術方法,有很多很多中用法.你可以在Flash中經常看到遮罩的使用,它可以另一些視覺元素更加驚豔.當我看到Unity中沒有包含任何幾何體和圖片的遮罩技術很不爽,不過,幸運的我找到瞭解決方案,就是"Depth Mask"著色器.

先看看著色器的代碼,沒錯,非常短.

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)
        }
    }
}

如果你想更改任何一個物體材質的特性座遮罩(紋理,顏色等等)將是失敗的,除非你用SetPass()去設定著色器,關於這個方法的文檔在這(http://unity3d.com/support/documentation/ScriptReference/Material.SetPass.html).

樣本項目下載:http://pixelplacement.com/wp-content/uploads/2011/02/Masking.zip

原文:http://pixelplacement.com/2011/02/15/masking-in-unity/
轉載請註明來自1Vr.Cn

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.