Liopoles.comSpecular reflection model in computer graphics

# The Phong Model, Introduction to the Concepts of Shader

8.13.2018 | Sydney Jenkin

Figure 1: the specular highlights are just a reflection of the strongest sources of light in the scene surrounding the ball. The ball is both diffuse and specular (shiny).

From there, it will become easier to generalise the technique which is what the concept of BRDF and illumination or reflection model are all about. Before we dive into the concept of BRDF and illumination model, we will introduce a technique used to simulate the appearance of glossy surface such as a plastic ball for instance.

There is an exception to this rule though with metals. If you want to simulate the appearance of gold, you have to multiply the reflected light by the metal's color: yellow. For gold for example, it is a yellow color. Thus in this case, you should not tint specular reflections. Though if the metal is covered with a layer of paint, then what you simulate the appearance of is not the metal anymore but the paint layer, which on its own is a dielectric. For copper it is some dark orange-red color, etc. Some metals have a color (bronze, gold, copper) and though are purely reflective. Metals change the color of the specular reflections with their own color if you wish.

The Phong Model, Introduction to the Concepts of Shader

If the material is more diffuse the result will look like a hemisphere. This represents in a way the set of possible directions that the surface reflects light into. If the BRDF model behaves like the measured data (it reflects light the same way) then the model is a good candidate for simulating the appearance of the measured material. For example in figure 7, in the bottom figure we combined a diffuse and a specular lobe together. In figure 7 we represented this lobe as two-dimension shape but the shape should actually be three-dimensional. If the material is more specular, there will be a long elongated lobe oriented about the reflection direction. In CG, we simulate this effect by combing several lobes with different parameters and weight. Data acquired from real material is very useful to either derived mathematical models that can be used to simulate a given material or validate the accuracy of a given BRDF model. The shape of the resulting three-dimensional data totally depends on the material property. The shape of this lobe changes with the incoming light direction. This is a property that most materials have. They have a unique way of reflecting light for each possible incoming light direction. We can acquire it using an instrument called a gonioreflectometer. We will finish this chapter on the concept of specular lobe which you may have head or read about. Note that when you look at the reflectance function of measure materials, you can see that they often have more than one lobe. You can draw or visualise this process by drawing some sort of elongated shape centred around the reflection direction as shown in figure 6. The function of this instrument is to measure how much light a given material reflects in every possible direction above its surface for a given incoming light direction. When a surface is rough, it reflects light in directions slightly different from the perfect reflection direction but centred around it. The resulting material should look both shiny and diffuse like with the Phong model. This what we call in CG, the lobe of the specular reflection. This lobe or the shape of this lobe can be quite complex for real material. More information on this topic can be found in the next section.

This question is often asked by CG artists but even the most experimented ones sometimes fail knowing what the exact answer should be. The answer to this question is.

Two observations are worth making at this point:

You can see a plot of this equation in figure 5 (the red curve). To solve this problem and shape the specular highlight, he raised the equation to the power of some value $$n$$ (which is often called the specular exponent):. Though Phong noticed that the curve has a pretty large shape which in itself would create a pretty large specular highlight. $$L$$ is the incident light direction at $$P$$, the shaded point.

If the light source emits white light, then the specular highlight should be white. If the light source emits red light, then the specular highlight should be red. if the material is a dielectric, in other words, if it is not a conductor/metal. It will be white. If the object is yellow and the light being reflected is white, the specular reflection won't be yellow. A specular reflection is only a reflection of a light source off of the surface of an object. Never, ever tint a specular reflection especially with the color of the object. Therefore the color of that reflected light should be the same than the color of the light emitted by the light source.

Figure 6: incoming $$I$$ and outgoing $$V$$ direction.

For example a plastic ball can be made of some sort of flakes or small particles acting as diffusers but glued together by a polymer that is itself acting as reflective (and often transmissive) material. This is the case of the skin of many fruits. We could put this concept in a equation form:. In other cases, objects are made of several materials layered on top of each other. As most materials, it can be described as having both a diffuse component and a glossy component (the shiny or specular reflections that you can see in the ball from figure 1). In the previous lesson, we learned about simulating the appearance of mirror like and diffuse surfaces. The reason why many materials exhibit this dual properties is not always the same. Though the flakes or small particles diffuse lights while the polymer reflects light. But what about glossy surfaces? First you should note that the plastic ball example that we have just mentioned, is more than just a purely glossy surface. An orange for example has a thick skin layer that is acting more like a diffuse surface which is itself covered with a thin oily layer which is acting more like a specular or reflective surface. In summary we can describe the appearance of many material has having a diffuse component and a specular or glossy component. In some cases, it is simply because the material is itself a composite of different materials.

Here is the code used to compute the images above:

