This is a really tiny diff compared to the last experiment -
I’m just going to add a new material type of ‘specular’.
I factored out a bit of common code (lightDistanceAndRay), and added specularMaterial:
Notice that in diffuseMaterial, we ignore the Ray parameter (the ray from camera to surface),
but in specularMaterial, it’s part of the lighting calculation. Hopefully this makes sense -
a matt material looks roughly the same no matter where you view it from, but a shiny surface will
have different brightness depending on the viewing angle. (If you happen to catch a reflection of a
light, it will appear bright at that point, but if not, the surface at that point will be dim).
Rather than have material variants for only diffuse, only specular, and part-diffuse-part-specular
surfaces, I’ve added a method that lets me combine different surface material kinds:
So with all that in place, the final image looks as follows: