billboard Shader待研究下
1 Shader "Tut/Project/Billboard_1" { 2 Properties { 3 _MainTex ("Base (RGB)", 2D) = "white" {} 4 } 5 SubShader { 6 Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } 7 pass{ 8 Cull Off 9 ZTest Always 10 Blend SrcAlpha OneMinusSrcAlpha 11 CGPROGRAM 12 #pragma vertex vert 13 #pragma fragment frag 14 #include "UnityCG.cginc" 15 sampler2D _MainTex; 16 struct v2f { 17 float4 pos:SV_POSITION; 18 float2 texc:TEXCOORD0; 19 }; 20 v2f vert(appdata_base v) 21 { 22 v2f o; 23 float4 ori=mul(UNITY_MATRIX_MV,float4(0,0,0,1)); 24 float4 vt=v.vertex; 25 vt.y=vt.z;//这个平面是沿xz平面 展开的 26 vt.z=0;//所以只关心其平面上的信息 27 28 //通过加上Object Space的原点在ViewSpace的信息,保持其透视大小 29 vt.xyz+=ori.xyz;//result is vt.z==ori.z ,so the distance to camera keeped ,and screen size keeped 30 o.pos=mul(UNITY_MATRIX_P,vt); 31 32 o.texc=v.texcoord; 33 return o; 34 } 35 float4 frag(v2f i):COLOR 36 { 37 return tex2D(_MainTex,i.texc); 38 } 39 ENDCG 40 }//endpass 41 } 42 }