This has for effect to blur the light reflected off of the surface of the object. You can find a lesson devoted to this topic in the next section. Figure 3: the rougher the surface, the larger and the dimmer the specular reflection. Because the surface of a rough surface acts like a broken mirror, computer graphics researchers like to define it as a collection of small mirrors which they also call micro-facets. This is the foundation of the micro-facet shading models. One of the ideas he developed in this thesis was that indeed many materials could be computed from a sum of weighted diffuse and specular component. The phenomenon is similar to that of a perfect mirror-like surface reflecting an image of the light sources or an image of the object from the scene, though rather than being perfectly smooth like in the case of a mirror, the surface of a glossy material is slightly broken up (at the microscopic scale) which causes light to be reflected in a slightly different direction than the mirror direction (the waves of a water surface produce a similar effect as shown in figure 2). Glossy highlights are just the reflection of lights sources by the object. Bui Tuong Phong was a promising researcher in the field of computer graphics who sadly past way in 1975 soon after he published his thesis in 1973. Though representing rough surfaces a collection of micro-facets simplifies the resolution of mathematical equations which can then be used to simulate the appearance of rough surfaces. You can see this as the light being "blurred" across the surface of the object. Readers interested in learning what causes some surfaces to be glossy are invited to read the first chapter of the previous lesson. The concept of micro-facets here is purely a view of the mind and doesn't obviously "reflect" how the surface of a rough surface actually looks.

Note also that the highlight brightness decreases in intensity as the distance of points on the surface of the object to the original reflected light position increases. This idea is illustrated in the following series of images. On the left you can see the reflection of a small light bulb by a perfect mirror. What's important in this last observation is basically that the brightness of the specular reflection decreases as the distance between a point on the surface of the object and the point where the reflection of the light source would be formed if the surface was a perfect mirror increases. Note how the reflection's brightness decreases and the light bulb's reflection spreads across a larger area. As we progress to the right, the surface roughness increases.

Chapter 1 of 2 Next Chapter arrow_forward.

Where $$V$$ is the view direction and $$R$$ is equal to:

Phong observed that it was possible to simulate this effect somehow by computing the ideal reflection direction of a light ray incident on the shaded point, and computing the dot product between this reflected ray and the actual view direction. When the two vectors are the same (when the view direction is parallel to the reflection direction), their dot product is equal to 1. As the angle between the view direction and the reflection direction increases, the dot product between the two vectors decreases (and eventually reaches 0). As we know from the previous lesson, to see the reflection of a point on the surface of a mirror-like surface, the view direction or light of sight needs to perfectly coincides with the reflection direction. If these directions are different (even by a small amount), then the observer won't see the reflection of that point at all.

Though we can take the dot product between the view direction and the reflection direction and this gives us an indication of how far the two vectors deviate from each other. This is the principle upping which specular reflections are simulated with the Phong model. Figure 4: if the view direction is not perfectly aligned with the mirror direction, we don't see the reflection of the light source.

Figure 5: the shape of $$(V \cdot R)^n$$ for different values of $$n$$.

A light ray can strike the surface in point x, travel through the material the object is made of and then exit the object in point x' which is some distance away from x. For translucent objects, these two points are different. Figure 8: for BRDFs, we assume that the point where the light ray strikes the surface is the same from the point where the same ray is reflected by the object.

As you can see, some of these spheres start to look like shiny grey spheres. Though this is clearly not the case in this render. Since the probability that a micro-facet reflects light toward the viewer decreases as the roughness of the object increases, the overall brightness of the specular specular highlight should also decrease with $$n$$. In other words, the larger the highlight, the dimmer it should be. Unfortunay Phong's model is empirical as he notices himself in his thesis, the numbers $$n$$ and $$K_s$$ have no physical meaning. Though there is a problem. In order to adjust the specular highlight intensity, you need to tweak the parameter $$K_s$$ until you get the desired look.

The higher the value, the narrower the curve, resulting in smaller, tighter specular highlight. Figure 4 shows the shape that this equation has for different values of $$n$$. If you apply this model and render a series of spheres with increasing values for $$n$$, here is what you get:.

It needs to be physically accurate, it needs to be accurate, and it needs to be computationally efficient (speed and memory consumption should both be considered here). The Phong model while considered still useful to teach people the basics of shading, is not really used anymore today and is replaced by more recent and more physically correct models. The Phong model is not physically correct but is computationally efficient and compact which is why it was very popular for many years. A good BRDF, is a BRDF that complies to these three rules. In general a few factors contribute to making a BRDF useful and good. It would be too long to demonstrate this in this lesson, though if you read the lesson on BRDF, you will learn why. The problem with the Phong model, is that it is essentially not energy conserving.

We could essential write this function as:. This function (which includes a specular and a diffuse compute). As mentioned above what Phong essentially used to simulate the appearance of shiny materials is a function. This function contains a certain number of parameters such as $$n$$ that can be tweaked to change the appearance of the material, but more importantly, it actually depends on two variables, the incident light direction (which is used to compute both the diffuse and specular component) and the view direction (which is used to compute the specular component only).

