Phong vs. BRDF

Before we dive into the concepts of BRDF and lighting models, we'll introduce a technique for simulating the appearance of glossy surfaces, such as plastic balls. From there, it will become easier to generalize the technology, which is what the concept of BRDF and illumination or reflection models is all about.

Figure 1: Specular highlights are simply reflections of the strongest light sources in the scene around the ball. The ball is both diffuse and specular (shiny)

In the previous lesson, we learned how to simulate the appearance of mirror-like and diffuse surfaces. But what about glossy surfaces? First of all, you should note that the plastic ball example we just mentioned is not just a purely smooth surface. Like most materials, it can be described as having both a diffuse component and a glossy component (the gloss or specular reflection you can see in the ball in Figure 1).

NSDT tool recommendationThree.js AI texture development kit - YOLO synthetic data generator - GLTF/GLB online editing - 3D model format online conversion - Programmable 3D scene editor -  REVIT export 3D model plug-in - 3D model semantic search engine

1. Phong model

Materials exhibit this dual property for different reasons. In some cases, this is simply because the material itself is a composite of different materials. For example, plastic balls can be made from flakes or small particles that act as diffusers, but are held together by a polymer that acts as a reflective (usually transmissive) material. While flakes or small particles diffuse light, polymers reflect it. In other cases, objects are made from multiple materials stacked on top of one another. This is the case with the skins of many fruits. For example, oranges have a thick skin layer that acts more like a diffusing surface, which is itself covered with a thin layer of oil that acts more like a specular or reflective surface. In summary, we can describe the appearance of many materials as having a diffuse component and a specular or glossy component. We can express this concept in the form of an equation:

where Sp represents "coloring at P". In this equation, diffuse() is the diffuse effect we learned to simulate in the previous lesson, and specular() is new and will be used to simulate the glossy appearance of the object . The strength of the two effects, or the different ways it balances one effect against the other, can be controlled by these two parameters Kd and Ks. In the world of shading and computer graphics, these terms are given many names, and a great deal of research has been done on them. You can think of them as the strength or gain of the diffuse and specular components. By adjusting them, one can create a variety of effects. But how these two parameters should be set, we will discuss later. Now, let's focus on the specular() function itself.

Figure 2: Waves in the water break up the reflection of the background scene

Bui Tuong Phong was a promising researcher in the field of computer graphics who sadly died in 1975, shortly after publishing his 1973 paper. One of the ideas he presented in the paper was that many materials could actually be computationally simulated by weighting their diffuse and weighted specular components. Readers interested in understanding what causes certain surfaces to be shiny should read Chapter 1 of the previous lesson. Glossy highlights are simply the reflection of light from an object. This phenomenon is similar to a perfectly mirror-like surface reflecting an image of a light source or an object in a scene, although the surface of a glossy material is not completely smooth like a mirror, and slight fragmentation (on a microscopic scale) causes the light to orient in a slightly different direction than the mirror. directional reflection (waves on the water surface will produce a similar effect, as shown in Figure 2). This has the effect of blurring the light reflected from the surface of the object. Because the surface of a rough surface resembles a broken mirror, computer graphics researchers like to define it as a collection of small mirrors, also called micro-facets.

The concept of microfacets here is purely an ideological perspective and does not explicitly "reflect" the surface appearance of a rough surface. Although representing a rough surface, a collection of microfacets simplifies the analysis of mathematical equations that can then be used to model the appearance of a rough surface. This is the basis of the microfaceting model. A lesson devoted to this topic can be found in the next section.

Figure 3: The rougher the surface, the larger and darker the specular reflection will be. Think of it as light "blurring" on the surface of an object.

There are two points worth observing at this point:

  • The glossy reflection of a light source is darker than the reflection of the same light source from a mirror-like surface (we assume that the observer is viewing the reflection of the light source in the direction of the light reflection, as shown in Figure 3). The reason for this is that only a small portion of the microfacets, or small mirrors that make up the surface of a smooth object, reflect light in the direction of observation, whereas in the case of a mirror-like surface, all light is reflected in that direction (Figure 3). In the case of a rough surface, when an observer looks down along the surface's ideal reflection direction, only a small portion of the light is reflected toward the eye, so the brightness is reduced.
  • The brightness of specular reflections decreases as the angle between the viewing direction and the ideal reflection direction increases. This is because as this angle increases, the number of microfacets that reflect light into the eye decreases, and therefore the brightness decreases. When the surface is a perfect mirror, the probability of finding a microfacet that reflects light in the direction of the observer decreases as we move away from the point where we observe the light reflection. This is a statistical property of the way microfacets are distributed.

