mia_physicalsky and haze

david | mentalray,rendering,tutorials | Monday, October 29th, 2007

A while ago I learned from one of "Zaps Mentalray Tips" that the mia_physicalsky haze parameter could be used to make clouds in the sky by connecting a file texture to it. Since then I have experimented with this technique and discovered some limitations and some solutions to those limitations.

sky_hazeWithVisDist_mentalrayTexture.jpg

(more...)

append existing lens shader

david | dj mod,mel script,mentalray,rendering | Wednesday, October 24th, 2007

Here's another modification to a maya 2008 mel script that enables you to easily hook up more than one lens shader to the camera.

For example, if you have set up the standard Physical Sun and Sky environment then you will already have a lens shader in place (mia_exposure_simple or mia_photographic perhaps). Now if you also want mia_lens_bokeh to do some depth of field then you will need to use the secondary lens shader list where you can "Create" a new lens shader.

But what if you want to use an existing lens shader rather than creating a new one?

This modification allows you to do just that.

For example you may wish to connect the mia_physicalsky node as a lens shader to take advantage of the "visibility distance" parameter. In this case you would definately want to use the existing mia_physicalsky.

The modified file is AEconnectionTableTemplate.mel and you should place it in your local scripts folder and restart maya. (Never put customized mel scripts into the maya installation folders). Now if you look at the camera's attribute editor you will see this

cameraShapeAE.jpg

You must first select a lens shader, then shift-select the cameraShape node, open the attribute editor and click "Append" to make the connection.

Download here

faster renders

david | rendering,tutorials | Wednesday, October 17th, 2007

Depending on how you currently start your maya renders, this tip may save you some render time.

If you launch renders using the command-line (either directly or via a render manager application) then you will already know about the various cmd-line flags that can be used to control various aspects of the render.

For a while now I have been using the command "render -r file" to tell the render to use which ever renderer (usually mentalray or software) I have specified inside the scene file. This is especially convenient when, because of render layers, I'm using both these renderers in the one scene.

Today I made an interesting discovery. If I instead use "render -r mr" to tell the renderer specifically to use mentalray then my render times decreased significantly, in this case, dropping from just over 5 mins per frame to approximately 3 mins per frame.

I know these differences will probably vary depending on the content of the scenes. And I know that being specific about the renderer will require some extra thought when different render layers may use different renderers, but the time saving is sure to make it worth the effort.

choose exposure

david | dj mod,mel script,mentalray,rendering | Tuesday, October 16th, 2007

In maya 2008, when you create a Physical Sun and Sky environment from the Render Settings window several shaders are added to your scene. One of these is the mia_exposure_simple shader which is a simple tone mapping shader that is connected to the camera as a lens shader. However one of the new features of maya 2008 is the addition of a more powerful tone mapping shader called mia_photographic. To make it a bit easier to get started with this new lens shader I modified one of maya's mel scripts and added a user interface for choosing which of the two exposure methods is used.

chooseExposureUI.jpg

This UI saves you having to make the lens shader connections manually.

To install it you need to download a modified version of createMentalRayGlobalsTab.mel (2008) or createMentalRayIndirectLightingTab.mel (2009) and place it in your local scripts folder, and restart maya. (No userSetup.mel edits for this one). If you decide you don't like it, just delete the local modified copy.

Download here.

update 19 March 2008: rar file now also contains a version for maya 2008 sp1

update 6 Feburary 2009: Modified createMentalRayIndirectLightingTab.mel for maya 2009. This should be used instead of the modified createMentalRayGlobalsTab.mel.

update 7 July 2010: Added maya 2011 version of createMentalRayIndirectLightingTab.mel

mrCreateCustomNode.mel

david | dj mod,mel script,mentalray,rendering | Sunday, October 14th, 2007

I read a post on Master Zap's blog where he wrote about a problem with mia_material shadows. You can read the full article here. He says "there is a performance issue with the "segment" shadow mode and the mia_material shadow shader" and "The workaround is very simple; don't use the shadow shader for opaque objects".