A bad BRDF is essentially one that breaks either one or more of the three following rules:. There are good and bad BRDFs.

Where $$\omega_o$$ and $$\omega_i$$ are the angle between the surface normal ($$N$$) and the view direction ($$V$$) and the surface normal and the light direction ($$I$$) respectively (figure 6). A BRDF is nothing else than a function that returns the amount of light reflected in the view direction for a given incident light direction:. The subscript $$o$$ stands for outgoing. In computer graphics, this function is given the fancy name of Bidirectional Reflectance Distribution Function or in short BRDF.

Sone other models such as the Phong reflection model are more empirical. For example the Oren-Nayar model is ideally suited to simulate the appearance of the moon which is not reflecting light exactly light a diffuse surface would. As suggested, this amount of reflected light depends on both the incident light direction and the view direction. Many BRDFs have been proposed other the years: some are designed to simulate a specific type of material. A lesson is devoted to the concept of BRDF alone so don't worry if we just scratch the surface of the topic for now. Some of these models were designed on either principles of optics or just to fit some physical measurements. You can also see a BRDF as function that describes how a given object scatters or reflects light if you prefer. Any of the shading models that we mentioned above, such as the Cook-Torrance of the Oren-Nayar model are examples of BRDFs.

The Phong model, which is very popular because of its simplicity, is only one example of such reflection model but a wide variety of other mathematical models exist. The model that Phong used to simulate the appearance of shiny material is what we call in CG a reflection or shading model. The reason why materials look the way they do is often the result of very complex interactions between light and the microscopic structure of the material objects are made of. To name just a few: the Blinn-Phong, the Lafortune, the Torrance-Sparrow, the Cook-Torrance, the Ward anisotropy, the Oren-Nayar model, etc. It would be too complicated to simulate these interactions therefore we use mathematical models to approximate them instead.

To simulate the appearance of complex materials you often need to combine several lobes together (like for example one diffuse lobe and 2 to 3 specular lobes with different specular exponent and weight). Figure 7: diffuse and specular lobes.

Figure 2: the waves of this water surface breaks the reflection of the background scene.

The appearance of many dielectrics also varies considerably. Water and glass can be simulated using a combination of reflection, transmission and Fresnel. BRDFs can't be used to simulate that sort of objects. In opposition, dielectrics are insulators. As mentioned in the previous lessons, we generally divide materials in two broad categories: dielectric and conductors. The ray generally follows some sort of random walk until it eventually leaves the object in some random position. Plastic can be simulated using a combination of diffuse and specular (the Phong model can be used to simulate plastic as it combines both components). Conductors are essentially metals: they conduct electricity. Though in the case of translucent materials, when a light ray strikes the surface on a object in a point x, it then generally travels though the material the object is made of and then eventually leaves the object in a different point x'. When the ray enters the objects, it is scattered one or multiples times by the structures that the material is made of. Simulating wax is a slightly different problem because wax is translucent. Wood can essentially be simulated using diffuse. The process by which we can find what the recipe for mixing these lobes together should be is generally complex, but the equations for creating the lobes themselves, are even the law of reflection or the Snell's law are themselves pretty simple. We need another kind of model called a BSSRDF. In all the examples we studied so far, we considered that the point where a light ray strikes the surface and the point on the object where the same light is reflected back into the environment are one and the same. To the contrary of what it may seem, there is only a few types of materials. BRDFs are designed on the assumption that this is indeed the case. Though remember that you should use a different Fresnel equation for dielectrics and conductors. Check the next section, to learn more about BSSRDF and simulating the appearance of translucent materials. This includes plastic, pure water, glass, wood, rubber, wax, etc. Conductors (gold, aluminium, etc.) are essentially reflective and their appearance can easily be simulated using the reflection law. Water wood, plastic and wax have different appearances. The phenomenon is also known as subsurface scattering. As mentioned earlier, objects' appearance is sometimes complex but only requires to combine different lobes together. This complex acronym stands for Bidirectional Scattering-Surface Reflectance Distribution Function.

Where the term $$S_P$$ here stands for the "shading at P". For now, let's focus on the specular function itself. in this equation, the term $$\text$$ is nothing less than the diffuse effect that we learned to simulate in the previous lesson The term $$\text$$ is new and will be used to simulate the glossy appearance of the object. But how these two parameters should be set is something we will look into later on. By tweaking them, one can create a wild variety of effect. You can look at them as the strength or gain of the diffuse and specular component. The strength of both effects or to say it differently balancing one against the other can be controlled through the two parameter $$K_d$$ and $$K_s$$. In shading and the world of computer graphics these terms are given many names and have caused a lot of ink to spill.

Specular reflection model in computer graphics