一、创建Shader
Shader "Custom/ShaderBlinnPhong" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_MainTint ("Diffuse Tint", Color) = (1,1,1,1)
_SpecColor ("Specular Color", Color) = (1,1,1,1)
_SpecPower ("Specular Power", Range(0, 1)) = 0.5
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
//内置的高光模型BlinnPhong(镜面反射光照模型)
//放在Unity安装目录Data文件夹下的UnityCG.cginc文件里在。
#pragma surface surf BlinnPhong
sampler2D _MainTex;
float4 _MainTint;
//_SpecColor: 在内置的高光模型中Unity已经为我们声明了该变量。
fixed _SpecPower;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex) * _MainTint;
o.Specular = _SpecPower;//高光强度
o.Gloss = 1.0;//光泽度
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
二、创建Plane和Sphere
运行效果