Happy Birthday Phong Shading
This month kind of marks the birthday of two very influential techniques in computer graphics: Phong Shading and the Phong Lighting Model. Both were published in the paper “Illumination for Computer Generated Pictures” 40 years ago in the Communications of the ACM in June 1975. While Bui Tuong Phong published his works also in his PhD thesis two years earlier, it’s debatable whether his algorithms would have become as popular as they are without a dedicated paper (this is the “kind of” part of the birthday).
What are Phong Lighting and Phong Shading?
The Phong Lighting Model describes how an object reflects light from a light source in the scene towards the virtual camera. Only those three objects are taken into account so it’s not a global illumination model, which means it can not handle shadows or indirect light at all. The new idea in Phong Lighting was how to model not only the diffuse reflection, but also specular reflections which can lead to specular highlights. Models rendered with Phong Lighting often look like plastic objects – this method lacks the ability to simulate a wide range of materials.
Before Phong, the lighting calculations were performed once per polygon or once per vertex and the resulting color values were interpolated across the surface while rasterizing them (e.g. Gouraud shading). As the specular highlights introduced by Phong are of high frequencies while the meshes were coarsely triangulated, Phong interpolated the surface normals instead and performed per pixel lighting.
Illumination for Computer Generated Pictures
Even if you don’t have access to the ACM library, a pdf of this paper is quite easy to find. It can be fun to take a look at older publications and I want to share some interesting quotes from this influential paper here.
“The quality of computer generated images of three-dimensional scenes depends on the shading technique used to paint the objects on the cathode-ray tube screen”
I would even extend this statement to non-cathode-ray tube screens ;-) A recent trend in real-time computer graphics (e.g. in games) is to move away from Phong Lighting and other special lighting models which can handle a specific set of materials towards a physically based model that can be used for (nearly) all materials in the scene. Those models are more complex, more expensive in terms of shader runtime but are based on physical properties and can result in more realistic images. So 40 years later this statement is still true and could still be the introduction to an abstract of a shading paper today (well, without the cathode-ray tube reference ;-) .
“The two principal problems encountered in the design of these systems are the elimination of the hidden parts and the shading of objects.”
While the shading is still an active field of research (especially if you extend this to global illumination effects), the other big problem of the 70th – hidden surface removal – was trivially solved. The problem: if two (or more) objects will get rendered onto the same pixel of the image, which one of them is nearer to the camera and should be visible in the end? A lot of time was invested into clipping algorithms and ways of sorting the objects and individual polygons back to front before rendering them. Today we store the distance to the nearest (already drawn) object in the depth-buffer (aka Z-buffer) and only update the framebuffer if a new pixel is nearer than that reference value. A trivial but brute-force solution unthinkable of in those days as no computer had enough memory for that!
“The computer system can be compared to an artist who paints an object from its description and not from direct observation of the object.”
Just a nice quote.
“The first step in accounting for the specular properties of the objects and the position of the observer is to determine the normal to the surface at each point to be shaded”
The key difference of Phong Shading to Gouraud Shading: calculate one normal per pixel to perform per pixel shading. Many years later we even have enough memory to store normals explicitly at a higher resolution than the meshes geometry: normal maps.
“These numbers are empirically adjusted for the picture, and no physical justifications are made.”
Phong provides useful values for the material properties in his paper, e.g. he suggests values between 1 and 10 for the specular exponent. The material properties used in Phong Lighting have no roots in real world object properties. Some combinations can even lead to an object reflecting more light than it receives! One more reason to move to physically based shading now that we have the computing resources.
“A hardware implementation of this shading model would of course require more hardware than the simpler Gouraud method.” “In addition, since the results of the interpolation do not yield a unit vector, (…) some extra hardware is necessary to ‘normalize’ the outputs of the interpolators.”
Even the GPUs in phones do not implement a specific lighting model anymore but support programmable shaders to let the developer decide how complex the shading should get. Gouraud and Phong shading can both get implemented and mixed with any lighting technique, the developer picks the shading model by simply placing the lighting code into the vertex or fragment shader. He/She is now responsible to make sure that in case of Phong Shading the normals are renormalized in the fragment shader. Not doing so leads to wrong lighting inside of the triangles but this bug is subtle so it might even be left out intensionally to save a square-root instruction.
A bit of Phong History
James F. Blinn suggested a modification to the original Phong Lighting Model in 1977 which leads to better results and is a bit faster (“Models of light reflection for computer synthesized pictures”). This variant was made the default Lighting Model in the fixed-function graphics API versions of OpenGL and Direct3D. Every application and game which used those APIs before the introduction of programmable shaders in consumer hardware in 2001 used Phong Lighting in combination with Gouraud Shading – per vertex lighting based on Phongs ideas but the results were interpolated across the surface during rasterization.
While programmable shaders allowed for Phong Shading (aka per pixel lighting) in games, so did Sega’s Hikaru arcade system in 1999 using a special GPU.
While console and PC games moved on to more complex physically based lighting (or a non-photorealistic style), Phong Lighting can still be an option for simple visualisations and slower hardware (e.g. smart-phones).
The Phong Lighting Model is still one of the first models to be taught in computer graphics classes and graphics programming tutorials. Compared to physically based models it’s quicker, faster to understand, faster to implement and needs fewer parameters to get something ok-looking onto the screen. This is why I expect it to remain in the curriculums for at least the next 40 years.