我有下面的 Phong 光照模型的基本着色器代码。我已经测试了漫反射、环境光和镜面光,它们产生了正确的结果。当谈到在最后一行中组合它们时,我不断得到一种看起来像环境照明的效果。有人知道它有什么问题吗?
//translate the normals to be in sync with any tranlations applied to the model
vec3 tnormal = normalize(vec3(viewMatrix * modelMatrix * vec4(normal,0.0)));
vec3 tVertex = vec3(viewMatrix * modelMatrix * vec4(position, 1.0));
// Ambient = La * Ka
vec3 ambience = La * theMaterial.ka;
//Diffuse = Ld * Kd * dot(s, n)
vec3 s = normalize(vec3(myLight.position - tVertex));
vec3 diffuse = myLight.Ld * theMaterial.kd * max(dot(s, tnormal), 0.0);
//Specular = Ls * ks * dot(r,n)^f
//r is the reflection of -lightposition, r = -s + 2 * dot(s,n) * n
vec3 r = normalize(reflect(-myLight.position, tnormal));
vec3 v = normalize(-tVertex.xyz);
vec3 specularity = myLight.Ls * theMaterial.ks * pow(dot(v, r), theMaterial.f);
//(ABS) Intensity = Ia * Id * Is
LightIntensity = ambience * diffuse * specularity;