Hi, I need to implement Phong lighting on a 3d cube. Am I right in thinking that all I need to do to achieve this is have ambient, diffused and specular light?
I’ve given it a go but I don’t think it’s working properly. The entire cube is covered in a turquoise light. Here’s my code for the lighting.
I’m not sure I do want to set a light’s position. I don’t fully understand how to do phong lighting. My understand was it was just ambient, diffused and specular light. Is that correct?
The variable names suggest you want to set the light’s position, but you are overwriting the diffuse color of the light source.
Since you are not writing your own shaders, but instead are using the OpenGL fixed function lighting you get OpenGL’s lighting model - I think that is not 100% identical to Phong’s lighting model, but rather uses the Blinn-Phong model and adds an emission term; the difference is not huge in practice though.
Wikipedia has descriptions of the Phong and Blinn-Phong models and how they differ.
The lighting equation has emissive, ambient, diffuse and specular terms.
The contribution from the diffuse and specular terms depends upon the direction of the light relative to the vertex being lit, so you need to specify either a position or direction for the light in order for those terms to be meaningful.