However when you create a mia_material in maya 2008 it is automatically added as a shadow shader and a photon shader. Rather than having to remember to break the shadow shader connection for each new material, I decided to insert a UI that would allow me to choose what connections to make.

The UI, which pops up when you create a new mia_material, looks like this

djExtraSGConnectionsUI.jpg

The mel script overrides the default maya 2008 behaviour. Just put it in your local scripts folder. Then add the following line to you userSetup.mel

source mrCreateCustomNode.mel;

and restart maya. If you dont like it, just delete it and everything will go back to how it was before.

Download mrCreateCustomNode.rar

UPDATE - 4 Dec 2007

After using this little add-on for a while I got sick of having to click OK every time I created a new mia_material_x. It was so rare that I would change my connection options that I decided it would be better to bypass the prompt and hard-code the connection defaults - which for me is shadow=NO and photon=YES. So I removed mrCreateCustomNode.mel from my local scripts folder and replaced it with a copy of mentalrayCustomNodeClass.mel (D:\Program Files\Autodesk\Maya2008\scripts\others) which I edited to change the defaults.

Near the start of mentalrayCustomNodeClass.mel is a section that relates to mia_material_x and I simply removed the following

connection/mentalray/shadow:

Now if I ever need the shadow connection (for transparant shaders for example) I hook it up manually by dragging-and-dropping onto the shadingGroup node in the hypershade window.

mia_physicalsky visibility distance

david | mentalray,rendering,tutorials | Wednesday, October 10th, 2007

This is a mini tutorial on using the visibility distance parameter of the mia_physicalsky shader.

Most people probably add mia_physicalsky to their scenes using the create button in the environment tab at the bottom of the mentalray render-settings (shown here)

renderSettings.jpg

This creates a shader network involving several nodes. If we look at the camera attribute editor mentalray tab we see that mia_physicalsky has been connected to the environment shader slot and mia_exposure_simple to the lens shader slot.cameraAttrEdA.jpg

The default settings are a good start point for lighting out door scenes. Here is a render of a 9 objects in a line using the default sun and sky settings - except for the mia_physicalsky visibility distance, which I changed from 0 to 10.

default sun sky render

So what is visibility distance and why am I writing about it?

The manual says "Aerial Perspective is a term used by painters to convey how distant objects are perceived as hazier and tinted towards the blue end of the spectrum. mia_physicalsky emulates this with the visibility_distance parameter." This can be a little confusing for two reasons: 1. there is also a "haze" attribute and 2. it doesnt seem to matter what value you give to visibility distance - nothing changes.

Making visibility distance work is easy once you know how. You need to connect mia_physicalsky as a lens shader. Our camera already has a mia_exposure_simple as a lens shader, but we can add another one. You might expect that you could drag-and-drop the existing mia_physicalsky shader into the empty lens shaders box, but for some reason that doesnt work. Luckily its easy to do with a simple mel command.

connectAttr mia_physicalsky1.message cameraShape.miLensShaderList[0];

(You may need to change the cameraShape name to match your camera.) Then the camera attribute editor should look like this

cameraAttrEdB.jpg

Update: You can also install a modified mel script to make the connection using a button in the attribute editor. Read about it here.

If we rerender the test scene we get this

withLensShader_visDist10_haze0.jpg

These are the same settings as the first render except now mia_physicalsky is being used as a lens shader as well as an environment shader. Here are some different visibility distance settings

withLensShader_visDist40_haze0.jpg

withLensShader_visDist100_haze0.jpg

So what is the difference between visibility distance and haze? Haze sets the amount of haze in the air and changes the look of the sky but on its own does not obscure the view of the objects. Here is a render with haze but zero visibility distance

withLensShader_visDist0_haze10.jpg

Here is the same haze value but visibility distance set to 100

withLensShader_visDist100_haze10.jpg

And here is another variation

withLensShader_visDist100_haze3.jpg

Summary: visibility distance only works if the mia_physicalsky is used as a lens shader.

