Showing posts with label Walkthrough. Show all posts
Showing posts with label Walkthrough. Show all posts

Thursday, September 17, 2015

Rendering Maya nHair Using Mental Ray

In the previous post, we saw how we can create an nHair system in Maya using FiberMesh in ZBrush. In this post, we will see how we can render the nHair system in Maya using Mental Ray and get as render like this.
nHair system rendered using Mental Ray.

Before we start, make sure that Mental Ray is loaded and that it is the active renderer. Here is my render at this point.
Figure 1. Render at the starting point.

1. Creating Physical Sun and Sky

We are going to light the scene using Mental Ray's Physical Sun and Sky system. (In 3ds Max, the equivalent is the Daylight System.) Creating physical sun and sky is easy:
  1. Open the "Render Settings" dialog.
  2. Go to "Indirect Lighting" tab (see Figure 2).
  3. Expand the "Environment" group.
  4. Click the "Create" button next to "Physical Sun and Sky".
Figure 2. Creating Physical Sun and Sky.
Here are what happened when we pressed the "Create" button:
  • Final Gather is automatically enabled (see Figure 3 left).
  • A directional light called "sunDirection" is created (see Figure 3 right).
Figure 3. Left: Final Gather is enabled. Right: a directional light is created.
There are more things happening behind the scene that we need to understand.
  • Let us start by selecting the "sunDirection" light.
    • The Attribute Editor shows the parameters of "sunShape" (see Figure 4 left).
    • Notice that "sunDirection" light is assigned a mia_physicalsun shader (see Figure 4 left). This is a Mental Ray light shader. It makes the directional light to behave physically correct during rendering.
  • Next, click the boxed arrow button on the right of "Light Shader" (see Figure 4 left).
    • The Attribute Editor now shows the mia_physicalsun parameters (see Figure 4 middle).
    • Notice that there are 5 parameters ("Multiplier", "Haze", "Red-Blue Shift", "Saturation", and "Horizon Height") highlighted in yellow. They are connected to the parameters of the physical sky shader (which we will inspect next). Remember that you can break any of these connections so that the sun shader uses a different parameter from the sky shader.
  • Click the "mia_physicalsky1" tab of the Attribute Editor (see Figure 4 right).
    • Notice that this shader uses the "sunDirection" light as its "Sun" parameter. This means you can create a light and assign it as the "Sun" of this sky shader.
    • Also, experiment setting the value of "Multiplier" to 2.0, then seeing the "mia_physicalsun2" tab. Confirm that "mia_physicalsun2" "Multiplier" value is also 2.0. The same connection applies to 4 other parameters as discussed above.
    • Make sure you set the "Multiplier" value back to 1.0 before proceeding.
Figure 4. More things happening behind the scenes. Middle: Mental Ray physical sun shader. Right: Mental Ray physical sky shader.
But that's not all. Select your render camera and see the Attribute Editor:
  • The physical sky shader, "mia_physicalsky1", is attached as "Environment Shader" (see Figure 5 left).
  • Another Mental Ray shader called "mia_exposure_simple1" is attached as "Lens Shader" (see Figure 5 left).



Figure 5. Mental Ray shaders attached to the camera. Left: the camera shape node. Right: the mia_exposure_simple shader.

We are particularly interested in the lens shader mia_exposure_simple:
  1. Click the boxed arrow icon on the right of "Lens Shader". The Attribute Editor will show the parameters for the mia_exposure_simple shader (see Figure 5 right).
  2. Notice that the "Gamma" value is 2.2.
  3. Render your scene.
    • My render looks like this.
Figure 6. Rendered image with Gamma value 2.2.
The rendered image looks deceptively alright, but it is actually overly bright because of incorrect gamma value.
  1. Set the "Gamma" value to 1.0.
  2. Render your scene again.
    • My render now looks like this.
Figure 7. Rendered image with Gamma value 1.0.

The shadow area looks more natural. However, the hair looks grainy and hard. We will now fix this.

2. Improving Sampling Quality

First, we will improve Mental Ray's sampling quality:
  1. Open "Render Settings" dialog.
  2. Go to "Quality" tab (see Figure 8).
  3. Expand "Sampling" section.
    • By default, the "Sampling Mode" is "Unified Sampling" and the "Quality" is set to 0.25 (see Figure 8 left).
  4. Set "Quality" value to 1.0.
  5. Render your scene.
    • The hair should look less grainy now, at the cost of longer render time.
