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的效果


fdd904b67e934e24b10e5c9c84392fc2[1].jpg
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容