Creating Realistic Glass Using 3 Different Materials
For this demo we will utilize Maya's Blinn material, Ramp texture, and Sampler Info utility. We will also use Mental Ray's Dielectric Material and new Mia_material. The user of this tutorial should note that I have also used Mental Ray as my renderer, with Final Gathering, Global Illumination, Caustics, and Image Based lighting used for optimal realism.
Creating Glass with a Blinn
Our first step is to create the geometry for the glasses. Whilst simple, we need to make sure that the revolved surface (constructed here using a NURBS) is thicker at the base (just like a real pint glass). See Fig.01.
Next, I duplicate out a few of these, and set up the scene. My render settings are listed here as well (Fig.02 - 03).
Understanding What Goes into Glass
There are several components which need to be created. The first thing to note is that, of course, glass is a transparent entity. While this is the most obvious, we cannot overlook the subtleties inherent in this transparency due to the thickness of the surface as perceived. Second, glass is reflective, but again we must examine how this reflectivity works. It is a specularized surface, and thusly not very diffuse in terms of surface properties. Finally, glass is a refractive surface, bending light as it enters this medium which is denser than the air around it. Let's break these elements down for a closer look:
Transparency - As mentioned, glass is transparent. But let's examine what happens to our material as it gets close to the edge ... It gets thicker. At the edges of the glass we are actually looking through a denser amount of material. Think about it this way: when a space shuttle exits the atmosphere by flying straight up (off the perpendicular normal of the Earth) it only goes through 62 miles of air to reach outer space. Conversely, if you were standing on the top of Mount Everest and could look both north and south from the summit, you might be able to see 150 miles in each direction (a total of 300 miles) before the Earth curves away and you are looking into space. When we look at the edge of the glass, the same thing is true, therefore we are looking at more "object" and should treat these edges as less transparent (Fig.04).
Reflectivity - Applying the same principle as before, that things are going to act oddly at the edge of our glass, we next throw into the mix the Fresnel Effect. When you look down at a reflective surface, the amount of reflection is determined by the viewing angle. If you were to look straight down into a pool of water, you would be able to see through the minimal reflectivity of the surface to the elements in the water below. At a more even angle, looking across the water, you are more likely to see reflection of the sky above, and not what is underneath. So, when texturing our reflectivity, we will also have to examine these edge effects to make our glass more reflective at glancing normals, and less reflective at normals which point directly towards the camera.
Specularity (vs. Diffuse) - We must also observe where on the spectrum for Diffuse to Reflective our glass needs to be. For the most part, since it is a dense, hard object, we will need to give it a low diffuse value and a higher specular value. We can then control glossiness depending on the purity of the glass, or whether or not the glass is "frosted".
Refractivity - Finally, since our glass is a denser medium than the surrounding air, we will need to compute the index of refraction value. A chart is listed for your convenience in Fig.05. We can quickly see that Glass's IOR value is 1.52 (or really any value between 1.5 and 1.55). As seen in Fig.06 - 07, when a beam of light enters a denser medium, it bends towards the normal of that surface, changing the perceived shape of objects inside or behind. The famous example can be seen on the left, this is called the "stick in the pond" example, theorized first by Socrates. The straw is not really bent, but the fact that we see it through a glass, with water inside that glass, means that light is bending twice between the straw and the eye. This concept has a name: Dielectrics (hence the specialized Dielectric shader that we will use soon).
Ok, so now that we have a handle on the physics that goes into this, we can make these materials. Let's start out by trying to accomplish the look of true glass using a Maya Blinn. I will first make the colour and diffuse colour very dark so as not to influence the look of the glass at all. The transparency is set pretty high (although we will texture this in a few moments). The Eccentricity is low and the Specular Roll off is high, creating a highly specularized (less glossy) look. The reflectivity will be textured in a few moments as well (Fig.08). Note: I do not have the Reflected Colour Channel textured since I have actual objects surrounding this in the pint glass in the scene. If the glass was on its own, it would need an image to reflect, and we would place that here.
It looks so bad in Fig.09, mostly because of the lack of refractivity. So reflectivity is what we will establish next.
Ok, let's get the refractivity working! (Fig.10)
It's looking better now (Fig.11), but the glass is still too uniform in its thickness and reflectivity. Time to add some ramps to control this!
Thickness - let's first add a ramp to control Transparency. We will control this ramp using Maya's Sampler Info node. First I will create a ramp texture and link it to control the transparency of the glass. The ramp is black-to-white, as it only controls alpha information. Whiter is more transparent; blacker is more opaque (Fig.12).
This will (by default) apply the ramp directly to the UVs. However, since this is a V-Ramp (as seen in Fig.12), we can use the Sampler Info Utility's facing ratio attribute to control this V-Coordinate. This will cause the ramp to be applied based on how much the normals of the glass face the camera. The top of the ramp will now represent where the object's normals are facing the camera; the bottom will represent the angle which is facing 90 degrees away from the camera. We can then perform yet another render (Fig.13 - 14).
We're getting there! Now let's establish the reflectivity that comes with the Fresnel effect.
The Fresnel Effect - we need to establish another connection of ramps to the reflectivity channel. Also known as the "Bidirectional Reflectance Distribution Function", our goal is to establish a ramp to correspond values of how reflective the object will be when we look at the mesh from a low angle, and correspondingly from a high angle. When established, the ramps should looks as shown in Fig.15.
Our hypergraph network should look as shown in Fig.16 (note: I have re-used the sampler info node). Here is our render (Fig.17).
Lastly, let's add some blurring for a touch more realism. With Mental Ray we can subtly blur our reflections and refractions (Fig.18 - 19).
Done! We have now successfully created glass using a Blinn. Let's now examine how Mental Ray can do this much more simply.
Creating Glass with a Dielectric Material
I have now made a second pint glass and created a Mental Ray Dielectric Material to apply to it (Fig.20). The attribute editor only has a few choices; this is because all of that sampler info and ramp stuff that we had to do with the Blinn is already taken care of. The material's attributes are a hard specular/reflective surface by default, and all we have to do is set the IOR value to that of glass. The IOR_out value is also crucially important and represents the value of the medium surrounding the glass (in this case air). A situation where this might need to be altered is when we are creating a material for water that is in a plastic water bottle. IOR would be set to 1.33 for water and the IOR_out would be set to 1.46 for the plastic surrounding it. Here we see a render as well (Fig.21 - 22).
So simple, you say! Well, it gets even simpler with Mental Ray's new Mia_material, available in versions of Maya 8.5 and after!
Creating Glass with a MIA Material
The Mia_material is a super awesome, physically accurate material that can simulate almost any type of surface. From Lambert or Oren-Nayer style diffuse surfaces, to metals, brushed metals, anisotropic, glass and gems, glossy metal, frosted materials, translucent surfaces - you name it. It has built in Ambient Occlusion, Final Gathering (per object basis), Fresnel reflectivity (BRDF), and metalicity. Plus, it comes with presets. Let's use one now: create the Mia_material (Fig.23).
Choose the correct preset (you will notice there are many to choose from). Now render (Fig.24 - 25).
We have now looked at 3 different ways to create realistic glass in materials in Maya. Here is one last look at the 3 glasses side by side by side (Fig.26).