An important last observation is that the brightness of a specular reflection decreases with increasing distance between a point on the object's surface and the point at which the reflection of the light source would form if the surface were a perfect mirror. The series of images below illustrate this idea. On the left you can see the reflection of the small light bulb in the perfect mirror. As we turn to the image on the right, the surface roughness increases. Notice how the reflection decreases in brightness and how the bulb's reflection spreads over a larger area. Also note that the intensity of the highlight decreases as the point on the surface of the object increases in distance from the location of the original reflected light.

Figure 4: If the direction of the line of sight is not exactly aligned with the direction of the mirror, we will not see the reflection of the light source. Although we can take the dot product between the view direction and the reflection direction, this can indicate how far the two vectors deviate from each other. This is how we use the Phong model to simulate specular reflections

Phong observed that this effect could be simulated in some way by calculating the ideal reflection direction of a ray incident on a shadow point and calculating the dot product between that reflected ray and the actual viewing direction. We know from the previous lesson that to see a reflection from a point on a mirror surface, the line of sight or line of sight needs to exactly coincide with the direction of the reflection. If these directions differ (even by a small amount), then the observer will not see the reflection at that point at all. When two vectors are the same (when the viewing direction is parallel to the reflection direction), their dot product is equal to 1. As the angle between the viewing direction and the reflection direction increases, the dot product between the two vectors decreases (eventually reaching 0).

where V is the view direction and R is equal to:

Figure 5: Shapes of (V.R)^n corresponding to different n values

L is the direction of incident light at shading point P, and you can see a plot of this equation in Figure 5 (red curve). Although Phong noted that the curve has a fairly large shape, which itself produces a fairly large specular highlight. To solve this problem and shape specular highlights, he raised the equation to a power of some value n (often called the specular index):

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

As you can see, some of these spheres are starting to look like shiny gray spheres. There are problems though. Since the probability of a microsurface reflecting light to the observer decreases as the object's roughness increases, the overall brightness of the specular highlight should also decrease as the object's roughness increases. In other words, the bigger the highlight, the darker it should be. Although that's not the case in this rendering. Unfortunately, Phong's model is empirical and, as he points out in the paper, these numbers n and Ks have no physical meaning. To adjust the specular intensity, you need to adjust the parameter Ks until you get the desired look.

Here is the code used to calculate the image above:

Vec3f castRay(...)
{
    ...
    if (trace(orig, dir, objects, isect)) {
        ...
        switch (isect.hitObject->type) {
            case kPhong:
            {
                Vec3f diffuse = 0, specular = 0;
                for (uint32_t i = 0; i < lights.size(); ++i) {
                    Vec3f lightDir, lightIntensity;
                    IsectInfo isectShad;
                    lights[i]->illuminate(hitPoint, lightDir, lightIntensity, isectShad.tNear);

                    bool vis = !trace(hitPoint + hitNormal * options.bias, -lightDir, objects, isectShad, kShadowRay);
                    
                    // compute the diffuse component
                    diffuse += vis * isect.hitObject->albedo * lightIntensity * std::max(0.f, hitNormal.dotProduct(-lightDir));
                    
                    // compute the specular component
                    // what would be the ideal reflection direction for this light ray
                    Vec3f R = reflect(lightDir, hitNormal);
                    specular += vis * lightIntensity * std::pow(std::max(0.f, R.dotProduct(-dir)), isect.hitObject->n);
                }
                hitColor = diffuse * isect.hitObject->Kd + specular * isect.hitObject->Ks;
                break;
            }
            default:
                break;
        }
    }
    else {
        ...
    }

    return hitColor;
}

2. Shading/reflection model

