Shader "VertPhone"
{
Properties
{
_MainTex( "颜色贴图", 2D ) = "white"{}
_Specular( "高光颜色", Color) = (1, 1, 1, 1)
_Gloss( "光泽度", Range(1,10)) = 4
_SpecularPow( "高光强度", Range(0,1)) = 1
}
SubShader{
Tags{ "RenderType" = "Opaque"}
Pass{
Tags{ "LightMode" = "ForwardBase" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fwdbase
#pragma multi_compile_fog
#include "UnityCG.cginc"
#include "Lighting.cginc"
uniform sampler2D _MainTex;
uniform fixed4 _Specular;
uniform half _Gloss;
uniform half _SpecularPow;
struct v2f{
half4 pos :SV_POSITION;
half3 worldPos : TEXCOORD0;
half2 uv :TEXCOORD1;
half3 normalWorld:TEXCOORD2;
UNITY_FOG_COORDS(3)
};
v2f vert( appdata_full v)
{
v2f o;
o.pos = UnityObjectToClipPos( v.vertex );
o.worldPos = mul( unity_ObjectToWorld, v.vertex).xyz;
o.uv = v.texcoord;
o.normalWorld = normalize( mul( unity_ObjectToWorld, v.normal) );
UNITY_TRANSFER_FOG(o,o.pos);
return o;
}
fixed4 frag( v2f i):SV_Target
{
fixed4 basecolor = tex2D(_MainTex, i.uv);
fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT * basecolor;
half3 lightdir = normalize( _WorldSpaceLightPos0.xyz );
fixed3 diffuse = saturate( dot( normalize( i.normalWorld ) , lightdir ) )* _LightColor0.rgb * basecolor;
half3 r = normalize( reflect( -lightdir, i.normalWorld ) );
half3 view = normalize( _WorldSpaceCameraPos.xyz-i.worldPos.xyz );
fixed3 specular = _SpecularPow * _LightColor0.rgb * _Specular * pow( max(0, dot( r, view )), _Gloss );
fixed4 c = fixed4( ambient + diffuse + specular, 1.0);
UNITY_APPLY_FOG(i.fogCoord, c);
return c;
}
ENDCG
}
}
}