2009-11-13

Fire and Ice - rendering Diamonds and Gems in mental ray



They say Diamonds are a Girls Best Friend, but they can be a poor rendering guys worst nightmare.

One of the reasons is the characteristic property of fine diamonds known in the gem business as "fire" - the nice "pretty colors".
These stem from the fact that Diamond is a material with very high dispersion. It is also coupled with the fact that the "cut" of a diamond is specifically made to enhance the "fire" (dispersion) and "brilliance" (ability to reflect light back to the viewer) as much as possible.

But even before we get to the actual dispersion part of things, lets try to see what it takes to render realistic gem's without it first.

Setting up a scene for Gem rendering




We start with a ridicolously simple 3D model. Since I can't model worth crap, I downloaded a diamond cut according to the classic "round brilliant" from here, and made this supercomplex scene:



First, make sure you have your gamma correction enabled, diamonds, like all physical things, should be rendered linearily.





Not gamma corrected - ugly

Gamma corrected - good

Now we need some decent lighting. We need to follow physics as much as possible. Especially we want to avoid nonphysical "hacks" like specular-only lights, lights without shadows, and other things. We really want to light this in the same way a real photographer would light his scene, with realistic lights with all their realistic effects.

In 3ds Max the easiest way to do this is to use the Photometric lights. This will become especially important later when we get to the caustics, because the Photometric lights automatically gives us the proper photon energy for free. That is a little bit more work to achieve in Maya or Softimage (XSI) because you have to set the photon energy up manually.



A key point here is that we make them Target Lights (i.e. spotlights). This is so we get the most efficient distribution of photons. If we didn't give them a direction to shine, our photon emission phase would be much slower because so many photons would get lost in empty space. Make sure you aim the lights where they are needed - this is especially true with caustics.


Since we are using photometric lights, this also requires us to use an exposure control. We will be using the mr Photographic Exposure control, and we need to make sure to check the "Process Environment and Background" checkbox:



We also want to make sure they are area lights. This gives us the nice soft shadows and "soft" lighting that you would use for an artsy product render like this:




Point lights - hard shadows

Area lights - soft shadows

So we enable area lights:



Now these two arealights are not enough, we need indirect light, and to light the scene from the environment as well. To do this we need turn on Final Gathering.

In Maya and Softimage, the very act of doing this will implicitly light the scene from the environment. This doesn't happen in 3ds Max unless we put in a "Skylight". So we add one of those to the scene, and very importantly, set it's option to "Use Scene Environment".




Now we have a little more light:



We are using a default Arch&Design (mia_material) on the gems.
Let us make it more gem-like by a) turning our diffuse to 0.0,
and b) turning our transpacenty to 1.0:




Diffuse = 0.0

Transparency = 1.0

The automatic energy conservation of Arch&Design (mia_material) already makes this a decent looking transparent looking thing... transparency is complete, but still "overridden" by reflections, and the reflections do depend on angle, just like on real dielectric materials. However, by default it is not basing it on the index of refraction, but a custom curve. We need to fix that by setting it to IOR mode!



This makes our transparency a bit "clearer":




Curve mode

IOR mode

The scene is still looking rather dull with the gray background. Diamonds (like metals) are not so interesting looking in-and-of themselves, but area all about reflections and very very bright "pings" of light. Some people may be tempted to cheat this with a bunch of specular only lights, but why cheat when there is a real reason for such effect - reflections of Bright Things.

And what's the easiest way to get some Bright Things, if not an HDR environment map? Lets slap in some interesting HDR environment map. In 3ds Max you do this by adding a Bitmap to your Environment slot, and make sure to set it to a spherical environment: (Note: When doing this you may need to play with the Physical Scale to avoid having the environment map render dark, see here)



This should give us something much more interesting to look at. And note how the background lighting changed in tone to match the environment? This is because Final Gathering is picking up the new environment and getting it's lighting from there:



Actually FG is even picking up some of the concentrated bright spots and creating a form of "faux caustics". We will get to real caustics later, but for now it is looking pretty.

To make our image look nice, we are using the mr Photographic Exposure control. To make it even nicer we are going to do some modifications.

First, images like this, where we want to focus on some nice center object, always benefit from a bit of vignetting (darkening of edges):



