|
|
@ -17,22 +17,20 @@ void main() |
|
|
|
vec4 ambientColor = U_AmbientLightColor * U_AmbientMaterial; |
|
|
|
|
|
|
|
//diffuse |
|
|
|
vec3 L = vec3(0.0); |
|
|
|
if(U_LightPos.w==0.0){ |
|
|
|
//这是方向光 |
|
|
|
L = normalize(U_LightPos.xyz); |
|
|
|
} else { |
|
|
|
//这是点光源 |
|
|
|
//model point -> light pos |
|
|
|
} |
|
|
|
vec3 L = normalize(U_LightPos.xyz); |
|
|
|
vec3 N = normalize(V_Normal); |
|
|
|
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 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); |
|
|
|
|
|
|
|
//specular blin |
|
|
|
vec3 viewDir = normalize(U_EyePos - V_WorldPos); |
|
|
|
vec4 specularColor = U_SpecularLightColor * U_SpecularMaterial * pow(max(0.0, dot(viewDir,reflectDir)), 64.0); |
|
|
|
vec3 M = normalize(L + viewDir); |
|
|
|
vec4 specularColor = U_SpecularLightColor * U_SpecularMaterial * pow(max(0.0, dot(M,N)), 64.0); |
|
|
|
|
|
|
|
|
|
|
|
gl_FragColor = ambientColor + diffuseColor + specularColor; |