Monday, April 30, 2012

MEL: How to apply commands to all the objects selected.

Here's how to apply a command or commands to each and every objects that are being selected.

string $selected[] = `ls -sl`;
     for ($member in $selected)
     {
          commands...
     }

The first line is to list all the selected objects, and put the list into a string array variable called $selected. The second line is a for-loop which will execute the commands for all the selected objects.

Notice that $member variable is for-loop internal variable which doesn't need to be declared.
It is only used inside of the for-loop.

For example, you can rename all the selected objects at one shot.

string $selected[] = `ls -sl`;
     for ($member in $selected)
     {
          rename $member "myObject#";
     }

If you execute this script, your selected objects will become myObject1, myObject2, myObejct3....


Here's another example.
You can add a new attribute to all the objects you select.
Let's add miLabel attribute.

string $selected[] = `ls -sl`;
     for ($member in $selected)
     {
          addAttr -ln miLabel -at long -min 0 -max 10 -dv 1 $member;
          setAttr -e keyable true ($member +".miLabel");
     }

This script is to add "miLabel" attribute to all the selected objects, and set its initial value to 1.

This is one of the most frequently used mel scripts. It can be used in many different ways.

Sunday, April 29, 2012

The cartoon style render of Iron Giant.


I tried the look of Iron Giant, the masterpiece, using the Mental ray's contour rendering feature.



 Here are the reference images from the movie.






The characteristics of the look in rendering the robot is the cartoonish shading and the ink line rendering.
You can easily achieve these effects.  
I use the Ramp shader for the two tone cartoonish shading and the contour rendering feature for the ink line.


 
I adjusted the color attribute so that I get two tone shading on the surface. Normalized Brightness is used for Color Input. I also turned off the specularity completely for a diffusive look.
Then I turn on Enable Contour Rendering option and set the color and the line width in the ramp shader's shading group node.

 I duplicated this shader a couple of times and tweaked the colors a bit and used them for other parts of the body.
If I render now I get the following look. I used one directional light with the raytraced shadow on.


Next, I move on to the contour rendering feature.


 
With the Between different instances option on only, the render looks like below.


I get lines around the silhouette and between objects.  Now I need lines inside of objects where there are hard edges. For this, I turned on Enable Normal Contrast and set the value to 7.0.
This will reveal more details.


The render result.


 Finished!




The look of 300, the movie.


Here are the reference images from the movie.















These images are exhibiting  the typical look of the movie.

The followings are the characteristics that can be found in the reference images.

  • Desaturated / bleached
  • only a few colors are noticeable : Red, turquoise, goldish yellow
  • high contrast
  • Heavy grains ( in the midtone only )
  • glowing sky

These can easily be achieved by color grading and a few basic filters


I used the following render image and basically used Magic Bullet Looks and Mojo to replicate the 300 look.




Fist, I started out with adding glow effect mainly to the background stormy sky. 



 
Then I used Magic Bullet Looks to add a series of effects and color correction.
I set the overall brightness and tone and applied the film grain, a bit of a vignette and chromatic aberration.





Finally, Magic Bullet Mojo is added to colorize. This is the main tool used to mimic the tonality of 300.
Mojo can create a bleached and contrasty  tone and also warm the bright area and cool the dark area.



original vs final



Here's the comparison.


The color grading and the post effects can make a dramatic change in look.

Color Management for Linear workflow in Maya


For the linear workflow in Maya, you inverse-gamma correct all the 8 bit (sRGB) file texture by attaching the gamma correct node with the gamma value of 0.455.
However, if you use Color Management feature in Render Settings, you can skip that gamma node attaching hassle.



 Turn on Enable Color Management option and set Default Input Profile to sRGB.

Now, create a file node and open attribute editor.




The file node has the Color profile attribute and it's set to Use Default Input Profile by default.
What this means is all the file nodes are treated as sRGB image and invers-gamma corrected internally by default.
Threfore, there's no need to attach a gamma correction node.
If you are reading a linear image ( HDR image, for example ), just simply set this attribute to Linear sRGB in the file node.Then, no gamma correction will be applied for that particular file node.
Simple as that. This can help  avoiding a cluttered shader connection and a potential Render Pass Mode artifact.

However, you still have to use gamma correction node for procedural textures and color pickers until Autodesk comes up with a better solution.

Saturday, April 28, 2012

Post motion blur effect comparison


I have results from 3 different post motion blur effects.



1. Furnace motionBlur in Nuke with no motion vector.
2. Reel Smart Motion Blur using la maison 2d motion vector shader.
3. Nuke's built-in vector Blur effect using Maya's 2d motion vector render pass (normalized one).

Here's the comparison in color channels. 



 Apparently, they all look very similar and showing a reasonable quality.
But in alpha channel, there are some differences.



The first one, Furnace motionBlur shows some artifacts. For example, you can find some smudging around the ball especially when the ball is being released from the hand.

This not-so-clean alpha is not desirable for compositing. Since the Furnace motionBlur was not helped by any motion vector source, this kind of artifact should be unavoidable.

The other two effects are done with a proper motion vector source provided and did generate a relatively clean and smooth alpha.

