Shader "Custom/Billboard"
{
Properties
{
_MainTex("MainTex", 2D) = ""{}
}
SubShader
{
Tags{"Queue"="Transparent" "RenderType"="Transparent" "IgnoreObjector"="Ture"}
// Cull Off
pass
{
Tags{"LightMode"="ForwardBase"}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert(appdata_base v)
{
v2f f;
float3 center = float3(0,0,0);
half3 viewDir = mul(unity_WorldToObject, float4(_WorldSpaceCameraPos,1)).xyz;
half3 normalDir = normalize(viewDir - center);
half3 upDir = abs(normalDir.y) > 0.999 ? float3(0,0,1) : float3(0,1,0);
half3 rightDir = normalize(cross(normalDir, upDir));
upDir = normalize(cross(rightDir, normalDir));
// float3 localVertex = v.vertex.x * rightDir + v.vertex.y * upDir + v.vertex.z * normalDir;
float3 localVertex = v.vertex - center;
localVertex = center + localVertex.x * rightDir + localVertex.y * upDir + localVertex.z * normalDir;
f.pos = UnityObjectToClipPos(float4(localVertex, 1));
f.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
return f;
}
fixed4 frag(v2f i) : SV_TARGET
{
fixed4 col = tex2D(_MainTex, i.uv);
return col;
}
ENDCG
}
}
}