通道遮罩 ColorMask可以讓我們制定渲染結(jié)果的輸出通道,而不是通常情況下的RGBA這4個通道全部寫入??蛇x參數(shù)是 RGBA 的任意組合以及 0, 這將意味著不會寫入到任何通道,可以用來單獨做一次Z測試,而不將結(jié)果寫入顏色通道
Shader "DepthMask" {
SubShader {
// Render the mask after regular geometry, but before masked geometry and
// transparent things.
Tags {"Queue" = "Geometry-10" }
// Turn off lighting, because it's expensive and the thing is supposed to be
// invisible anyway.
Lighting Off
// Draw into the depth buffer in the usual way. This is probably the default,
// but it doesn't hurt to be explicit.
ZTest LEqual
ZWrite On
// Don't draw anything into the RGBA channels. This is an undocumented
// argument to ColorMask which lets us avoid writing to anything except
// the depth buffer.
ColorMask 0
// Do nothing specific in the pass:
Pass {}
}
}
實現(xiàn)如圖效果,前面的cube改為DepthMask的shader,實現(xiàn)在前面的cube透明,但是仍然擋住了后面cube的效果

fdd904b67e934e24b10e5c9c84392fc2[1].jpg