Composing the ADS (Phong/Gourang) components

111 views Asked by At

I have the basic shader code below for the Phong lighting model. I've testing the diffuse, ambient and specular lighting and they're producing the correct results. When it comes to composing them on the final line I keep getting an effect that looks like ambient lighting on its own. Does anybody know what's wrong with it?

//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;
1

There are 1 answers

0
user2211776 On

I'm an idiot. My notes incorrectly state intensity should be the product of the components when it's actually the sum.