Secondly, since these are diamond renders, and we truly want strong "pings" of light, we should turn up the highlights, to make the really bright bits be really really bright:



These are the knobs we used to do this:



And here comes a final little subtlety. This is really hardly a visible change, but I like it. The model is made with absolutely perfectly sharp edges. And a Jeweller will want to sell you on the idea that his diamond is perfectly flat with totally sharp edges.

But reality have no such thing as 100% sharp edges, so I love to throw in a teeny bit of edge rounding, which will make edges catch "glints" and look more realistic. Cue the mental ray render time round corners shader thingy, and you will get...



...this. Yeah, not such a big difference, I know. It does more on other shaped Gem's than the round Brilliant cut, though, so I still suggest you use it.

Taking a shortcut



Another way to quickly get to the place we are now with the material, and be certain that all the settings make sense, is to base it on the Physical Glass preset. All we need to do is to load the preset, and set enable the corner rounding feature (which is off in this preset), to get a very quick and decent result:



However, we are using the default index of refraction of glass, which is 1.5.

The IOR of diamond is 2.42 - so let's change that:



To really make sure we get every single nice "glint" and "ping" of the material, we will disable a speed optimization in the material intended to skip "unnecessary" reflections on the inside of glass objects, which tend to be very weak. But we don't want to loose any light, so we turn that feature off.



Color Gems



Now these gems look a tad blue. This is because the "Physical Glass" preset introduces some blue. Before we go further with the diamonds, lets discussed coloring our gems for a moment.

The quick and "obvious" way is to reach for the transparency color swatch, and set this to a color. While this gives something (which can look pretty nice), it is not physically accurate:



This is because it modifies the color of the ray "at the surface" of the object, whereas real colored transparent object modify the color of the ray gradually as it travels through the medium.

Looking at the gems above (rubies, perhaps?), the small ones are just as deeply red as the big one, and the tip of the big one is just as deeply red as the thickest part of it. That doesn't look... correct.

What we need to do is to enable attenuation through the medium instead. To do this we need to set our transparency color back to white (basically, treat the surface itself as completely transparent), and move to the falloff settings within the material:



We can use the same color as before, but we just have to set up a distance; at how thick a piece of material would you expect to see that color? Thinner than this will be less colored, thicker will be more deeply colored.

NOTE: It is important that this color has no component of 100%, and no component of 0%. If you were to set it to 1,0,0 red, it would be just as bad as the nonphysical setting. A better "red" would be something like 0.9,0.1,0.1, meaning, it lets through a lot (but not all) red, and very little (but not zero) of the other colors.

Here is our result:



But ideal diamonds are pretty much completely transparent, so for our excercise we will turn this falloff inside the mateial off completely! Uncheck the "Max Distance" and get:



We are getting somewhere. One further thing to ensure the largest amount of nice shiny "pings" in our material is to set our area lights to be "visible". Because most glints in a diamond is a reflection of an actual light. Turning this option on will render the area lights as superbright surfaces, that will then be seen refracted through our diamonds.



Caustics



Finally, it is time for those elusive Caustic effects. First we must make sure the material is set up to actually do caustics, since Arch&Design (mia_material) has an explicit option to NOT do that. If we used the "Physical Glass" preset, this will already be set up for us, but lets make sure:



Also we must make sure that caustics are turned on in the render itself. To get nicer "sharp" caustics, I tend to lower the number of photons per sample, and set the filter to "cone".

Generally, the Multiplier should always be 1.0, but we can allow ourselves some artistic licence here and turn it up a tad. But in general, since we are using the photometric lights, we should be getting the physically correct caustic brightness out-of-the-box. If they seem to weak, its probably beacuse people intuition of how bright they "should" be tend to be very overestimated.

We get this image:



Notice how the shadows actually became darker? This is because they were previously faked by simply attenuating the light a little bit, bit now the light is properly concentrated in the caustic effect instead. So this is correct.

A final touch on this image is to apply some glare.

Both real world cameras and human eyes perceive a "glow" around superbright objects, partially due to scattering in the atmostphere, but actually much more due to scattering in the light path (lenses) and the imaging surface itself (the film, the CCD, or our retina).