self reflection plus alpha

david | mentalray,rendering,tutorials | Tuesday, October 2nd, 2007

You should read the previous post called "self reflection" before this one.

If you had tried my suggestions you may have discovered that the reflection pass had no alpha channel. Normally you would "add" or "screen" a reflection when compositing, so you could manage without an alpha channel, but I thought I should do an update and show how to get one.

A small change to the shader network is required. This hypershade snapshot shows the new layout.hyperShadeC.jpg

The difference is that now the mip_rayswitch connects to the surfaceShader instead of to the shadingGroup. And so the shadingGroup attributes look like this.

shadingGroupC_attr.jpg

Notice that the mentalray "Custom Shaders|Material Shader" slot is now free and I have turned off the "Suppress all Maya Shaders" flag. You may get some wierd looking shader ball swatch in the hypergraph when you do this, but you can safely ignore that.

Now when you render, the reflections should look the same as before, but the alpha channel will look like this.

alpha.jpg

One more thing. In my examples I am using mia_physicalsky as an environment shader. I should have mentioned that to get the black background in the reflection pass I turned on the "Use Background" flag in the mia_physicalsky attributes, and then left the "Background" slot empty. This way it is still used as a reflection environment, but not for the visible background.

Here is an updated maya scene file with the changes.

self reflection

david | mentalray,rendering,tutorials | Monday, October 1st, 2007

Sometimes it is desireable to render in layers or passes that will be combined in post production. This give the compositor more control especially when integrating CG with live action. You may choose to render passes like diffuse, shadow, occlusion, specular, reflection, depth - the list goes on and the choices depend on many factors.

What I want to demonstrate here is a way to tackle a reflection pass using some of the new maya 2008 shaders. Actually I am going to use a new "unsupported" shader - so... you have been warned.

First, a render of some reflective surfaces.

beauty.jpg

One way to get a "reflection pass" is to make the diffuse components of all the shaders black. That way we are left with just the reflections. Here is the result if I do that.refl_result_noSelf.jpg

The problem is that the sphere is reflected in the cylinder and the ground, but it's reflection is black. What we really want is colored reflections and to do that we need the new mip_rayswitch shader.

mip_rayswitch was included in maya 2008 as an "unsupported" shader, which means it was hidden away. To expose it you need to edit a mel script called mentalrayCustomNodeClass.mel (C:\Program Files\Autodesk\Maya2008\scripts\others). Right at the end of the file is this line

return "rendernode/mentalray/internal";

and you need to change it to this

return "rendernode/mentalray/material";

When you restart maya, mip_rayswitch will be one of several new materials in the mental ray section (sadly lacking icons).

The job of mip_rayswitch is to help the renderer decide what content particular types of rays will contain. There are several ray types, but we will look at the "eye" ray and the "reflection"ray. The "eye" ray is what we see through the camera. The "reflection" ray is... I bet you can guess. So we want the fully colored shader to be seen by the reflection ray and just the reflections to be seen by the camera (the eye ray). And to get that we need the connection editor and the new mia_material_x shader.

mia_material_x is a more advanced maya2008 version of the maya8.5 mia_material. One of its new features is "multiple outputs" - meaning it has the ability to output a long list of components independantly. Here we are interested in only two of these called "result" and "refl_result".

mia_material_x.result is the "beauty" pass. Its what you usually see when you render it. On the other hand, mia_material_x.refl_result is just the reflection component of the shader. What we are going to do is create a shader network where the mia_material_x.result is used for the reflection ray in mia_rayswitch and mia_material_x.refl_result is used for the eye ray. This needs to be done for each shader.

Here is a picture of the shading network with the important connections highlighted.

hyperShade

The mip_rayswitch is hooked up to the shadingGroup's mentalray material

shadingGroup_attr.jpg

Now if we rerender that reflection pass we get this

refl_result_withSelf.jpg

Now we have colored reflections, but only the reflections.

Here is my maya scene file if you want to have a look.

Powered by WordPress | Based on a theme by Roy Tanck