Create a ‘Fresnel’ Render Pass in Maya

First off what is a ‘Fresnel’ render pass? At it’s most basic form a Fresnel pass in a matte which can be used to remove or reduce other render passes based on camera angle. For example if you where to stand front of a clean shinny car the side panels looks more reflective than the roof, this is because you are looking directly at the side where as the roof appears less reflective. Another example is the way water in a swimming pool looks dependant on whether you look direction down into the water or look across it. One way appears pretty much transparent where as the latter look more opaque. In order to fully grasp what’s going on where need to understand a bit of physics.

Reflection
Reflection is the change in direction of a wavefront at an interface between two different media so that the wavefront returns into the medium from which it originated. Common examples include the reflection of light, sound and water waves. The law of reflection says that for specular reflection the angle at which the wave is incident on the surface equals the angle at which it is reflected. Mirrors exhibit specular reflection.

In acoustics, reflection causes echoes and is used in sonar. In geology, it is important in the study of seismic waves. Reflection is observed with surface waves in bodies of water. Reflection is observed with many types of electromagnetic wave, besides visible light. Reflection of VHF and higher frequencies is important for radio transmission and for radar. Even hard X-rays and gamma rays can be reflected at shallow angles with special “grazing” mirrors.

reflection

Reflection of light is either specular (mirror-like) or diffuse (retaining the energy, but losing the image) depending on the nature of the interface. Furthermore, if the interface is between a dielectric and a conductor, the phase of the reflected wave is retained, otherwise if the interface is between two dielectrics, the phase may be retained or inverted, depending on the indices of refraction.

A mirror provides the most common model for specular light reflection, and typically consists of a glass sheet with a metallic coating where the reflection actually occurs. Reflection is enhanced in metals by suppression of wave propagation beyond their skin depths. Reflection also occurs at the surface of transparent media, such as water or glass.

In the diagram a light ray PO strikes a vertical mirror at point O, and the reflected ray is OQ. By projecting an imaginary line through point O perpendicular to the mirror, known as the normal, we can measure the angle of incidence, θi and the angle of reflection, θr. The law of reflection states that θi = θr, or in other words, the angle of incidence equals the angle of reflection.

Refraction
Refraction is the change in direction of a wave due to a change in its velocity. This is most commonly observed when a wave passes from one medium to another. Refraction of light is the most commonly observed phenomenon, but any type of wave can refract when it interacts with a medium, for example when sound waves pass from one medium into another or when water waves move into water of a different depth.

In optics, refraction occurs when light waves travel from a medium with a given refractive index to a medium with another. At the boundary between the media, the wave’s phase velocity is altered, usually causing a change in direction. Its wavelength increases or decreases but its frequency remains constant. For example, a light ray will refract as it enters and leaves glass, assuming there is a change in refractive index. A ray traveling along the normal (perpendicular to the boundary) will change speed, but not direction. Refraction still occurs in this case. Understanding of this concept led to the invention of lenses and the refracting telescope. Refraction can be seen when looking into a bowl of water. Air has a refractive index of about 1.0003, and water has a refractive index of about 1.33. If a person looks at a straight object, such as a pencil or straw, which is placed at a slant, partially in the water, the object appears to bend at the water’s surface. This is due to the bending of light rays as they move from the water to the air. Once the rays reach the eye, the eye traces them back as straight lines (lines of sight). The lines of sight (shown as dashed lines) intersect at a higher position than where the actual rays originated. This causes the pencil to appear higher and the water to appear shallower than it really is. The depth that the water appears to be when viewed from above is known as the apparent depth. This is an important consideration for spearfishing from the surface because it will make the target fish appear to be in a different place, and the fisher must aim lower to catch the fish.

refraction

The diagram on the left shows an example of refraction in water waves. Ripples travel from the left and pass over a shallower region inclined at an angle to the wavefront. The waves travel more slowly in the shallower water, so the wavelength decreases and the wave bends at the boundary. The dotted line represents the normal to the boundary. The dashed line represents the original direction of the waves. This phenomenon explains why waves on a shoreline tend to strike the shore close to a perpendicular angle. As the waves travel from deep water into shallower water near the shore, they are refracted from their original direction of travel to an angle more normal to the shoreline. Refraction is also responsible for rainbows and for the splitting of white light into a rainbow-spectrum as it passes through a glass prism. Glass has a higher refractive index than air. When a beam of white light passes from air into a material having an index of refraction that varies with frequency, a phenomenon known as dispersion occurs, in which different coloured components of the white light are refracted at different angles, i.e., they bend by different amounts at the interface, so that they become separated. The different colors correspond to different frequencies.

So what does a ‘Fresnel’ pass look like and how do you make one in Maya?

fresnelPass01

First of all create a new ‘Render Layer’ and add your objects.

fresnelPass02

Next change your ‘Render Settings’ to use mental ray as the Renderer, no need to create a render pass as you just need the standard beauty which you get for free.

Now in your ‘Hyper Shader’ create three new nodes all from the Maya Nodes section. Firstly a ‘surfaceShader’, secondly a ‘ramp’ and lastly a ‘sampleInfo’ Node

fresnelPass03

Next edit the ‘ramp’ Node removing the central colour and then changing the top colour to black and the bottom colour to white. Changing the amount of black and white in this ramp is the way you fine tune the Fresnel effect.

fresnelPass04

From here we need to wire all the nodes together. Firstly, via the ‘Connection Editor’ (it will pop up if you drag one node onto the other via the middle mouse button), connect the ‘ramp.outColour’ to the ‘surfaceShader.outColour’. Then connect the samplerInfo.facingRatio’ to the ‘ramp.vCoord’.

fresnelPass05

Now making sure you have your new render layer selected, right click on the ‘surfaceShader’ and select the ‘Assign Material Override for (name of your render layer)’.

For this type of render layer there is no need to Batch Render your scene, simply doing a standard ‘Render Current Frame’ will render your new custom Fresnel pass.

fresnelPass06