When adding the "Glare" output shader, we get the following image:



Notice how it looks much brighter without actually being any brighter at all. That's psycho-optics at work. A white pixel just looks white. A white pixel with a glow around it, and you'll be reaching for your sunglasses.... :)

And now - finally - time for Dispersion



Dispersion is when different wavelengths refract differently. I guess the most obvious case of this is a rainbow.

Real sunlight is a spectra containing basically an infinite number of wavelengths at once, and each of the different wavelengths will refract slightly differently... i.e. when a sunray hits a surface, one would (in principle) need to trace an infinite amount of rays around the scene to get the "real" effect.

Computers aren't very fond of doing an infinite number of things - at least not if you want them to ever finish. So there are several ways to simulate this w. various techniques.

The technique we will be using here is a very low-tech one - we simply render the scene multiple times with slightly different IOR's, colorize each of the renderings based roughly on the "color" of that wavelength, and combine the result. Et voila, we have a dispersive render.

To aid in this I slapped together a little piece of maxscript. Go to your Maxscript menu and choose "Run Script". A small dialog will pop up with some options.

Simply put, the script will render your image multiple times, while modifying the IOR of your material. But to do this, it needs to know what "your material" is.

It tries to be clever and find any material named "Diamond", but if it doesn't find it, you will have to click the "pick material" button, and choose the material from the scene that you are using (in Instance mode).

Then you need to set the IOR you want it to use, and how the amount of "dispersion". In gemology "dispersion" is pretty much defined as the change in IOR across the visible spectrum, so I tried to mimic this in the script, but it's a bit hacky and probably not accurate at all, so take it for what it is.

When you are done setting up, you can hit the "Do Dispersion Render" button. (Note: The script does not save the image, you will need to do that yourself from the image window)

The "3 bands" mode does three renders, one each for red, green and blue, and looks like this:



The "6 bands" mode does six renders, for red, yellow, green, cyan, blue and magenta, and is a more subtle effect, but more likely to yeild a "nicer" looking rainbow effect:



And as a final pièce de résistance, we can enabled depth of field on the camera.

In 3ds Max, this is done by using a 'multi pass render effect' on the camera. This is a bit of a misnomer because it isn't really a "multi pass" effect at all, but it re-uses the UI concept of other 3ds Max "multi pass" effects, so that's where you'll find it. Sorry, it wasn't me who put it there :)

You simply set the f-stop of the camera, and you will get the physically correct depth of field assuming that

  • your scene units are properly set up, AND
  • your Aperture Width (in the render dialog) makes sense.


That will give you this "ultimate" render - and we are pretty much done:



Of course, we can exaggerate the dispersion effect for arts sake (simply turn up "Dispersion" a bit):



Finally, the script also supports a somewhat hacky "chromatic abberation" mode, where it introduces the Lume "Distortion" lens shader, and modifies the pincushion/barrel distortion slightly for each of the colored renders, if you want to go really Crazee. This is one result of that:



Hope this was helpful.

Unfortunately, you can't cash these diamonds in a bank, nor sell them on eBay...

/Z



60 comments:

DarkNemos said...

Great tutorial. Thanks.

But will there be a dispresion shader built into mental ray in the future? I think finalRender has it.

Doerge said...

Very cool. Thanks.

Could you outline a more high-tech approach, that doesn't include multiple renderings?

Arie said...

Beautiful render, and thank you for sharing the technique!

James said...

perhaps using the raylength to attenuate the color?

Jenni said...

Outstanding, as always. Beautiful render, and great techniques.

Doerge said...

@James
Hmm.. in my head that would still involve multiple renderings or am I misunderstanding you?

Dmitry said...

Great job, but am I right that it is impossible do the same in Maya because of using maxscript for dispersion?

Dispersion - that is the problem when I try to make diamond renders in Maya. All the settings of your scene can be easily done in Maya except dispersion...

Doerge said...

@Dmitry
You can also do it in Maya. The max script is only rendering out several versions with slightly different IOR and then colorizes them differently and combine them to the final picture.

You just have to do it manually (or setup your own script).

Yacino said...

thanks u,for help, still waiting for built-in shader....

Hamilton said...

