Dielectric Material This shader is a physically based material shader that can be used to simulate dielectric media such as glass, water, and other liquids. The shader uses Fresnel's formulas for dielectric interfaces. This means that most light is transmitted through the surface for perpendicular incident directions while most light is reflected by the surface for grazing incident angles, simulating the behavior of real dielectric materials. The shader also uses Beer's law for absorption of light that passes through a medium. This means that the light is subject to an exponential falloff as it is transmitted between two surfaces with dielectric material. One of the most asked questions I get, aside from skin, is how I render glass and liquids without a lot of work. Often rendering glass and liquids will elicit headaches for the artist, have no fear, take two Excedrin s, and call on Mental Ray. With MR s dielectric materials we have the ability to acquire sharp looking glass with little work. There is however a couple of problems that could stump the artist during its use resulting in bad render errors. Hopefully, this info sheet will shed some light onto the myth that is Dielectric and get you rendering glass and liquids in no time. First, let s get some of the basic stuff out of the way for those whom have never worked with mental ray shader s and their integration into the Maya workflow. There are numerous ways to attach MR shaders within Maya so let s keep it simple. The best way to build a custom shader network for mental ray is to start off with a standard Maya shader like a Blinn, or a Lambert in Hypershade. Bring Blinn to the workspace and then display the input and output connections, as shown in figure 1. figure 1 Mental Ray shaders will always attach to the shading figure 2 group of a particular shader like our Blinn. Bringing up the attribute editor for the blinn1sg and then dropping down the MR tab displays all the connections for Mental Ray shaders, there are allot, but most often you will only use a couple and they are pretty self explanatory figure 2. Like any other attribute in Maya clicking the little checker icon will bring up the create render node window figure 3 for mental ray shaders. figure 3 Any questions you may have regarding this list seek the Maya help docs. On the left hand side of the window under the heading Rendering and Render Setup there is a little section titled Mental Ray Reference figure 4. Be warned that allot of the reference material is coding examples and more, shall we say, not so friendly techy jargon. Nonetheless, it can be beneficial as I will demonstrate later. Alright, with that little bit of the way that s build our glass shader. figure 4
Starting with a fresh Maya scene build a simple cup out of Nurbs, or Polys, like the one I am using shown in figure 5. Here I have a simple revolved cup made with nurbs and one spotlight shinning onto the surface. One thing to note is I have kept the nurbs patches for the outside, interior, and lip of the cup separate. Its best practice if you model your glass in this fashion and you ll soon see why. A render of this scene is demonstrated in figure 6. figure 5 figure 6 Next, open the Hypershade and create a Blinn shader, rename it to glass and bring up the attribute editor. Change the following to the settings displayed in figure 7. Highlighted elements are the ones I changed. figure 7 Once you have adjusted your settings attach the shader to the glass element, or nurbs patches. Now, open up the Render Settings and change Render Using to Mental Ray and then set quality to production. Fire off a test render and you will see something like figure 8. figure 8 Not too bad, a glass most people are happy with. Put a little reflection on it, some fake fresnel and it may suffice. Ah, but we can make it better!!
Alright time for MR to work its magic. Bring up the Hypergraph and open the attribute editor for the glass shader. Click the icon Go to Output Connection. The tab should switch to blinnsg1. Under the mental ray tab -> custom shaders locate and click the checkered box next to Material Shader and then select Dielectric Material figure 9. Your attribute editor will change to the settings for the newly attached material figure 10. figure 9 Leave everything default except Ior which is our refraction index for the medium, in this case glass, which for all intents and purposes is 1.34. Additionally set phong coef to something like 200. Close this window and fire off a render. You may get something like figure 11. If you did and are now confused, fantastic, just like everyone else who attempts a glass shader. If your render came out like nice glass, will that s awesome too, however you should still read what follows because one day you will encounter this problem its guaranteed. figure 10 This is a common rendering error when working with this particular material so let us find out why by opening the Maya help docs and looking up dielectric material. The description, presented below, sheds some light on the inner working of the dielectric material and provides the fix. Two achieve physically correct simulations it is important to use the correct surface interfaces. When modeling a glass of cognac three different interfaces are required: glass-air, glass-cognac, and cognac-air. The dielectric material uses the normals of the surface to distinguish the media on either side of the interface. For a dielectric-air interface the normals point into the air. For a dielectric-dielectric interface the normal point into a dielectric material which is "outside". To use the dielectric material the model normals must be oriented correctly unless the ignore_normals parameter is set to true. This shader cannot be used as a shadow shader. figure 11
Essentially this is a modeling problem concerning the direction of our surface normals. When a ray is sent out from the camera it hits the first wall of our glass and the shader basically goes Okay I have a ray hitting, because my normal points out to air I am entering a new dielectric material, lets start the calculation as the ray pass through the material it encounters the inner wall and says Alright I have just passed through one wall now the inner wall surface normal points toward the outer wall which tells me im entering another, new, dielectric material, guess I need to bend the light again. Resulting in no refraction and just reflection. Figure 12. How it should read is Alright I have just passed through one wall now the inner wall surface normal is pointing opposite the outer wall so I must be completely through the medium and I am now exiting back into air. Figure 13. Glass Profile Camera Ray Ray Hit Point (In and Out) Air Air or Liquid Ray bends through medium (Refraction) Surface Normal Air Air or Liquid figure 12 figure 13 Figure 12 is what we have happening within our render. Figure 13 is what we want happening. This is an easy fix and the reason why I keep the nurbs patches separate. For me I just select the inner wall and reverse the surface direction Edit Nurbs-> Reverse Surface Direction. If you modeled your glass differently display your normals to find out their direction. Select your object or patch of concern Nurbs Normal Display : Display -> Nurbs Componets -> Normals (Shaded Mode) Polygons: Display -> Custom Polygon Display (click little box and located and check Normals) Set your inner wall normals facing in, towards each other, and your outer wall normals facing out as seen in Figure 14. Agian to reverse normals on Nurbs Edit Nurbs-> Reverse Surface Direction. On Polygons Edit Polygons -> Normals -> Reverse. After we have our normals oriented correctly fire off a render and now we have something figure 15!. That s looking more like glass, but we need some shadows. Bring up the light and turn on ray traced shadows. Fire off another render (figure 16). Looking good, but there is a problem with the shadow. We can t see half of it! In order to correct this we have to use a MR Light Shader. figure 14 figure 15
In order to correct this we have to use a MR Light Shader. Again bring up the attribute editor for the spotlight, scroll down to the mental ray tab, open it up and find Custom Shaders, then light shader. Click the checkered box next to Light Shader and then select Physical Light (figure 17). You could use spotlight but I like this light shader the best. This shader is controlled by the colors value. Double click the color swatch and set the value appropriate to your scene. After a couple of test renders you ll get it. I left it at the default, you may need to adjust. Here is the render (figure 18). figure 17 figure 18 Turing on caustics is a simple process. The only bad thing is intensity, exponent, and amount is going to depend on the scene you are using. Therefore, play with the settings until it looks good. To start open up Render Settings and turn on caustics leaving everything default (Mental Ray Tab -> Caustics and Global Illumination). Now open up the attribute editor on the light and under Mental Ray, turn on emit photons. These are the settings I m using during a close to final render. Looking really good, but it still has problems with the shadow. The shadow is not rendering light passing through the glass, its just solid and thus incorrect. So what s the fix? Well, it isn t much of one. I still have yet to locate a way in which to render out shadows that reflect the transparency of an object. Honestly don t think there is a simple way in MR. The only way to convey light passing through the glass is to turn on caustics, can you say render times! Oh well, least it s going to be a correct simulation of light through a dielectric material. For the Light : Render Settings: After a long wait, nada (figure 19) No good. One more step. In order to get correct caustic simulations from the dielectric material you have to attach one more MR shader, a photon shader to your glass. I mean MR has to know how to calculate photons hitting a medium like glass right? Anyway ways bring up the Attribute Editor for the glass shader group. Hypergraph->double click glass-> show output connections Locate photon shader, click the checker box, then attach the Dielectric Photon Material. Set the Ior to what you set before 1.34. Same process as attaching the original Dielectric material to the blinn s shading group, just a different location and shader type. Fire off another render and wow, look how pretty.
That s about all there is to making glass in MR; pretty simple stuff and a good way to introduce working with MR Shaders and how they interface within Maya. You can use a duplicate of the glass material, same process, to render the liquid in the glass. The primary difference would be, of course, the color and transparency. In addition make sure to specify the in the Dielectric Material and in the Dielectric Photon Material the Color In and the Color Out. Ray coming in hits the glass that s the color in. Ray exits the liquid so that would dictate the color out. Here is a render with everything the same expect for the items I mentioned prior. Remember glass is very dependent on the scene. Since there is no environment in my simple scene the glass looks a little flat and plastic like. But I tell you true, once you set this up in an environment with stuff and colors to reflect and refract it really pops and sells. Addition: I wanted to discuss the normal direction problem because I think it highlights issues many people run into and don t know the cause. It also allowed me to further the discussion on the Dielectric Material, the way a Ray traces refracts through a medium like glass, thus providing you with some more insight. However know that in some cases you can remedy the rendering errors by checking Ignore Normals in the settings for the Dielectric Material. I advise against it because I never like to leave it up to the renderer to decide what s best. Setting it up correctly to begin with and understanding why is very important advice and remains the best work method too. However, if it works use it!!! 2006 Howard Coulby