改成不被模型遮挡
时间: 2023-09-05 08:09:04 浏览: 43
如果您想让 Additive Shader 不受其他模型遮挡,可以在 SubShader 中添加一个 ZTest Off 的指令,这将关闭深度测试。同时,您还需要将渲染队列设置为“Overlay”,这样可以确保该对象总是在其他对象之上渲染。下面是一个示例代码:
```
Shader "Custom/AdditiveOverlay"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (1,1,1,1)
}
SubShader
{
Tags {"Queue"="Overlay" "RenderType"="Opaque"}
Pass
{
Blend One One
Cull Off
ZTest Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _Color;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// 从纹理中采样颜色
fixed4 col = tex2D(_MainTex, i.uv);
// 将颜色乘以颜色属性
col *= _Color;
// 返回颜色并进行加法混合
return col * 2;
}
ENDCG
}
}
FallBack "Diffuse"
}
```
请注意,这种方式会导致新的对象始终绘制在屏幕的最上层,因此如果您需要在场景中使用多个 Additive Shader 对象,请注意它们之间的遮挡关系。