在unity里面为啥写好的顶点着色的shader代码在编辑器下能正常运行,开始运行游戏shader就感觉没有起到正常的作用呐。
编辑模式下:
运行模式下:
代码:
Shader "Unlit/wxy_transparent开启深度写入"
{
Properties
{
_MainTex("MainTex", 2D) = ""{}
_AlphaScale("AlphaScale", Range(0,1)) = 1
}
SubShader
{
Tags{ "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Pass
{
//开启深度写入
ZWrite On
//忽略颜色
ColorMask 0
}
Pass
{
Tags{ "LightMode" = "ForwardBase" }
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "Lighting.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
fixed _AlphaScale;
struct v2f
{
float4 pos:SV_POSITION;
float2 uv:TEXCOORD0;
};
v2f vert (appdata_base v)
{
v2f data;
data.pos = UnityObjectToClipPos(v.vertex);
data.uv = v.texcoord.xy * _MainTex_ST.xy + _MainTex_ST.zw;
return data;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 texColor = tex2D(_MainTex, i.uv);
return fixed4(texColor.rgb, texColor.a * _AlphaScale);
}
ENDCG
}
}
}