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.
32 lines
920 B
32 lines
920 B
uniform vec4 U_AmbientLightColor;
|
|
uniform vec4 U_AmbientMaterial;
|
|
uniform vec3 U_LightPos;
|
|
uniform vec4 U_DiffuseLightColor;
|
|
uniform vec4 U_DiffuseMaterial;
|
|
uniform vec3 U_EyePos;
|
|
uniform vec4 U_SpecularLightColor;
|
|
uniform vec4 U_SpecularMaterial;
|
|
|
|
|
|
varying vec3 V_Normal;
|
|
varying vec3 V_WorldPos;
|
|
|
|
void main()
|
|
{
|
|
//ambient
|
|
vec4 ambientColor = U_AmbientLightColor * U_AmbientMaterial;
|
|
|
|
//diffuse
|
|
vec3 N = normalize(V_Normal);
|
|
vec3 L = normalize(U_LightPos);
|
|
float diffuseIntensity = max(0.0, dot(L,N));
|
|
vec4 diffuseColor = U_DiffuseLightColor * U_DiffuseMaterial * diffuseIntensity;
|
|
|
|
//specular
|
|
vec3 reflectDir = normalize(reflect(-L,N));//-L是入射光向量,通过reflect函数求到反射光方向
|
|
vec3 viewDir = normalize(U_EyePos - V_WorldPos);
|
|
vec4 specularColor = U_SpecularLightColor * U_SpecularMaterial * pow(max(0.0, dot(viewDir,reflectDir)), 64.0);
|
|
|
|
|
|
gl_FragColor = ambientColor + diffuseColor + specularColor;
|
|
}
|