RSMB still produced a better alpha than Nuke's vectorBlur.
While the ball is exiting the frame, the edge of the ball looks better in RSMB's case ( the center )than Nuke's vectorBlur ( the right ).

Overall, the winner is... Reel Smart Motion Blur (imho).

Symmetry can help uv lay-out


Symmetry can help uv laying out
When you work on a character that is symmetrical, halfway done is almost done.
You can just work on one half and mirror that to the other side.

Here's a character's head and its uv.




I select the uvs on the right side only and apply unfold and relax to smooth out the uvs a little bit.



How to save a final gather map file for each frame


When you use the final gathering for animation, you'd probably have to refresh final gather map and rebuild it from scratch at every frame unless it's a camera fly-thru only animation.
In that case, you'd have to use very high settings for the final gathering and each frame would take a good amount of rendering time. What if you have re-render the entire sequence for some reason.
All the final gather maps that you previously calculated has been over-written and only the final gather map for the last frame remains. What a waste.
So, I'll show you a simple way to save all the final gather maps that are created during the rendering.

 
You can access and control the final gather map's name by the attribute called
"miDefaultOptions.finalGatherFilename"

You can simply set this attribute to a file name of your choice using setAttr command like below.
The filename goes between the parenthesis. 


setAttr -type "string" miDefaultOptions.finalGatherFilename ("FGmap_save."+`currentTime -q`+".fgmap");

Here, my scene file name is" FGmap_save.mb", so I typed "FGmap_save.".
You can use your scene file name or any name.
Each fgmap name will be unique by quoting the current frame number using `currentTime -q` command and appending that to the file name.


This one-line script goes to Pre render frame MEL slot under Render Options  in Common tab.


This mel script will be executed before every render begins at each frame.
Now you can find that for every test render,  the Primary Final Gather File name updates for the current frame.

Now render your sequence with FG rebuild option ON and your FGmaps will be saved for each and every frame. 

When you need to re-render any frames or the entire sequence, just switch the Rebuild option to Freeze and render again. The renderer will locate the corresponding saved FGmap for each frame.




This can be a big time saver especially when you find that you need to adjust the Point Interpolation attribute only after the sequence is once rendered.



Wednesday, April 25, 2012

One weird normal map error.


I found this weird error when I was using a normal map in Maya.
If you attach more than one bump2d node to a single file node and use these bump2d nodes as a normal map, whether set to Tangent Space Normals or Object Space Normals, this will cause a problem.
The object's color doesn't show up and the surface normals get messed up.


 
Here I have a simple shader connection.  A blinn shader with one normal map input.
The render looks like this.


I  create a new shader and used the same file node as a normal map through a new bump2d node and assign this new shader to the right plane.



Tuesday, April 24, 2012

Optimizing the portal light.

Traditionally, to simulate the illumination that comes through the window, area lights are placed in the window. This method is enhanced by using portal light which obtains its intensity and color from the environment outside the window.
The portal light helps in a great deal reducing Final Gathering's noise and since it's a light source it can cast shadow.


 
 Here's a scene with a room. I have set up an area lights for each window and a portal light is connected to each light.



 This is the spherical environment texture used for IBL as a primary environment for Mental ray in HDR format. It's a very high resolution texture. ( 6250x3125)
Using the default setting, this is the initial render result.



indirect illumination for skin shading








In this post, I will talk about applying indirect illumination to the skin shader  using ambient light and AO
Mental ray's  misss_fast_maya_skin shader is a  one of the better skin solutions.
Like its name implies, it's fast and quite easy to accomplish a quick skin look.
But if you look for more realistic results, you need to provide with indirect illumination to the skin.
First of all, you need to approach the skin shader from two different directions. direct and indirect illumination.
Most of the skin tutorials generally deal with direct illumination part only.
Sometimes direct illumination only can create a satisfactory result, especially for cartoonish look characters.
But a realistic human skin cannot go without considering the indirect illumination.
So, I'd like to show a method of doing this, not using expensive final gathering but ambient light and AO combo.
Here's a scene with a head model. A skin shader is alreay assigned to it.



I have set up two light sources. One from the front for epidermal and subdermal scatering and the other from the back for back scattering.

Area 1: This is where the direct illumination hits the sufrace.
Area 2: This is where you can see scattering.
Area 3: This is where no illumination or scattering is found.


Sunday, April 22, 2012

miLabel attribute to control ambient occlusion


Mental ray's ambient occlusion material doesn't respect transparency and this can create undesired occlusion for transparent materials like windows.
You can easily turn on and off AO for a certain object using miLabel attribute.
Let's look at the simple scene here.

  


 
All three objects in this scene are assigned with the same ambient occlusion material.
What if object#2 is a transparent object like window. If the window is transparent enough,  it should not cast that much occlusion on the floor.



Flexible shading on Maya Fur and Hair




Maya's native fur shading doesn't give you much flexibility.  So often times you want to use
another shader but Maya's default fur and hair shaders are hard-coded it
 doesn't let you assign a shader of your choice.
 I'll take a look into what to do to override the default material.
Here's a simple scene with two spheres.
The left one has fur assigned to it and the right one has hair.



 
Here's the render result that looks alright but with a better shader it will look better.