Saturday, June 1, 2013

How to render position pass in Maya and then use it with the PositionToPoints node

The PositionToPoints node is used to generate a 3D point cloud using the position data contained in the image. In this tutorial, we will first create a position render pass in Maya 2014 and then we will create a 3D point cloud using the position data in Nuke. Then, we will composite a 3D object in our scene with help of the 3D point cloud. Lets get started:

Step - 1
Create a project folder in Maya and open the scene that you need to render. Next, create a camera and set the camera angle. Figure 1 displays the scene that we will render.
Figure 1
We will be rendering a 32 bit image so first we set frame buffer to 32 bit.

Step - 2
Invoke the Render Settings window and then select mental ray from the Render Using drop-down list.

Step - 3
Now, choose the Quality tab and then enter 1.5 in the Quality edit box.

Step - 4
Scroll down to Framebuffer area in the Quality tab and then select RGBA (Float) 4x32 Bit from the Data Type drop-down list.

Next, you will create layers in Layer Editor and create layer overrides.

Step - 5
Select everything in the viewport and then choose the Render tab in Layer Editor. Next, choose the Create new layer and assign selected objects button from Layer Editor, refer to Figure 2; the layer1 layer will be created in Layer Editor.

Figure 2
Step - 6
Rename the layer1 layer as beauty_layer.

Step - 7
Similarly, create a new layer and rename it as position_layer.

Step - 8
With the position_layer selected, invoke the Render Settings window and then clear the Enable Default Light check box. Next, right-click on the check box; a shortcut menu will be displayed. Next, choose the Clear Layer Override button from the menu.

Step - 9
Select the beauty_layer in Layer Editor and then in the Render Settings window, make sure the Enable Default Light check box is selected and then create a layer override for it, as discussed above.

Step - 10
In the File Output area of the Render Settings window, enter <Scene> in the File name prefix edit box.

Step - 11
Select OpenEXR (exr) from the Image format drop-down list.

Step - 12
Select the name.ext (Single Frame) option from the Frame/Animation ext drop-down list because we will be rendering only one frame.

Step - 13
In the Indirect Lighting tab, select Final Gathering check box from the Final Gathering area and then create a layer override. Next, enter 200 in the Accuracy edit box.

Step - 14
Now, close the Render Settings window.

Step - 15
Select the position_layer layer in Layer Editor and then invoke the Hypershade window.

Step - 16
Now, add a Sampler Info uility node and and a Surface Shader node to the Work Area tab of the Hypershade window.

Step - 17
Drag the samplerInfo1 node onto the surfaceShader1 node with the SHIFT held down; Connection Editor will be displayed.

Step - 18
Expand the pointWorld node in the Outputs area. Next, expand the outColor node in the Inputs area.

Step - 19
Connect pointWorldX, pointWorldY, pointWorldZ to the outColorR, outColorG, and outColorB, refer to Figure 3.
Figure 3
Step - 20
Next, right-click on the surfaceShader1 node; a marking menu will be displayed. Next, choose Assign Material Override for position_layer, refer to Figure 4; the surface shader will be applied to the objects in the position_layer as  an override.
Figure 4
Step - 21
Now, choose Render > Batch Render from the menu bar; the rendering will start.

Step - 22
On completion of the rendering, select camera1 in the viewport and export it as fbx file.

If you want to use the images that I have rendered, you can download the files from the following link: https://www.dropbox.com/s/o9h9fcbftxyjw5h/nt006.zip. This file contains camera fbx file as well. Next, we will bring the position into Nuke.

Step - 23
Start Nuke.

Step - 24
Read in the position pass; the Read1 node will be inserted in the Node Graph panel. Similarly, import the color pass in the Node Graph panel; the Read2 node will be inserted in the Node Graph panel.

Step - 25
Add a PositionToPoints node to the Node Graph panel.

Step - 26
Connect the Read2 node with the PositionToPoints1 node. Next, connect the pos input of the PositionToPoints1 node with the Read1 node.

Step - 27
Select the PositionToPoints1 node in the Node Graph panel and then press 1 to view the point cloud in the Viewer1 panel. Rotate around the scene to view the cloud properly, refer to Figure 5.
Figure 5
The points in the scene are the 3D representation of the position data that we rendered from Maya.

Step - 28
In the PositionToPoints tab of the PositionToPoints1 node, select wireframe from the display drop-down.

Step - 29
Choose Camera from the 3D menu; the Camera1 node will be inserted in the Node Graph panel.

Step - 30
In the File tab of the Camera1  node properties panel, select the read from file check box and then load the cam.fbx file that you have downloaded.

Next, you will add a 3D geometry in the scene and align it with help of the points in the cloud.

Step - 31
Add a Cylinder node to the Node Graph panel and then connect the butterfly.jpg with it that you have downloaded.

Step - 32
In the Viewer1 panel, place the cylinder as required.

Step - 33
Connect a ScanlineRender node to the Cylinder1 node; the ScanlineRender1 node will be inserted in the Node Graph panel.

Step - 34
Connect the cam input of the ScanlineRender1 node with the Camera1 node.

Step - 35
Select the ScanlineRender1 node and press M; the Merge1 node will be inserted in the Node Graph panel.

Step - 36
Connect the B input of the Merge1 node with the Read2 node.

Step - 37
Select the Merge1 node in the Node Graph panel and then press 1 to view the output in the Viewer1 panel, refer to Figure 6.
Figure 6
This concludes the tutorial. You can use Light and other nodes to blend the your 3D object with your render. Figure nt6-7 shows the node network used in the script.
Figure 7

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...