Figure 8. Mental Ray Sampling parameters. Left: default settings. Right: my personal preference.
I personally find "Unified Sampling" mode make render time much longer than necessary; so I prefer to use "Legacy Sampling Mode" (see Figure 8 right). This mode gives me more control over the quality-render time trade-off. For example:
  • I set "Min Sample Level" to -1 & "Max Sample Level" to 1 for fast renders.
  • I set "Min Sample Level" to 2 & "Max Sample Level" to 3 for high quality renders.
I use the settings shown on Figure 8 right and here is my render.
Figure 9. Rendered image with improved sampling quality.
The hair still has grainy look to it, caused by hair shadow. We will fix this next.

3. Improving Hair Shadow

Select the light "sunDirection" and open the Attribute Editor:
  1. Expand the "Shadow" section (see Figure 10 left).
    • By default, the light uses ray traced shadows. The render scenes with hair, use depth map shadows instead.
  2. Check "Use Depth Map Shadows" (see Figure 10 right).
  3. Set the following parameters:
    • "Resolution": 4096;
    • "Use Mid Dist": unchecked;
    • "Filter Size": 4 (or higher; the higher, the more blurred the shadows are);
    • "Bias": 0.05.
Figure 10. Shadow settings.

Credit: I learned about hair shadow settings from the article "Set up hair self-shadowing" at Autodesk Knowledge Network. Read this article for more insight behind the values I set above.

Render your scene. My render looks like this.
Figure 11. Rendered image with improved hair shadows.
And that is it! You can now work on your lighting and get a nice hair render.

Thursday, August 27, 2015

Creating Maya nHair Using ZBrush FiberMesh

In this post, I will go through how you can export FiberMesh from ZBrush to Maya to render. I will focus on the procedural steps, not the artistic aspect.
Hair rendered in Maya using Mental Ray
To manage expectation, let me point out that the post only covers the creation of the nHair system. At the end of it, you do not get the render above yet. To get that render, you will need to go through this post as well as the rendering post.

 1. Creating FiberMesh Hair in ZBrush

There are tutorials out there that show you how you can create hair using FiberMesh. I recommend going through this video tutorial: "Fibermesh : Zbrush to Maya, Efficient Workflow Pt1 /// ZBRUSH" (it is 15 minute long).
In addition, I got excellent tips from Charlie Kim.
Figure 1. Brush menu.
  • Go to Brush menu; expand FiberMesh section (see Figure 1).
    • Set "Preserve Length" to 100.
      • This means whatever we do to the Fibers using the active brush, the Fibers will remain the same length.
      • I find this is the key setting that makes working with FiberMesh (relatively) easy.
    • The "Front Collision Tolerance" enables a collision detection between the Fibers and the head mesh. On the other hand, the collision detection causes the Fibers to look "jittery".
  • Further down Brush menu, expand Auto Masking section (see Figure 1).
    • "Mask By Polygroups" enables you to affect only the polygroup you start your stroke on. I turn this on and off depending on what I am doing.
    • "FiberMesh Mask Curve" determines how much your stroke affects the Fiber along the Fiber strand.
      • By default, the mask is maximum at the root. This is why it is impossible to move the root of Fibers. This is also why the tip moves the easiest.
      • Change the shape of the curve based on what you are working on.

Here is how my FiberMesh looks.
Figure 2. Left: screenshot of ZBrush viewport. Right: BPR render.

2. Exporting FiberMesh to Maya

  1. Go to Tool menu.
  2. Make sure you select the SubTool that contains your FiberMesh (see Figure 3).
  3. Scroll further down to FiberMesh section, "Export Curves."
  4. Click "Export Curves" button.
  5. Make sure you save as "Maya Ascii Format (*.ma)" (see Figure 4).
Figure 3. Tool menu.
Figure 4. "Export FiberMesh Curves" dialog.
Now we are ready to open the curves in Maya.

3. Creating Hair in Maya using nHair