I still dream of dispersion built-in to the mia_matrial shader. It's one of the few features missing.

polyvore said...

Uhhhh, Can't you juse use a Combination of Shellac Materials with Refractive values Set to R, G, B For each with the Different IOR's for this rather than re-rendering the entire scene?

Also works in Vray Blend material where each shaders blend value is RGB

jigu said...

does script work at all? I tried but even after 3 passes of rendering, I didn't successfully get the dispersion effect. Is it specifically limited to your diamond model only?

jigu said...

script didn't work in max 2009 64bit but it worked only in max 2010 64bit.. Thank you this! Really nice hack.. I wonder how would do you do compositing in photoshop if you have different RGB renders with IOR?

jigu said...

script didn't work in max 2009 64bit but it worked only in max 2010 64bit.. Thank you for this! Really nice hack.. I wonder how would do you do compositing in photoshop if you have different RGB renders with IOR?

JOHANN MOISÉS , Maringá ,PR - BRASIL said...

Very nice Master Zap!
Thank you and have a nice day man! =)

ytsejam said...

great Zap

Web Master said...

HI master zap. Very nice tutorial,
Can you make a tutorial about rendering vray like interior in mr in max or maya.

ArtGhost said...

amazing, nice tut

ArtGhost said...

great, thats awesome, nice tut

Tom said...

Interesting method Zap, Strangely enough, i recently had to make a diamond in 3ds with mental ray.

My Solution was to create 3 lights that had their position offset very very slightly. Each light was either Red, Green or Blue.

This means that when the caustics are used, it breaks up the light into their colours but when the light hits a surface before a bounce or scatter it remains white.

Here is the render:

http://fc09.deviantart.net/fs51/i/2009/295/2/5/Diamond___Album_art_by_Duophonix.jpg

Tom said...

woops, link doesnt work,

try this:
http://tiny.cc/X2Jm6

ytsejam said...

Hey Zap.... do you want to change your Diamonds with My Diamonds?

http://mayadvance.blogspot.com/2009/11/make-your-diamond-farm.html

info said...

Great tutorial/ sollution, thanks.

But I'm wondering about one thing:
how is it you are able to use Area-shadows as they are not supported by MR ?

Or did I miss something ?

grtz. T

Master Zap said...

> But I'm wondering about
> one thing: how is it you are
> able to use Area-shadows
> as they are not supported by MR ?

I use area *lights* - the proper way to do area lighting. These use raytraced shadows. The "area shadows" shadow type is a horrible hack for the Scanline rendererer to fake proper area lighting, never use that!!!

mental ray supports all the photometric area light types, as well as it's own "mr Area Spot" and "mr Area Omni" of course.

/Z

Xian said...

Hi Zap!!

Thanks for this amazing tutorial and for all the time you took to write it.

I'm a student and right now I'm learning MEL. I took your MAXScript and tried to translate it to MEL, as an exercise.

I haven't been able to find a function or a process like the "pastebitmap" you used, so I just rendered the images and comp them in Nuke to try them out.

I get a beautiful dispersion effect in the caustics, but in the gems themselves I start to get some not so beautiful results.

I think I'm doing something wrong.

I uploaded two images. First one without Nuke, and the second is the result of rendering 3 images with a dispersion of 0.044 and comp them in Nuke. Could you please help me to find out what is happening?

www.chrisgranados.com/diamantesFinal01.jpg
www.chrisgranados.com/diamantesFinal02.jpg

Thank you very much for your time!!!

Chris Granados

Darvinius said...

Hy master zap,
indeed very realistic renderings, but how much time do you need for duplicating such a setup.
I have tried for hours and hours to duplicate your result without success.
Could you provide the scene whit the setup for study purpose. I have encountered a big problem relating the normals of the object. Do i need to clear all normals or to let them at 45 (angle)
And, i have seen that on a 8 core 8 gigs ram dell workstation this renders reeeely slow.
Its veeeeeery realistic render, but not efficient, could you make an alternate tutorial for obtaining such a result whit less render time(fake reflections, caustics ,etc)?
Thanks in advance.

Strob said...

