Production Shader Examples

So, who wants to know more about the production shaders? Raise of hands? (See the introductory post, if you missed that.)

OK, I don't have time for an extravagant essay right now, but what I did do is to put a set of examples online.

The example uses some geometry (in some cases, our friend "Robo" pictured here on the right) and shows how to use this together with the production shaders, both to introduce our geometry into various backgrounds, as well as using features like the motion blur and motion vector code.

General Overview

The Production library does a lot of things, but one of it's specialties is to help us to integrate a CG object into a photographic background, with the help of a photo of the background and a photo of a mirror ball taken at the same location in the same camera angle as the background photo. So, to play with that, we need a set of backgrounds, with matching mirror ball photos.

As luck would have it, I happen to have just that. (Amazing, innit?) ;)

These backgrounds are available in this backgrounds.zip file. Please download that and unzip before downloading any of the demos scenes (I also apologize for not having time to put Robo into any of the Maya scenes, but he was out at a party the day I made those file and didn't come home until late....)

In a hurry?

If you don't want to read, but play play play, you can go directly to this directory and you will find the files.

Examples for 3ds Max 2008

The 3ds Max demo scenes are sort of "all in one" demos, demonstrating a scene using the mip_matteshadow, mip_rayswitch_environment, mip_cameramap and mip_mirrorball to put a CG object into a real background as described in the PDF docs.

The file robot-1.max puts Robo in my back yard, robot-2.max puts him on my dining room table, robot-3.max on a window ledge, robot-4.max out in a gravel pit (how absolutely charming place to hang out) and finally robot-5.max on my dining room table but at night, and some alien globules has landed...

They all work pretty much the same, i.e. the same settings only swapping in different backgrounds and mirror ball photos from the backgrounds.zip file.

The exception is the file robot-4-alpha.max which demonstrates how to do the same as robot-4.max does, but set up for external compositing (see more details below in the Maya section).

Examples for Maya 2008

The examples for Maya are more "single task" examples, and demonstrates one thing at a time.

mip_matteshadow1.ma and mip_matteshadow2.ma both demonstrate how to put a set of CG objects into a real background, using the exact same techniques as for 3ds Max above:

The file mip_matteshadow2b.ma demonstrate the same scene as mip_matteshadow2 but set up for external compositing (what is called "Best of Both Worlds" in the manual).

To recap from the manual briefly: In the normal mode (when you composite directly in the rendering and get a final picture including the background right out of the renderer, you use mip_cameramap in the background slot of your mip_matteshadow material, and in your global environment (in the Camera in Maya, in the "Environment" dialog in 3ds Max) you put in a mip_rayswitch_environment, which is being fed the same mip_cameramap into it's background slot, but into it's environment slot it is being fed a mip_mirrorball.

To do the "Best of Both Worlds" mode (to get proper alpha for external compositing, and not see the background photo in the rendering - but yet see its effects, its bounce light, its lighting, its reflections, etc. - one need to do a couple of changes from the above setup:

  • In the global Environment should still be a mip_rayswitch_environment as before, the only difference is that instead of putting mip_cameramap into it's background slot, you put transparent black (0 0 0 0).

    The trick in Maya is that you cannot put an alpha value into a color slot. We can cheat this by using the mib_color_alpha from the base shaders, and set its multiplier to 0.0.

  • In the background slot of your mip_matteshadow you used to have a mip_cameramap with your background. What you do instead, is to put in another mip_rayswitch_environment, and into it's environment slot (important, yes, the environment and NOT the background!) you put back the mip_cameramap with your background photo, and in it's background slot you again put transparent black (using same trick as above).

Having done this (as is already is set up in the mip_matteshadow2b.ma example) you will get this rendering:

This image contains all the reflections of the forest, the bounce light from the forest, the reflection of the environment from the mirror ball... but doesn't actually contain the background itself.

However, it has an alpha channel that looks like this...

...which as you see contains all the shadows. So compositing this image directly on top of the background in a compositing application, will give you the same result as the full image above, except with greater control of color balance etc. in post.

Maya in Motion

There is three further example files for Maya:

mip_motionblur.ma, which demonstrates the motion blur, and mip_motionvector.ma and mip_motionvector2.ma who both demonstrate how to output motion vectors.

I know these are rudimentary examples, but the day only has 48 hours... ;)

To quote the Governator: "I'll be bak".


Making Better Metal with mia_material

When using the Arch&Design (mia_material) in the various products, the manual mentions that to make metal, one should enable the "refl_is_metal" switch (shown here from the 3ds Max UI, but it's available in all products):

Metal Mode

When one does so, the color of the metal comes from the diffuse color swatch. However, most people stop there, and get a very dull looking material, and wonder "what wen't wrong?".

Well, not reading the rest of the manual is what went wrong ;)

Just kidding. Anyway, just turning on the "metal" mode doesn't make it look magically like metal. It looks more metal-ish but there is one more thing to do, take care of the BRDF curve.

When metal mode is on, the reflectivity (and the BRDF curve) drives the balance between traditional "diffuse" shading and reflective "metallic" shading. So if your reflectivity is zero, or you are at an angle where the BRDF curve is very low, you will be seeing mostly plain old diffuse shading, i.e. not very "metal" looking.

So what needs to be done is to pump up the Reflectivity value (probably to 1.0), and modify the BRDF curve to contain more reflectivity.

The default BRDF curve only contains a 0 degree reflectivity of 0.2, which isn't really very "metallic looking". One could change this to a higher value like so: (UI from 3ds Max shown, but exists in all products):

Making Metal More Metallic

This works pretty nicely, and most metals can be done this way. But still, it may look a tad "off" in how the reflectivity depends on angle.

Well, then we try the fresnel mode.

"What" I hear you yell, "Fresnel" is for dielectrics... transparent stuff... like water, glass and such. It is based on the Index Of Refraction. Metals aren't transparent, they can't refract stuff! O'le Zap's gone completely bonkers now!

Well... actually... no. Metals are indeed not refractive, and are indeed not dielectrics (meaning, electrical insulators). They are Conductors, and for some baroque reason these are also considered to have an "Index of Refraction".

Now, don't ask me how on earth someone came up with the idea of refractive metals or how this is actually calculated... I didn't write the laws of Physics (I just abuse them) so just trust me it's there.... and these values are high. Not your average "1.3" ish like for water, but values like "25" or "50".

So, if you turn on the Fresnel reflection mode and put in an IOR of 50 you get something like this (Again UI from 3ds Max coz it has the neat curve):

Mysterious Metal Magic

As you see from the quirky curve, the angular dependency of the metallic reflection is... odd. But when rendering this, the metal just looks a tad more... well... metallic:

Gold in the Sun

The above is a gold material under Sun&Sky lighting. It looks "ok", but not great.. why is that? Well, our visual perception of metals come largely from the reflections. While a totally empty sky is "ok" as reflection, it's not more than just "ok"... it looks dull. (But a photo of metal in a completely cloudless desert would look about as dull).

Lets try with reflecting the good o'le "Kitchen.hdr" environment:

Gold in the Kitchen

There, exactly the same material, only reflecting something "interesting". (And yes, a tad of Glare on top, and using the Photographic exposure... so sue me ;) )

Hope this helps in the quest for More Metallic Metals.



Production Shaders: "Hidden Treasures" of 2008

May I present to you, the "production" shader library.

What? Where? Production shaders?
Well, here's the story:

The Hidden Shaders

If you have installed 3ds Max or Maya 2008, you will have obtained mental ray 3.6, and with mental ray 3.6 comes the production shader library.

However, in neither of Max or Maya are these shaders exposed by default to the end user. They are hidden, and therefore "unsupported".

Still, they are there, and they can be used. But to do so, one must first "unhide" the shaders.

Why "hidden"

Simple matter of resources of Quality Assurance at Autodesk. The shaders has not gone through enough torture - yet - to be signed off by QA as "officially supported". But that's where you, my adventurous mental ray addict, come in! Consider this an extremely public beta, if you will....

How do I "unhide" them?

Unhide instructions for 3ds Max 2008 are here

Unhide instructions for Maya 2008 are here

What are they

The production shader library is a set of tools, some simple, some complex, to aid in doing production rendering, i.e. in a visual effects context.

There are two basic categories of shaders:

First we have the simple utilities like applying a gamma to a color, or giving different results for different "ray types" (reflection rays, transparency rays etc.). These shaders are very simple, and you probably have found similar shaders online before. These shaders are not better than those other shaders that do the same thing, they are simply a standard set that now ship with all products. I.e. "mip_rayswitch" isn't terribly different to Control Studio's "ctrl_rays", but you don't have to install anything to use it.

Then we have the more complex shaders, such as the 2.5d motion blur shader, or the matte/shadow/reflection system used to cast shadows (and reflections) off of a stand-in object in your scene, for integrating CG objects into a background plate.

A lot of examples of the mip_matteshadow and other production shaders are available as a small demo movie constructed for siggraph, it's available as YouTube as well as WMV, QuickTime and DivX versions.

What do they do?

The main intent is to simplify the workflow of compositing CG objects into background plates, and other visual-effects related tasks that one may run in to on a daily basis.

In some cases they exist to give a simple workflow to a simple thing. For example, the mip_cameramap is a simple camera mapping shader that simply projects back an image from the render camera (and only that camera) "into" the scene 3-dimensionally (unlike, say, mib_lookup_background, Max's "Screen" mapping, or similar).

There are more complex "camera projection" shaders out there both for Maya and Max that can do similar jobs, but at a slightly higher effort. Again, the logic here is to provide the simple tool that can do the job, and if you need the more advanced feature, use the more advanced feature.

Similarily, the mip_mirrorball shader is for a simple unwrap of a mirror ball into an environment map when taken from the same camera angle as the background plate. For anything more advanced you would probably have to unwrap the mirror ball image in some unwrapping software and apply as a spherical map... or maybe you are a high-end user that uses SpherOn cameras and don't even use mirror balls... then ignore this shader, use your more powerful tools.

Mark my words, I will be posting quite a lot on the topic in the months to come, but meanwhile you can read the PDF documentation. In Max, the names of the shaders will appear slightly different than in the manual, but you can figure that our rather quickly, I hope.

That's all I have time for for for now:

Stay tuned to future blog posts on the subject.



Max 2008: Physical Camera with DOF and motion blur

So, does anyone want a Physical Camera for mental ray in 3ds Max 2008? Read on...

The Photographic Exposure Control (mia_exposure_photographic) gives you values in f-stops and shutter speeds like in a real camera. However, it only applies to the exposure of the image (i.e. the brightness, basically).

In a real camera, the above mentioned parameters affect the depth of field and the motion blur of the camera.

This isn't supported out-of-the-box - the exposure control really only deals with the exposure.

A second thing is that the exposure knobs being "camera oriented", but they are not ON the actual Camera object. Whereas it would make more sense if these parameters "lived" in the UI of the Camera.

To try to solve these issues, I wrote a little "proof of concept" script to test out what such a UI would perhaps look like. It's very clumsy in many ways and an ugly hack, because it's just a "scriptable plugin", and scriptable plugins has a ton of limitations in max.

First of all, a scriptable plugin can only extend an existing object, not make a "new" one. Secondly, scriptable camera can only extend the "free" camera due to technical limitations of MaxScript (well, the MaxScript docs tell me so anyway), but most people "want" to use a "Target" camera.

Due to this limitation, the camera always gets created in "Free" mode, but after it has been created, you can switch it to "Target" mode. Ugly, but... livable.

How to use this plugin hack

1. Download this plugin and save into the "plugins" directory under your 3ds Max main directory.

2. Now, either restart max, or just load the plugin manually as well from the MaxScript menu.

3. Now, under your "cameras" you have a new "mr Camera" item.

4. Insert it - unfortunately always comes in as a "Free Camera". The UI at this point will look like the old camera.

5. Go to the "Modify" tab to see the "new" UI.

6. Play, rejoice, etc.

Remember, this is an ugly unsupported quick hack. The "mr Camera" simply "feeds" other existing plugins with value (mr Photographic Exposure, mental ray Depth of Field, motion blur, etc.) and doesn't really "do" anything by itself.

And it probably has more bugs than you can shake a stick at... but is provided here "for fun".




"What he said"

I love when people save me time. One guy who saves me time sometimes is Jeff Patton. He has another mental ray Blog an sometimes he reads my mind, and magically write things that I intend to post, saving me the time to actually post it.

Just now, for example, Jeff posted a tip on how you can use the portal lights as light cards. Quite useful, and quite an intended "additional feature" of the portal lights, albeit perhaps a tad under-documented....

Another cool mental ray Blog (more slanted towards Maya) is DJX blog with a lot of cool tips.

I'll add these blogs to my link list on the right, methinks....


3ds Max 2008 released: Some Known Issues

Or "Why do my brand new 3ds Max 2008 render black when I choose a mental ray render preset"?

3ds Max 2008 has been released, and as always, some things sneak in the wasn't really intended in the final version.

Here, a "minor edit" to the rendering presets became less minor than was intended;

Since 3ds Max 2008 contains the new mr Photographic Exposure control, the rendering presets (y'know, the ones down at the bottom of the render dialog) for daylight was supposed to be changed from the old Log exposure to the new Photographic exposure set for "sunny day" lighting.

The problem? That this was done.... but by accident all mental ray render presets got this setting.

Yes, even the "plain old" settings got, by mistake, a setting suitable for a superbright sunny day enabled:

The setting accidentally put in

But a sunny day can easily be lit by 100000 lux. And your average interior surely is not. So out of the box, starting up max and putting in some photometric lights (try to use the photometric lights as often as possible, btw) you would get a really dark scene.

And even worse, putting in some non-photometric scene would yield a pretty much completely BLACK scene. Why?

Well, the new mr Photographic Exposure Control has a 2nd feature; The feature of treating any "oldschool" value as real, physical cd/m^2 values (if you wonder about what a "candela per square meter" is, go back to the "Gnomes and Basketballs" post).

The Units Setting

This means that if an "oldschool" light of the arbitrary intensity value "1.0" shines perpendicular to a white (100% reflective) lambertian surface (i.e. plain old white diffuse thingamabob), this will emit light that is interpreted as 1 cd/m^2.

Now that is really really really really REALLY really dark.

I.e. turning on max, loading a mental ray render preset, and putting in and oldschool "Omni" light gives you a black render. Not good.

The fix? Easy.

Do one of three things:


1: Turn it off altogether

Hit "8" to bring up the "Environment/Effects" dialog and do as follows:

Exposure Control Turned Off

By simply turning off the exposure control, you are back to a "known" behavior. However the exposure control is really neat and gives very nice images... so I don't really recommend that method!

2: Use the exposure controls "non physical" mode

Exposure Control in "Non Physical" mode

This is better; it still gives you all the nice image control of crushing blacks, taming highlights, camera vignetting and saturation controls, but it uses a fixed unity gain, i.e. the intensity of the pixels does not change (except it applies a gamma correction if the 3ds Max gamma is disabled, if the 3ds Max gamma is enabled, that gamma is used).

However, it is not perfect just because of the fact that you lack any control over exposure; the "non physical mode" is locked to unity gain with no control over it.

There is, however, a third variant:

3: Use the exposure control with an EV=0.0

Exposure Control with an EV of 0.0

It so happens that when using the "oldschool pixels equal cd/m^2 mode" (pictured above) the EV value of zero (0.0) is very close to the "unity gain" mode set by the "Non Physical" mode. But you can change it up or down to re-expose the scene.

So for a scene lit completely with "oldschool" lights (non photometric), that is the easiest setting with the greatest control.

A further note on the units / physical scale

Now if you have an old scene with a blend of photometric and non-photometric lights, you may want to revert to the old behavior of using the "physical scale" setting, which exists in the old Logarithmic exposure control.

Using a "Physical Scale" like in the past

In this mode you cannot use the "EV=0" setting, you probably need to pick one of the "indoor" presets, or just play with the EV until you get a "nice" image, because this means that now an oldschool light of intensity "1.0" will equate to an illuminance of ~1500 lux when perpendicular to a surface, so an exposure "suitable" for that amount of light must be used.

Hope this helps!



Yer in a "Heap" of trouble now: Avoiding random crashes in Maya/Max due to running out of Windows resources!

Note; This tip has nothing to do with mental ray at all, but since the issue I describe tend to manifest on Maya when opening the mental ray control panel (due to the sheer number of tiny windows w. subwindows) I mention it here.

Have you ever run, for example, Maya (on Windows XP or earlier - Vista works better here) with a ton of other programs running, and tried to open a particularily complex AE template for some shader, to find the application go "plop" and disappear?

While there are any number of probable causes, I was debugging a particular case and actually found the cause, and it was sometihng I never really suspected, and is pretty non-obvious. And doesn't have anything whatsoever to do with mental ray, as I said above.

So what's up?

Back in the day of 16 bit Windows 3.0, running out of "window handles" (each window on screen has a "handle", like an identifier, used by the operating system to keep track of it) was extremely common, and every Windows user recognized the symptoms... windows wouldn't open, or buttons/texts would be missing from dialogs, or windows opened as only borders, or a strange "placeholder text version" of dialogs popped up.... whatever.

You'd think that a "modern" operating system wouldn't have a limit on the number of windows it could have opened, right? With multipled gigabytes of RAM, this shouldn't be an issue... right?

Well... think again. ;)

First of all the number of possible handles is apparently - still - limited to a 16 bit number (that's 65536 possible handles). But the real limit doesn't lie there, coz that's plenty. The real limit lies in the fact that each "window handle" also implies a memory allocation of a special data structure, that lives in a special memory area called the "desktop heap". And this memory area is small. As a matter of fact, by default, on XP (32 AND 64 bits) ... it's 3 megabytes!!!! Thankfully, on Vista it's larger, so Vista users do not need to do anything (except cry over all the other issues with Vista.... but that's for another blog day...)

Practically, this means that at around a few thousand windows (or other handles), things start failing.

Now, the user interface in Max, Maya and XSI are "windowed" UI's. This means that each control in each dialog is considered a "window" (from the point of view of the operating system). And sub-dialogs, little rollouts, etc. are all subwindows, with controls sub-sub-windows, and buttons can be sub-sub-sub-sub-windows, etc.

Anyone who has seen a compelex Max dialog box or Maya UI, and consider that counting every single little box, control, and thing, you'll find that that's a lot of windows. Maya easily consumes a couple of thousand handles all on it's own. (You can see this by telling your task managers "processes" tab to display the "GDI OBJECTS" column)

(Incidentally, this issue is known by Microsoft, to the extent that they try to write their software "windowless", i.e. when you run, say, Internet Exploder, each little thing on the webpage is not a separate window from the OS's point of view, precicely because of this problem!)

All is lost! The Sky Is Falling! Or?

Not at all.

See, the cool thing is that you can set up the size of the "desktop heap" by fiddling with the registry.

However, there are two things to consider when doing this, one fairly benign, and one less so.

The benign issue is that the "desktop heap" actually comes out of a larger memory area called the "Session View" (don't you just love these names?). And the size of the "Session View" is also limited (to 48Mb by default). Which is again adjustable, but that in turn lives in Kernel address space, which also is limited... to another, larger, value. And so on. You get the idea.

So the point is, you can increase the "desktop heap" size by editing the registry, but you can't just do it willy nilly and put in any old value, because you will get other problems, of running out of "Session View" space.

What I did was to up it from 3Mb to 4Mb, and the problems I had pretty much went away immediately.

The second, less benign issue, is that this is a really hairy registry location, and a horribly convoluted registry key, which actually contains a long string of some 200 characters where you have to change one thing in the middle, and the problem is the fact that doint it wrong can turn your PC into a brick.

Let me repeat that: Doing the registry edit INCORRECTLY CAN TURN YOUR PC INTO A BRICK. A DOORSTOP. A BOAT ANCHOR. MKAY!!??

So proceed with caution!

So what do I do?

Well, first of all, be aware of the above. I will take no responsibility for you turning your machine to scrap metal by a clumsy registry edit. Really. Proceed at your own risk, your own peril, and totally on your own responsibility. If you work at a studio, and the machine is not your own, talk to the TD or machine responsible person, point him to this webpage, and let him do it.


Made that clear?

If things blow up, do not come crying to me. I warned you. Ok? Good.

The registry key in question is (and if you don't know how to edit the registry, you probably shouldn't be trying this...):

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\SubSystems\Windows

The default value of this key is something like this

%SystemRoot%\system32\csrss.exe ObjectDirectory=\Windows
SharedSection=1024,3072,512 Windows=On SubSystemType=Windows
ServerDll=basesrv,1 ServerDll=winsrv:UserServerDllInitialization,3
ServerDll=winsrv:ConServerDllInitialization,2 ProfileControl=Off

...except it's all in one gargantuan long line, requiring you to scroll horizontally. See that "SharedSection" thing in there? After it it says "1024,3072,512"? Well, the 3072 in the middle, that's the "3 megabytes" we are talking about. 4 megabytes is 4 * 1024, i.e. 4096. So what we want to do is change "3072" to "4096".

Having done that, and rebooted, you should be gold.

More information about the desktop heap can be found here, or using, well, Google.



Maya: No Alpha channel on mia_material(_x)?

This must rank as the "most frequently asked question ever". (And consequently, the worst use of Google ever, apparently, since CGTalk alone has more threads on the topic than you can shake a stick at).

The problem: You render stuff in Maya, using mia_material(_x) - or any other "mental ray" shader - but you find that those pixels containing that shader has no alpha. What gives?

The reality is that Maya has a very peculiar notion of Alpha... because the Maya software renderer actually has true three-colored "transparency", so transparency gets passed around separately in the most... odd... ways ;)

Hence, to get the Maya system to "understand" a standard shader that uses alpha, you need to check this here little checkbox:

Then, life should be more fun again!



Hot Fuzz: Hair Revisited

In a previous post I briefly mentioned hair. People started to wonder about the details of that, so:

If you render hair w. Raytrace shadows and using the normal raytracer, it works.. but takes a while:

Whereas if one enables the Fast Rasterizer, and use Detail Shadow Maps, it can be both nicer looking and faster:

So the question then is... where do I turn this on?

I admit some things can be hard to find, and sometimes they are renamed in the UI of a particular application... for example, the mental ray detail shadow maps are actually not named "detail shadow maps" in 3DS max, they are named "Transparent Shadows". You find them here:

In Maya, however, they have their proper name and are found here:

However, Maya has "special" shadow settings for Hair and Fur one may need to watch out for.

Turning on the "Fast Rasterizer" is easier since it has it's proper name in most applications. Max:

And Maya:

Hope this helps with the "Fuzzy sidekick" rendering. Note that the Rasterizer is great for motion blur and fuzzy stuff, but can be suboptimal when involving many raytraced effects (glossy reflections, etc.)



Maya's default shadow settings


No too long ago I wrote about Maya and shadows.

There is another "issue" related to Maya and shadows; the default shadow trace depth on Maya is 1 (called "Ray Depth Limit" in the lights "Raytrace Shadows" panel). This means that even after one bounce (like a reflection in a mirror, or behind a pane of glass) you suddenly do not have shadows any more! This can hugely impact any quality interior GI render, and you can get all sorts of issues caused by this.

NOTE: A common misconception is that the Maya "Ray Depth Limit" on the ray traced shadows is how many surfaces the shadow rays penetrate. This is not so!.

This image is rendered with the "Ray Depth Limit" of 1:

Notice how the light still gladly penetrates 3 blue glass blocks (6 surfaces in total) and still generates a shadow? Yet when viewed through the single red glass block, the view as seen trough it suddenly is completely shadow-less!

Whereas if we turn up the "Ray Depth Limit" to 3, and the "Shadows" depth to 3 in the mental ray render globals (yes, you must change both!) you get:

Another demonstration of this can be found here

So, in conclusion

Make sure to take a look at Maya's shadow settings, making sure to look at

- shadow trace depth (note this must be set on the light (defaults to 1) as well as in the mental ray render globals (defaults to 2))

- "Low" area light samples (defaults to 2x2) and the "High Sample Limit". However the "High Sample Limit" defaults to 0, which turns OFF the "low area light sampling" mode. This is "good" quality wise (you never actually get the "low area sampling") it precludes a particular mia_material(_x) optimization (it tries to control this from the material, driven by importance, but it cannot do so if it is set to 0). I suggest you turn it up to 4. You can generally keep your "low" sampling at 2x2 when you are using the mia_material, but when using other materials, this may be something to watch out for, since they will strictly adhere to the "depth" setting rather than the relative ray importance, like mia_material(_x) does it.