Shader "Custom/Grab" {
SubShader {
Tags { "Queue" = "Transparent" }
LOD 200
GrabPass{}
Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _GrabTexture;
struct v2f{
float4 pos:POSITION;
float2 uv:TEXCOORd0;
};
v2f vert(appdata_base v){
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
//红字部分是一个常用法:根据顶点的投影坐标,获取对应的屏幕纹理的纹理坐标
float4 screenUV = ComputeGrabScreenPos(o.pos);
o.uv = screenUV.xy/screenUV.w;
return o;
}
fixed4 frag(v2f i):Color{
fixed4 texCol = tex2D(_GrabTexture, i.uv);
return 1-texCol;
}
ENDCG
}
}
}