You can sorta think of this post as part 2 of my “Everything is shiny rant”. While standard specular lighting is pretty common in games, one effect that we rarely see in games is proper fresnel.
Hopefully, you know what specular is by now. The most common model for specular in video games is Blinn-Phong, which is:
H = normalize(V+L);
specVal = pow(saturate(dot(H,N)),power);
In this case, V is the view vector, L is the light vector, N is the normal vector, and power is the specular exponent. H is the derived half vector, and it is the vector half-way between the View and Light vectors.
How does it work? Here’s a diagram. You can see the View, Light, and Normal vector. Now, with this function, where will the specular value peak? Intuitively, you would want the specular function to max out when the view vector is at a reflection vector to the light. And that is what happens. This function peaks when the half vector is aligned exactly with the normal, which happens to be when the reflection of the View vector points right at the light. And life makes sense.
Here is another case:
Once again, the View vector reflects exactly into the Light vector. In this case, would the specular highlight be the brighter, dimmer, or exactly the same as the first case? Well, it would be the same, since you are viewing the maximum value of the specular highlight in both cases. Is this how the real world works? The short answer is no.
Here is a picture of a brick, from two different camera angles. In the top image, the light and camera are both looking straight down, which resembles the first case. In the second line, the light is hitting the surface at a grazing angle, as in the second case. I’ve split the specular and diffuse components with polarization so the diffuse is on the left and the specular is on the right. Let’s check out a brick.
So, wtf? For a material as simple as a freak’n brick, the Blinn-Phong model for specular is completely wrong. And it turns out this happens because of a little thing called fresnel.
Let’s take another look at our two cases of specular. According to Blinn-Phong, they should have the same intensity, but in reality, the one at the grazing angle is much brighter.
To account for this affect, you can use Fresnel. A pretty good realtime approximation for Fresnel is the Schlick Fresnel. From the GPU Gems 3 chapter on skin:
float base = 1 - dot(V,H);
float exponential = pow( base, 5.0);
float fresnel = exponential + F0 * (1.0 - exponential);
specVal *= fresnel;
For some reason, most people tend to want fresnel only on the really shiny surfaces, like water, glass, and metals. But really, fresnel has a strong effect on almost every material. In fact, I would argue that fresnel is more important visually on the less-shiny materials. Here is a piece of PVC pipe.
Certainly, PVC has a fresnel. But in my opinion, I would say that the fresnel has a more visually important effect on the brick than the PVC. Going from almost nothing to very specular is much more important than going from high to higher specular. Isn’t that a more visually important effect? For me, it’s a mistake to think about fresnel only as an effect for water/glass/metal, because it makes a tremendous visual difference on the less shiny surfaces. Here are a few more examples.
Poor cardboard. So misunderstood. It always gets referred to as a “pure diffuse material”, even though it actually deserves to hang out with its shiny friends. The specular is important at straight angles because it adds a subtle desaturation, but cardboard has a very bright specular reflection at grazing angles.
Ever wonder why it feels bright when you drive to work in the morning? Most people think that happens because the sun is in their eyes. Actually, the major source of brightness is that road pavement has a strong fresnel as well. Next time you are driving and the sun is in your eyes, look at your side-view mirror and check out how much darker the pavement in the side-view mirror is relative to the pavement in front of you.
Here is some cloth. It’s a towel from Ikea. Rough, cotton cloth is about the least specular common material that you will see around the house. This comparison isn’t that great because the second image is brighter overall, so it’s harder to see the relative change of the specular to the diffuse. If you want a better example, I’m leaving that as an exercise for the reader.
And just for kicks, let’s check out an X-Rite color checker. When using a color checker, they always recommend that you hold it perpendicular to the camera. Hopefully you don’t need me to tell you why that is.
Viva la Fresnel!
comments powered by Disqus