前言
暂时不太方便上截图,有时间会补上。效果是被遮挡的部分会以设定的颜色亮起,且边缘高亮.
shader
直接看shader怎么写的。
Shader "Exercise/TransparentShader-1" {
Properties {
_MainTex("Texture", 2D) = "white" {}
_Color("Color", Color) = (1,1,1,1)
}
SubShader {
Tags { "RenderType"="Opaque" "IgnoreProjector"="True" "Queue"="Geometry"}
Pass {
ZWrite Off
Blend SrcAlpha One
ZTest Greater
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
fixed4 _Color;
struct v2f {
float4 vertex : SV_POSITION;
float3 normal: normal;
float3 viewDir: TEXCOORD0;
}
v2f vert(appdata_base v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.normal = v.normal;
o.viewDir = ObjSpaceViewDir(v.vertex);
return o;
}
fixed4 frag(v2f i) : SV_Target {
fixed3 normal = normalize(i.normal);
fixed3 viewDir = normalize(i.viewDir);
float rim = 1 - dot(normal, viewDir);
return _Color * rim;
}
ENDCG
}
Pass {
ZWrite On
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
sampler2D _MainTex;
float4 _MainTex_ST;
struct v2f {
float4 vextex : POSITION;
float2 uv: TEXCOORD0;
}
v2f vert(appdata_base v) {
v2f o;
o.vertex = v.vertex;
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
}
fixed4 frag(v2f i) : SV_Target {
return tex2D(_MainTex, i.uv);
}
ENDCG
}
}
FallBack "Diffuse"
}
结语
后续还会继续更新对于半透明情况处理的shader。如果以上有错误之处,还请指正