home about gallery publications education links contact


..::refraction colours::..

Even though Mental Ray gives us a few additional glass-orientated shaders, it does not take into account the refraction of light within the object / material. Refraction is a term given to the way light is separated into its spectrum; in this case we are dealing with white light. White (visible) light comprises of colours from red through to violet; the most commonly used method of viewing this would be using a glass prism which would take the incident ray of light and separate it. However, we don’t need to go that far with our refraction technique as we only need to give a visible interpretation of the effect.

As the light passes into the object (preferably a faceted surface, such as a cut diamond), the light splits up, therefore the derived colours will not be visible on the exterior of the surface; they will be broken up when passing into the new medium and will therefore reflect off the inside of the object (with some light passing back out of the object) due to internal reflection. This “broken” light will therefore be reflected back to the point of incidence (and to adjacent surfaces naturally due to light dispersion) causing a colour tint on the interior. This reflection will be reflected again, and again and again, resulting in all of the interior surfaces being affected by the broken light spectrum.

However, this will not be as apparent if you view the object in real-life; the surface(s) directly in front of you will appear to have a reduced, if no, broken light present. This is due to the visible light you are seeing is being refracted straight through the object to the opposite side (provided the opposite side is relatively parallel to the viewed surface). This will result in the effect being mainly viewed on the perpendicular.

Moving around the object we will also be able to see colour changes, not only due to the reflection and refraction of the exterior environment (which must be present in our CG scene, else the overall effect will not appear convincing; even if a diamond is viewed in a black case, there is still external light and surfaces reflected and refracted in it!), but due to the different rays of internally diffracted light from the incident ray hitting the surface under which we are viewing.

So how can we recreate this effect using 3ds max? As mentioned, we are going to be using Mental Ray, purely for the effective glass shaders, but we are also going to have to use a scene to start with. The basic scene is part of the resulting HDRI Q&A from a previous issue that we can re-use as it has already got the lighting set up; all we need to do is to convert it to using Mental Ray, which is simply a case of enabling the Mental Ray renderer, creating our diamond object and assigning a Mental Ray material to it, and finally add a Glass shader with the right Index of Refraction for a diamond to the material. However, we still need to create refraction effect.

We have determined that the refraction effect is on the opposite side of the object, is only visible on the perpendicular and only appears around the object due to internal reflection. With this in mind, we can create a stepping gradient that contains all the colours of the rainbow and is set to be displayed based on polygon normal direction. Due to the objects not being smooth (thanks to the introduction of a Smooth modifier which has Auto Smooth disabled or the ability to turn smoothing off at the base level) these faceted surfaces will change colour abruptly as we move around the object as desired. The front masking is simply a case of not having colour in that part of the gradient (white being set as the original diamond colour), which has its intensity also controlled by a Falloff map set to Shadow/Light.

3ds max 5 users, even though you don’t have access (by default) to the Mental Ray renderer, you can still create a comparable result using the standard Scanline renderer; please see the Tips section for more information.

Enlarge Screenshot
Load in the refraction_start_max5.max file included on the cover cd. Select the Geosphere in the scene and turn off Smooth. Open the Render panel, open the Assign Renderer rollout and change the Production Renderer to Mental Ray.
Enlarge Screenshot
Open the Material Editor and create a new Mental Ray material; label it Diamond and assign it to the Geosphere and ring tube object in the scene. Add a Glass (lume) shader to the Surface slot in the Basic Shaders group. Turn on the material background to see the material swatch in action.
Enlarge Screenshot
Set the Index of Refraction of the Glass (lume) shader to 2.417; the IOR value of Diamond. Add a Mix map to the shader’s Diffuse slot, label it Refraction Perpendicular Mixer and swap the colours over.
Enlarge Screenshot
Add a Gradient Ramp map to this Mix map’s Colour 2 slot and label it Refraction Colours. Remove the middle Flag in the Gradient and set the Gradient Type to Normal and Interpolation to Solid. Set the flag at position 0 to RGB 176,0,255. Add flags at positions 45 (RGB 105,0,255), 56 (RGB 0,0,255), 63 (RGB 0,187,0), 69 (RGB 255,215,35), 73 (RGB 255,100,0), 77 (RGB 255,0,0) and 80 (white).
Enlarge Screenshot
Add a Falloff map to the Refraction Perpendicular Mixer’s Mix Amount slot and label it Refraction Control. Set the Falloff Type to Shadow / Light and set the Shaded colour swatch to RGB 100,100,100. Add an additional couple of points to this map’s Mix Curve and clamp them off as illustrated to create a defined lit and shaded area as illustrated.
Enlarge Screenshot
Open up the Render panel again and go to the Indirect Illumination tab. Enable Final Gather, set the number of samples to 100 and render off the scene. As we are using HDRI lighting for the scene, you may wish to tweak the Exposure a little.
Enlarge Screenshot
Out fin-al scene with diffraction colouring the internal perpendicular surfaces. Here we have two types of object – a solid spherical shape and one torus tube.
Download the max file!
Zip file to accompany.

..::tips::..

We could have simply used the Falloff map and the rainbow Gradient Ramp map to generate the effect by dropping the Gradient Ramp map in the Side slot and having a white colour in the front slot, then simply amending the Mix curve to restrict the amount of colour coming through from the Gradient Ramp map. However, as the method described in the next tip would require this map setup to be reworked even more, the setup described could be modified easier.

For those who do not yet have access to 3ds max 6, this process can also be recreated using 3ds max 5. Simply use a Raytrace material with an IOR set to glass / crystal / diamond with the Gradient Ramp map and masking setup in its Luminosity slot and you will get a comparable result (although the glass won’t look as nice!). However, due to this now illuminating the material, even with the lights all turned off you will have a slight glow…

…therefore, swap the colours over in the Falloff map, and invert the result, which will result in a map that only displays a colour in shadow when there is light present! You can even use HDR images with the TIFF format using the Skylight light and Light Tracer (although it may take a little longer to render the scene out!).

Even though we have used a material setup to give the impression that our objects are made from diamond, simply amending the IOR of the material will yield different material results. Try changing the IOR so that it resembles a clear vinyl material, for example, however should you do this you will have to tweak the modelling somewhat to remove any harsh edges from the mesh. This is due to the “manufacturing process”; try chamfering the harsh edges a little and smooth them off. You may lose some of the faceted effect, but the end result will be consistent for that type of material.

Initially published: 3D World magazine, Issue 52, June 2004.

Copyright Pete Draper, June 2004. Reproduction without permission prohibited.

www.xenomorphic.co.uk