The model Phong uses to simulate the appearance of shiny materials is what we in CG call a reflection or shading model. The reason a material looks the way it does is often the result of a very complex interaction between light and the microstructure that makes up the material. Simulating these interactions is too complex, so we use mathematical models to approximate them. The Phong model, very popular for its simplicity, is just one example of such a reflection model, but a wide variety of other mathematical models exist. To name a few: Blinn-Phong, Lafortune, Torrance-Sparrow, Cook-Torrance, Ward anistropy, Oren-Nayar models, etc.

3. The concept of BRDF and the rise and fall of the Phong model

Figure 6: Light direction I and view direction V

As mentioned above, the essence of what Phong uses to simulate the appearance of shiny materials is a function. This function (which includes specular and diffuse reflection calculations) contains a number of parameters, such as n which can be adjusted to change the appearance of the material, but more importantly it depends on two variables, the incident light direction (which is used to calculate diffuse reflection and the specular component) and the view direction (only used to calculate the specular component). We can basically write this function as:

where W0 is the angle between the surface normal N and the view direction V, and Wi is the angle between the surface normal N and the light direction I (Figure 6). The subscript o represents the outward direction. In computer graphics, this function is given the fancy name of the "bidirectional reflectance distribution function" or BRDF for short. BRDF is nothing more than a function that returns the amount of light reflected in a given view direction given the direction of incident light:

Any of the shading models we mentioned above, such as the Cook-Torrance model of the Oren-Nayar model are examples of BRDFs. If you prefer, you can also think of BRDF as a function that describes how a given object scatters or reflects light. As suggested, the amount of reflected light depends on the incident light direction and the viewing direction. Many BRDFs have been proposed over the years: some of them are designed to model specific types of materials. For example, the Oren-Nayar model is ideal for simulating the appearance of the Moon, which does not reflect light exactly the same as that reflected by a diffuse surface. Some of these models are designed based on optical principles or simply to accommodate some physical measurements. Some other models, such as the Phong reflection model, are more empirical. This course is dedicated to the concept of BRDF, so don't worry if we've only scratched the surface of the topic right now.

There are good and bad aspects of BRDF. Bad BRDF essentially violates one or more of the following three rules:

  • First, the BRDF is a positive function everywhere within the range of valid incoming and outgoing directions.
  • Second, BRDF is reciprocal. In other words, BRDF(Wo, Wi) = BRDF(Wi, Wo) . If you swap the incoming and outgoing directions in the function, the function returns the same result.
  • Finally, BRDF is energy conservation. This essentially means that a BRDF cannot produce more light than it receives (unless the surface itself is emissive, but this is a special case). In general, an object cannot reflect more light than is incident on its surface. BRDF should naturally follow the same rules.

A good BRDF is one that conforms to these three rules. The problem with the Phong model is that it is not energy conserving in nature. It would be too long to demonstrate this in this course, but if you read the course on BRDF you'll understand why. In general, there are several factors that help make BRDF useful and good. It needs to be physically accurate, it needs to be accurate, and it needs to be computationally efficient (speed and memory consumption should be considered here). The Phong model is not physically correct, but it is computationally efficient and compact, which is why it has become very popular over the years. The Phong model, although still considered useful for teaching people the basics of shading, is no longer used today and has been replaced by newer, more physically correct models.

4. What does specular lobe or diffuse lobe mean?

Figure 7: Diffuse lobes and specular lobes. To simulate the appearance of complex materials, it is often necessary to combine multiple lobes (for example, one diffuse lobe and 2 to 3 specular lobes with different specular indices and weights)

Let's end this chapter with the concept of specular lobes that you may have heard of or read about. When a surface is rough, it reflects light in a slightly different direction than a perfect reflection, but is centered around the perfect reflection direction. You can draw or visualize this process by drawing some sort of elongated shape centered in the direction of the reflection, as shown in Figure 6. This represents, in part, a set of possible directions into which the surface will reflect light. This is what we call specular lobes in CG.

