//原Pass不变,插入一个Pass,用于显示模型遮挡部分
Shader "Test/Model_XRay"
{
Properties
{
_MainTex ("Diffuse (RGB)", 2D) = "grey" {}
_Color("Color (RGBA)", Color) = (1,1,1,1)
_XRayColor("XRay Color", Color) = (1,1,1,1)
}
SubShader
{
Tags
{
"RenderType"="Opaque"
"Queue"="AlphaTest+1"
"IgnoreProjector"="True"
}
LOD 200
Fog { Mode Off }
//渲染X光透视效果的Pass
Pass
{
Blend SrcAlpha One
ZWrite Off
ZTest Greater
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Lighting.cginc"
fixed4 _XRayColor;
struct v2f
{
float4 pos : SV_POSITION;
float3 normal : normal;
float3 viewDir : TEXCOORD0;
};
v2f vert (appdata_base v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.viewDir = ObjSpaceViewDir(v.vertex); //计算顶点到相机的向量
o.normal = v.normal;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
//利用法线跟视线向量的点乘值计算颜色浓度
float3 normal = normalize(i.normal);
float3 viewDir = normalize(i.viewDir);
float rim = 1 - dot(normal, viewDir);
return _XRayColor * rim;
}
ENDCG
}
Pass
{
CGPROGRAM
//定义顶点/片元着色器代码
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
//定义顶点着色器的输入
struct a2v
{
float4 vertex : POSITION;
float2 uv :TEXCOORD0;
};
//定义顶点着色器的输出、片元着色器的输入
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv:TEXCOORD0;
};
v2f vert (a2v v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
return tex2D(_MainTex,i.uv);
}
ENDCG
}
}
FallBack "Diffuse"
}
评论