Monday, October 8, 2012

MentalRay Custom Color Buffer / Linear Work Flow

Goal
Convert an existing mental ray shaded object into comp passes.

Introduction


Pic 1

In pic 1, we have the original shader.


Pic 2

In pic 2, we have the shader network. The top blinn is for the wooden base, the bottom material is for the porcelein/ceramic material. It consists of a fast_SSS connected to a mia_material, the color correction is to vary the front SSS color from the back SSS color.


Seperating the Passes
To reiterate, the goal is to recreate Pic 1 from passes.

Step 1: Create Passes
First lets go into Render Settings > Passes


Pic 3: Passes Window


Click on the first button on the right. It'll show a window with a list of different available passes. We'll just click on custom color, there are options to enter a prefix if needed. Rename the pass as "Diffuse". Do this another 3 times and name it as, "Refl", "SSS", "Spec". Once created, select all the passes and press the green check button in the middle of the Passes window. This will activate the passes.

Step 2: Rebuild the Shader Network
Lets do the wooden base shader first. This is simple blinn shader that consists of diffuse, specularity, and reflectivity.

Step 2A: Base Section
1. So let us create 3 writeToColorBuffer nodes in the hypershade. It can be found under the hypershade>create>mental ray>miscellaneous. Rename them as diffuse, spec, and refl. The custom color drop down list will contain a list of color passes we created in Step 1. Select the corresponding color passes for each writeToColorBuffer node.

2. Let us duplicate the blinn shader as well, since we can't output individual shading components from the blinn shader, we will need to re-create the shading components.


  • Diffuse: For the original blinn, turn reflectivity to 0 and specular color to black, and rename it diffuse.
  • Reflection: For reflection, create a mib_reflect under Sample Compositing
  • Specular: For the duplicated blinn, change diffuse to black and reflectivity to 0 and rename it to spec.


3. Now connect each of the blinn shader output to their corresponding writeToColorBuffer input. If you select all the nodes and graph it now, it'll show the pass nodes in the hypershade as well, as shown in pic 4.


Pic 4


4. If you render now, only the diffuse pass will show up since only the diffuse shader is connected to a shading group. One way for the other writeToBuffer node to evaluate is have the blinn somehow connect to the shadingGroup. But the official method is to use the evaluation passthrough of each writeToBuffer node.

  • Connect the refl node to the spec node, and the spec node to the diffuse node.
  • Disconnec the diffuse shader from the shading group
  • Create a surface shader and connect it to the shading group
  • Connect the diffuse writeToBuffer node to the surface shader input color.

It'll look something like in pic 5.



Pic 5


5. If we render now, it'll look like this,


Pic 6

The base will be black because of the surface shader. Here is what the passes look like,


Diffuse



Reflection



Specular



This concludes the base part.

Step 2B: Vase Section


  1. Create a SSS pass in render settings
  2. Create 4 writeToColorBuffer nodes and rename them as 2XSSS, refl, diffuse
  3. Upgrade the shaders,the vase part, I have a misss_fast_shader for diffuse and SSS, and a mia_material for the reflection. The misss shader is connected to the mia_material through additional colors. However, it would not matter once we use passes. These shaders are much easier to ouput passes since you can upgrade them to their respective X_passes shaders. The connections will be a little messed up but its easy to fix.
  4. Once upgraded, have the misss output front and back SSS results into to color buffers.
  5. Output diffuse result into the diffuse color buffer
  6. Output the reflection result from mia_material into the refl color buffer
  7. Disconnect materials from the shading group
  8. Create a surface shader and connect the last buffer node to the surface shader



pic 7
The final layout. 

Step 3: Render
Diffuse

Reflection

Specular

SSS
Combining the Passes
Once combined, you will notice that the combined passes will NOT look like the master beauty pass, this is due to the exposure mental ray adds to the beauty pass that is not added to the buffers. 

Comped Image

Master Beauty



To correct for this, we will need to upgrade our workflow to linear workflow.

Linear Workflow


  1. Change render settings > file format to exr
  2. Change render settings > quality > framebuffer to 4x16bit half in render settings
  3. Change render view > display > 32bit HDR
  4. Change render > display > color management, image color profile to linear, and display color profile to sRGB
  5. Color correct ALL texture/color swatch with a gamma correct node set to 0.4545



Comped Image

Master Beauty

The final shader network looks like this,


Final Shader Network

To have both master beauty and final passes rendered out, I connect the last outEvaluation to outMatteOpacity of the surface shader, doesn't effect anything but it will let it evaluate the passes. 

Notes I
There are limitations to custom color buffer workflow, some shading components from maya shaders will not output correctly and some might even interfere with other shading components. The safest way to ensure a consistent workflow would be to stick with mental ray shaders and keep it simple, after all, we're pretty much offloading the light tweak stage to the compositing department in this workflow.

Notes II
To improve the workflow it is advisable to standardize/limit the shaders used and also automate the pass and gamma correction process. Mel scripts will be provided.... when i get around to it.





0 comments:

Post a Comment