找回密码
 立即注册
查看: 142|回复: 0

Unity 粒子渲染层级出错!!!

[复制链接]
发表于 2022-11-4 08:43 | 显示全部楼层 |阅读模式

如图所示,美术添加个粒子特效,但是有个特效却显示在了UI上方,正确的应该是特效在UI下方,被遮挡部分不显示才对。

经查找分析发现是shader的问题,为什么呢?

因为我们的界面下方是scrollview,scrollview是用了模板测试的,但是看错误的粒子shader却没有模板的参数设置,可能是由于模板测试成功了,导致uI上方的粒子也被渲染出来了。
如下所示
Shader "Mobile/Particles/Additive" {
Properties {
    _MainTex ("Particle Texture", 2D) = "white" {}
}

Category {
    Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
    Blend SrcAlpha One
    Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) }
   
    BindChannels {
        Bind "Color", color
        Bind "Vertex", vertex
        Bind "TexCoord", texcoord
    }

    SubShader {
        Pass {
            SetTexture [_MainTex] {
                combine texture * primary
            }
        }
    }
}
}添加了模板参数后,如下所示:
Shader "Mobile/Particles/Additive" {
Properties {
    _MainTex ("Particle Texture", 2D) = "white" {}
}

Category {
    Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
    Blend SrcAlpha One
    Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) }
   
    Stencil
   {
      Ref 1
      Comp Equal
      Pass Replace
      ReadMask 1
      WriteMask 0
   }

    BindChannels {
        Bind "Color", color
        Bind "Vertex", vertex
        Bind "TexCoord", texcoord
    }

    SubShader {
        Pass {
            SetTexture [_MainTex] {
                combine texture * primary
            }
        }
    }
}
}模板测试正常了,特效也正常显示了。



如果对你有帮助,欢迎点赞+关注

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-7-2 07:18 , Processed in 0.092007 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表