You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
3.2 KiB
104 lines
3.2 KiB
Shader "MyShader/LookAtCamera"
|
|
{
|
|
Properties
|
|
{
|
|
_MainTex("Main Tex", 2D) = "white" {}
|
|
_Color("附加颜色", Color) = (1, 1, 1, 1)
|
|
_VerticalBillboarding("强度", Range(0, 1)) = 1
|
|
_Xscale("X轴缩放",float) = 1
|
|
_Yscale("Y轴缩放",float) = 1
|
|
}
|
|
SubShader
|
|
{
|
|
Tags {"Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "DisableBatching" = "True"}
|
|
|
|
Pass
|
|
{
|
|
Tags { "LightMode" = "ForwardBase" }
|
|
|
|
ZWrite Off
|
|
ZTest Always
|
|
|
|
Blend SrcAlpha OneMinusSrcAlpha
|
|
Cull Off
|
|
|
|
CGPROGRAM
|
|
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
|
|
#include "Lighting.cginc"
|
|
|
|
sampler2D _MainTex;
|
|
float4 _MainTex_ST;
|
|
fixed4 _Color;
|
|
fixed _VerticalBillboarding;
|
|
half _Xscale;
|
|
half _Yscale;
|
|
struct a2v
|
|
{
|
|
float4 vertex : POSITION;
|
|
float4 texcoord : TEXCOORD0;
|
|
float3 normal:NORMAL;
|
|
};
|
|
|
|
struct v2f
|
|
{
|
|
float4 pos : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
float3 normal:NORMAL;
|
|
float4 wVertex : FLOAT;
|
|
};
|
|
|
|
v2f vert(a2v v)
|
|
{
|
|
v2f o;
|
|
|
|
// Suppose the center in object space is fixed
|
|
float3 center = float3(0, 0, 0);
|
|
float3 viewer = mul(unity_WorldToObject,float4(_WorldSpaceCameraPos, 1));
|
|
|
|
float3 normalDir = viewer - center;
|
|
|
|
normalDir.y = normalDir.y * _VerticalBillboarding;
|
|
normalDir = normalize(normalDir);
|
|
|
|
float3 upDir = abs(normalDir.y) > 0.999 ? float3(0, 0, 1) : float3(0, 1, 0);
|
|
float3 rightDir = normalize(cross(upDir, normalDir));
|
|
upDir = normalize(cross(normalDir, rightDir));
|
|
|
|
// Use the three vectors to rotate the quad
|
|
float3 centerOffs = v.vertex.xyz - center;
|
|
float3 localPos = center + rightDir * centerOffs.x +upDir * centerOffs.y + normalDir * centerOffs.z;
|
|
|
|
o.pos = UnityObjectToClipPos(float4(localPos, 1));
|
|
o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
|
|
o.normal = mul(unity_ObjectToWorld, v.normal);
|
|
o.wVertex = mul(unity_ObjectToWorld, v.vertex);
|
|
return o;
|
|
}
|
|
|
|
fixed4 frag(v2f i) : SV_Target
|
|
{
|
|
fixed2 uv1 = i.uv;
|
|
uv1 -= float2(0.5, 0.5);
|
|
uv1 *= float2(_Xscale, _Yscale);
|
|
uv1+= float2(0.5, 0.5);
|
|
|
|
|
|
fixed4 col = tex2D(_MainTex, uv1);
|
|
|
|
col.rgb *= _Color.rgb;
|
|
|
|
return col;
|
|
|
|
|
|
}
|
|
|
|
ENDCG
|
|
}
|
|
|
|
|
|
}
|
|
FallBack "Transparent/VertexLit"
|
|
} |