Hi Zap. Thanks for this tut.
I got a problem trying to follow it though. I am getting a lot of dithering in the reflection and refraction. I can see the same dithering in your red gems but it is worse in mine.
Do you have an idea about what is causing it? Could work for stills but for animation would be more noticable I think.

Strob said...
This comment has been removed by the author.
Strob said...

The dithering i get is due to the Disc shape of the photometric light. The larger the disc the more I get noise in the specular...

Is there any samplign we could increase to solve this...

hglr said...

Hi Master Zap :)
Very nice tut :)

I use HDRI map in Enviroment slot in MR Arch&Design material. This gives you more freedom in your scene.

My diamond link -
http://www.orkastudio.com/diamond_ok.mov

google?lol said...

3 things,

1.
you also need to increase and activate the "transluency" of the material, my stones were rather dark without it

2.
you need to activate "generate caustics" in the stone's object properties

3.
if you intend to use it for class maybe explain your setup a bit more detailed, distances, light intensity and position, etc are vital for good render results

furthermore did you say somin along the lines "oh a brilliant, a rather cheap and easy model", well lol... i guess that was some kind of a joke now wasnt it? 90yrs after the tolkowsky cut and the diamond nerds still aint sure how to do one properly...

anyway, great tutorial, thanx for the effort, TAK!

Lorne said...

What is the equivalent to that Glare node in MR for Maya?

I don't see it anywhere under the MR Lens Shaders.

Brent Scott said...

Amazing tutorial but I can't do alot of that in XSI mostly because I don't know how. I attempted this but it looks like glass.
http://area.autodesk.com/forum/autodesk-softimage/rendering/shading-a-jewel/
GIGAX

review said...

It is good to see that information, really like to share this, this database really helps, Thanks for the information.


Web Development Karachi

Jay St M said...
This comment has been removed by the author.
Jay_St_M said...

Hi, Master! Thank you very much for the lesson... but...
It's my test scene:
http://files.mail.ru/52ERZF?t=1
(scenefile "desperado.max" is here for downloading: http://files.mail.ru/BUTCYF)

Final frame, rendered with "dispersionhack.ms" script:
http://files.mail.ru/68U2ZH?t=1

Caustic is here, but DISPERSION isn't...
I've tried to render this scene one and half million times, checking every parameter, varying "Dispersion" etc.
Script is really working, "bluring" caustic effect, but in any of three (or six) steps THERE'S NO COLOURS!!!

What's wrong with me? What should I do? HELP ME PLEASE SOMEBODY, I'm too young to go mad!!!
And GREAT thanks for your time.

Stefan said...

Hej Håkan "Zap"
Your pictures seams to lost there connection.

Mvh Regards
Stefan

abcde12345 said...

zap-meister~
i'm using maya 2011 and i can't seem to find the glare shader anywhere...does it even exist for maya? if not is there some way to replicate the effect? since the glare is a post process, can it be done easily in post or is there any 3D info contributing to the solution? thanks in advance.

Matthew Shaw said...

> I use area *lights* - the proper
> way to do area lighting. These use
> raytraced shadows.

Sorry but am I missing something here? In the tutorial you show you use the photometric target lights, not the "mr area spot/omni". I'm unable to achieve the area shadows with these lights as the "area shadows" shadow type isn't supposrted by MR, and the "mr area spot" aren't photometric. Could you please explain how you achieved the area shadows with the phtomoetric targets?

Cheers for the help, great tutorial.

Master Zap said...

Not only the "mr Area..." lights are area lights, the photometric lights are also area lights.

I know this may be nonobvious to the naming, but this is the case. Do not think only the "mr Area X" lights are area lights.

The legacy "area shadows" feature is something different, intended for the 3ds Max scanline renderer, never use that with mental ray area lights, always use ray traced shadows for mental ray area lights.

/Z

niceman said...

Hi,In maya,how create 3bands effect?

Mohit Shukla said...

Sir, I did everything according to you... but I cant convert spot my photochromatic light to spot area light, also unable to get dispersion wid caustics on floor....
M much worried how to correct it.. plz help...!!!

Sasa Drobac said...
This comment has been removed by the author.
Sasa Drobac said...

hi zap,

Could you make a maya dispresion shader?

thx

Irina said...

Please, write about the Lights propely.I am not that professional...so spent the whole evening.Feel tired and frustrayed.
*Sexy Girl

Martin said...
This comment has been removed by the author.
Manie Bhatia said...

Hey Zap...data a "LIFE SAVER" tutorial...I just hv 1 doubt..I want to render a sequence using your maxscript..How can i???

Thanks once again for the tut...:)

