Shader "Custom/phong" {
Properties {
_MainTex ("Main Tex", 2D) = "white" {}
_MainTint("Diffuse Tint",Color)=(1,1,1,1)
_SpecularColor("Specular Color",Color)=(1,1,1,1)
_SpecPower("Specular Power",Range(0,30))=1
}
SubShader {
Tags { "RenderType"="opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Phong alpha:fade nolighting
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
float4 _MainTint;
float4 _SpecularColor;
float _SpecPower;
struct Input {
float2 uv_MainTex;
};
fixed4 LightingPhong(SurfaceOutput s,fixed3 lightDir,half3 viewDir,fixed atten)
{
//求反射光
float NdotL = dot(s.Normal,lightDir);
float3 reflectionVector = normalize(2*s.Normal*NdotL-lightDir);
//视向量与反射光求点积计算高光
float spec = pow(max(0,dot(reflectionVector,viewDir)),_SpecPower);
float3 finalSpec = _SpecularColor.rgb*spec;
//计算最终光照
fixed4 c;
c.rgb = (s.Albedo*_LightColor0.rgb*max(0,NdotL)*atten)+(_LightColor0*finalSpec);
c.a = s.Alpha;
return c;
}
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex,IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
phong光照
最新推荐文章于 2023-07-24 08:51:19 发布