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.