Before importing the curves, let us create an nHair system first.
  1. Create a plane.
    • This plane is just a temporary dummy to create nHair system; we will delete it later.
  2. Make sure you select "nDynamics" menu set (see Figure 5).
  3. Click "nHair" > "Create Hair" (see Figure 5).
  4. Figure 5. Creating nHair system.
  5. Open Outliner.
  6. Figure 6. The Outliner after we created nHair.
    • Notice that Maya created 4 objects (see Figure 6): hairSystem1, hairSystem1Follicles, pfxHair1, and nucleus1.
    • hairSystem1 is where we set parameters to control the look of the hair a well as its dynamic behavior in simulations.
    • pfxHair1 is the paint effect that gets rendered.
    • nucleus1 is the Nucleus simulation solver.
    • In this method, we do not need hairSystem1Follicles.
  7. Delete hairSystem1Follicles.
Now we are ready to import the curves.
  1. Click "File" > "Import".
  2. Select the file with hair curves and click "Import".
Depending on the Fiber count you had in ZBrush, Maya viewport may slow down drastically. In this case, you may want to hide the curves.
Next, we will add the imported curves to the nHair system we created earlier.
  1. Select the curves.
  2. Click "nHair" > "Assign Hair System" > "hairSystemShape1" (see Figure 7).
    • Maya may take a while if your curve count is high.

Figure 7. Adding curves to nHair system.
If we open the Outliner, we can see that Maya created a new group hairSystem1OutputCurves. This is what the nHair system needs to generate hair. The generated hair is in pfxHair1.
Figure 8. The result of adding curves to nHair system.
Let us take a close look at the generated hair.
Figure 9. Left: Each curve (green lines) has multiple hairs (brown lines). Right: "Hairs Per Clump" parameter.
Each imported curve actually has multiple hairs (see Figure 9 left). This reason is the default setting of hair system. Here is how you can make sure there is 1 hair for each curve:
  1. Select the shape node of the hair system. In my case, it is called "hairSystemShape1".
  2. Open Attribute Editor.
  3. Expand "Clump and Hair Shape" section.
  4. Set "Hairs Per Clump" to 1.
    • By default, this value is 10 (see Figure 8 right). This is why each curve has multiple hairs and therefore overall the hair looks thicker.
This opens up a new possibility: we can set a low Fiber count in ZBrush. This way, we export fewer curves; which means importing and hair generation in Maya will be faster. Then, to compensate, we set "Hair Per Clump" parameter to a value greater than 1.

Back to our hair, here is how it looks in the viewport and Maya software render.
Figure 10. Left: viewport render; right: Maya software render.

And that is it! You can now render the hair using your favourite renderer. In the next post, I will cover how to render the hair system using Mental Ray (and how I got this render below).
Figure 11. The same hair system rendered using Mental Ray.

Thursday, January 1, 2015

Reflection on Batman Tumbler - Part 3: Checking Angles

This is the final part of a material walkthrough for Batman Tumbler model. I explained the problem in Part 1 as well as offered a partial solution. Part 2 followed up with map manipulations to improve the render.

At the end of Part 2, I got this render.
Figure 1. Render at the end of Part 2.

It looks pretty good: the metal parts have reflection and dirt details at the front part can be seen. Now it is time to check renders of other frames.

The roundtable animation has 120 frames. At this stage, I do not want to render every frame yet. Instead, I rendered every 30 frame to get four different angles of the Tumbler.
Figure 2. The rendered four angles

Looking at the 2 back angles, I found the back wheels looked too "painted" due to the Diffuse map. To reduce the painted feel, I composited Noise maps on top of the Diffuse bitmap. As figure 3 shows, I used 2 Noise maps to break the regular look of the Noise maps.
Figure 3. Composite map to reduce the painted feel of wheel diffuse

For consistency, I made the same modification to the front wheel Diffuse map. Here are the final renders. (On hindsight, the front wheels look too new in these renders.)
Figure 4. Four angles of the final render
I turned on Final Gather to make the shadow areas brighter when rendering the final video. I made further minor parameter tweaks that made the final video look slightly different from the renders above.
Here are two points about Arch & Design that I learned from this test:
  • Setting Reflection Glossiness very low will result in dark or even black reflections.
  • Reflection Color should be close to white.
I hope you find this walkthrough useful.

Credit: The Tumbler model and textures were created by Henry Chan. 