In Figure 7, we represent this lobe as a two-dimensional shape, but the shape should be three-dimensional. The shape of this lobe changes with the direction of incident light. This is a property shared by most materials. They have a unique way of reflecting light for every possible direction of incident light. For real materials, the lobe or the shape of the lobe can be quite complex. We can obtain this using an instrument called a goniometer. The function of this instrument is to measure the amount of light a given material reflects in every possible direction above its surface in a given direction of incident light. The shape of the resulting three-dimensional data depends on the material properties. If the material was more dispersed, the result would look like a hemisphere. If the material is more specular, long lobes will appear around the direction of the reflection. Data obtained from real materials are useful for deriving mathematical models that can be used to simulate a given material or to verify the accuracy of a given BRDF model.

If a BRDF model behaves similarly to the measured data (reflects light in the same way), the model is well suited for simulating the appearance of the measured material. Note that when you look at the reflectance function of measured materials, you will find that they often have multiple lobes. In CG we simulate this effect by combining multiple lobes with different parameters and weights. For example, in the bottom panel of Figure 7 we combine diffuse and specular lobes. The resulting material should look glossy and diffuse like the Phong model. More information on this topic can be found in the next section.

5. What about other types of materials?

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

Contrary to what it seems, there are only a few types of materials. As mentioned before, the appearance of objects is sometimes complex, but only requires the combination of different lobes. The process by which we find the recipe for mixing these lobes is often complex, but the equations that create the lobes themselves, and even the law of reflection or Snell's law itself, are very simple.

As mentioned in previous lessons, we generally divide materials into two broad categories: dielectrics and conductors. Conductors are essentially metals: they conduct electricity. In contrast, dielectrics are insulators. This includes plastic, pure water, glass, wood, rubber, wax, etc. Conductors (gold, aluminum, etc.) are reflective in nature, and their appearance can be easily modeled using the laws of reflection.

But remember, you should use different Fresnel equations for dielectrics and conductors. Many dielectrics also vary greatly in appearance. Water, wood, plastic, and wax have different appearances. Water and glass can be simulated using a combination of reflection, transmission, and Fresnel. Wood can essentially be simulated using diffuse reflection. Plastics can be simulated using a combination of diffuse and specular reflections (the Phong model can be used to simulate plastics because it combines these two components).

Simulating wax is a slightly different problem because wax is translucent. In all the examples we have looked at so far, we think of the point at which a ray hits a surface and the point on the object at which that same ray of light is reflected into the environment as being the same. BRDF is designed based on the assumption that this is indeed the case. But in the case of translucent materials, when light hits an object's surface at point x, it usually passes through the material that makes up the object, eventually leaving the object at a different x' point. When light enters an object, it is scattered one or more times by the structure of the material. The ray usually follows some kind of random walk until it eventually leaves the object in some random location. BRDF cannot be used to simulate such objects. We need another model, called BSSRDF. This complex acronym stands for Bidirectional Scattering Surface Reflection Distribution Function. This phenomenon is also called subsurface scattering. Check out the next section to learn more about BSSRDF and simulating the appearance of translucent materials.

6. Should I color specular reflections with the color of the object?

CG artists often ask this question, but even the most experienced artists sometimes don’t know what the exact answer should be. The answer to this question is...no.

If the material is a dielectric, in other words, if it is not a conductor/metal. Specular reflection is simply the reflection of light from an object's surface. Therefore, the color of the reflected light should be the same as the color of the light emitted by the light source. If the light source emits red light, the specular highlight should be red. If the light source emits white light, the specular highlight should be white. Never color specular reflections, especially the color of an object. If the object is yellow and the reflected light is white, the specular reflection will not be yellow. It will be white.

But there is an exception to this rule when it comes to metals. Some metals are colored (bronze, gold, copper) and are purely reflective. If you wish, metals can change the color of the specular reflection with their color. For example, gold is yellow. For copper, it's some deep orange-red color, etc. If you want to simulate the look of gold, you have to multiply the reflected light by the color of the metal: yellow. However, if the metal is covered with a layer of paint, then the appearance you simulate is no longer the metal, but a layer of paint, which itself is a dielectric. Therefore, you should not shade the specular reflection in this case.


Original link:Phong and BRDF - BimAnt

Guess you like

Origin blog.csdn.net/shebao3333/article/details/134941159