我有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;
答案 0 :(得分:0)