Wednesday, December 10, 2014

Reflection on Batman Tumbler - Part 2: Reflection Color

In the previous post, we saw how I got back reflections and hit another problem with bump effect as shown here.
Figure 1. The last render we covered. Notice the bump effect problem on the metal piece near the back wheel.
There is a metal piece near the back wheel that should be smooth but looks bumpy. I checked the Bump map slots and found that the Bump map slot was assigned an incorrect bitmap. Easy to fix. Other than that, I felt the bump was too strong, so I reduced the bump amount from the default 0.3 to 0.15. I got this render.
Figure 2. Bump effect fix. Note that the metal piece near the back wheel now looks smooth.
At this point, the render looked fine and I could have stopped. However, I thought I should make use of the painted texture maps in some way. To begin, I assigned the Specular bitmap to the Reflection Color map slot.
Figure 3. The Specular bitmap
I know that reflection color for an Arch & Design material should be close to white. How do I make the Specular bitmap, which is rather black, close to white? I needed to cheat and I cheated in 2 steps.
First, I forced the image to be interpreted as if it had gamma value of 1.0 even though it actually had sRGB gamma (which is approximately gamma 2.2).
Figure 4. Forcing gamma 1.0 interpretation
Next, I manipulated the Output Curve of the bitmap to make it even closer to white.
Figure 5. Manipulating bitmap Output Curve
Here is a comparison to show what these steps do.
Figure 6. Specular bitmap comparison. 1: original image; 2: forcing gamma 1.0 interpretation; 3: manipulating Output Curve

With these manipulations, I got this render.
Figure 7. Render with manipulated Specular bitmap
Note that I got back the dirt details painted in the Specular bitmap. However, I found the reflection color of the dirt too dark. I know that the Diffuse bitmap has color for dirt areas, so I made another cheat: I added the Diffuse map, interpreted as having gamma 1.0, to the Specular bitmap. I used a Composite map to do this. Here is my setup.
Figure 8. Adding Diffuse bitmap to Specular bitmap
And here is the render that I got.

Figure 9. Render with Diffuse map added to reflection color

Now it is time to check the render from other angles.We will cover this in the next post.

Credit: The Tumbler model and textures were created by Henry Chan.

Friday, December 5, 2014

Reflection on Batman Tumbler - Part 1: Getting Back Reflection

Last week I did a quick Arch & Design shader test for my class. Here is the result:


First, a proper credit. The Tumbler model and textures were created by Henry Chan, a modeling student here at CG Protege.

The reason I carried out the test out was that Julien Lew, a student in the Visual Effects class I am teaching, used the model in his assignment. He worked on the shaders and could not get reflections on the model. In this post, I will share what I found.

Technical details are due. All the images were rendered using 3ds Max 2011, Mental Ray renderer. The shaders are Arch & Design.

I started off with this render.
Figure 1. Starting render. Note the lack of reflection on the body.
I used Mental Ray Daylight system and turned on the mr Photographic Exposure Control. I set Exposure Value (EV) to 10.0. To save effort of selecting a HDR map, I simply used mr Physical Sky map. I used a Photometric light for rim lighting and 8 photometric lights surrounding the Tumbler as fill lights. This way, I can get reasonably good-looking render without using Final Gather. Figure 2 shows my lighting setup.
Figure 2. Lighting setup
The first step in troubleshooting a complex shader is to understand its structure. Next, go through the structure to isolate the cause of the problem. Thanks to Julien's work, we isolated the cause of lack of reflections to the material called "Grey" assigned to the Tumbler body.
Figure 3. "Grey" material

The Reflection Glossiness map slot (highlighted in figure 3) caught my eye. Inspecting the bitmap used as glossiness map, I found that it was very dark.
Figure 4. Bitmap used as glossiness map
To verify, I rendered with the glossiness map disabled (in other words, Reflection Glossiness was constant at 0.5 throughout the surface).
Figure 5. Render with constant glossiness. Note the unnatural bumps on the metal piece near the back wheel.

Now I got reflections on the metal body. Problem solved.

However, another problem arose. One of the metal pieces near the back wheel had strange bumps (I expected it to be smooth). The next post will cover this.

Credit: The Tumbler model and textures were created by Henry Chan.