MentalAss said...

Hey Zap.

I spent the whole day, literally, around 20 hours, going through this tutorial. I've been doing 3D for 3 years now, I totally understand you and thank you so much for this tut.

Here's my outcome, I swear i've done something wrong.

Thanks man and take care.

Mr. Gibby said...

ZAP,

Thank you for spending the time to make this great tutorial with quality renders. I can't imagine how busy a person like your self must be but if you have anytime to take a peak at my scene file I would really appreciate it.

I am able to reproduce your results until I get to the step where you reduce the diffuse color and increase the transparency. My diamonds don't have a clear glass quality.

If anyone has successfully reproduced Zap's tutorial in Maya and would be willing to let me look at their scene file or help me with mine, I would be grateful.

Been working on this for two days with unsatisfactory results, please help.

Thanks,
Michael

mia no transp. no caustics

http://clients.kampgrizzly.com/gibby/diamonds_red_01.tif

mia / physical glass presset / ior 2.42 / transp. 1.0 / caustics / hdri pluged into image based lighing /

http://clients.kampgrizzly.com/gibby/diamonds_01.tif

mgibson505@yahoo.com

Mr. Gibby said...

Here is my scene file.

Maya 2011 hotfix3 64bit

http://clients.kampgrizzly.com/gibby/diamonds_v07.mb.zip

3d rendering said...

nice tutorial, i use it in my job. thanks

11 said...

hello i live in taiwan

my english is so bad sorry

i use maya2009

can you teach us

how to do the same rendering Diamonds in maya?

thank you!

Unknown said...

Hi Zap

I have been trying to get the same effect but I think due to lack to light setup explanation I can't get this effect. Care to upload the scene including the diamond material? I can reverse engineer and learn from it.

Thanks

Rajendra Kr. Sanger said...

hell sir i am making a turntable of diamond but how to add a sparkle look like this video ref http://www.jamesallen.com/#!/engagement-rings/side-stones/14k-white-gold-0.54ct-common-prong-round-shaped-diamond-engagement-ring-item-1105
rajendrasanger@gmail.com

fckdupathens said...

Great tutorial covering the 'Fire & Ice' effect. It's unfortunate that mental Ray fails to support this itself without having to rely on your fantastic script.

I managed to get a suitable effect using the Max Falloff parameter by using a combination of a mixed Environment map a falloff (light/shadow) however it's only a cheat effect to similarly catch the ray effect and influence the shadow color.

I'll cover that on my blog shortly which can be found here :

http://esadude.wordpress.com

If you have no objection, I'd like to add your tutorial to the link when It's finished.

As a matter of curiosity, is there a way of using the script for an animation sequence or is it just frame specific?

William Banti said...

Hi Master Zap.

Thank you for this tutorial;)

I can share with you another method that I found after a lot of research.

I use shaders, Diffraction.dll Diffraction.mi

*.dll 64 bit=> http://www.shaders.moederogall.com/
*.mi=> http://www.maxplugins.de/mentalray.php?search=Diffraction&sort=Author

and prism_photon.dll and prism_photon.mi

*.dll et *.mi=> http://www.maxplugins.de/mentalray.php?search=Prism&sort=Author

You can downloaded the 3DSMAX scene at the end of the tutorial.
The tutorial are currently in French.

https://www.facebook.com/william.art.fr

William Banti said...

Oups, the link of tutorial
http://www.3d-station.fr/index.php?topic=23919.msg342879#msg342879

Riker Alvin said...

You should elaborate multiple renderings. please provide some data on high tech approach. Its about diamond shapes education

Riker Alvin said...

I was asking for the elaboration of multiple renderings. Its ok …..! Thank you… You’ve defined all information in proper way; awesome 3D models are easy to understand. Now I can assess the exact diamond value before selling my Diamond jewelry

GOAH KAOS said...

This helped me to look extraordinary gemstone, thanks Admin