unity3d shader ar任意门(传送门)

通道遮罩 ColorMask

ColorMask可以让我们制定渲染结果的输出通道,而不是通常情况下的RGBA这4个通道全部写入。可选参数是 RGBA 的任意组合以及 0, 这将意味着不会写入到任何通道,可以用来单独做一次Z测试,而不将结果写入颜色通道

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

实现如图效果,前面的cube改为DepthMask的shader,实现在前面的cube透明,但是仍然挡住了后面cube的效果
unity3d shader ar任意门(传送门)_第1张图片

你可能感兴趣的:(Unity3d,Shader,Unity3d,Shader)