Tuesday, May 22, 2012

Mudbox PTEX to Houdini Mantra

In order to export a PTEX from Mudbox to Houdini (for rendering with Mantra), the workflow is at first similar to the Mudbox PTEX to Maya Renderman tutorial I wrote.  The main difference being that there will be more hijinks in Houdini to get the displacement to work correctly.

To add another level of complexity, I have chosen to also work with PTEX color maps.  Here is my sculpt with the painting on it in Mudbox.  I tend to paint in many layers, but have merged them for the sake of simplicity in this tutorial.

I have switched the Display to Flat Lighting in order to better show the color, this allows us to make sure the color PTEX in Houdini is mapping properly.

Without Flat Lighting:

Flat Lighting on:

To prepare your model for PTEX, step the mesh down to level 0 (navigate levels using the Page Up or Page Down buttons on the keyboard), go to Mesh and select PTEX Setup... from the dropdown menu.


A blue and white grid will appear on your model.  Increase or Decrease at will to find a happy medium between a clean blue line and a small file size.


Select Done when ready, the program will spend some time calculating.
As stated before, I have merged all my paint layers to simplify this next step.
Select your paint layer and Right Click on it.  On the menu that pops up, click on Export Selected...


Save your file as a PTEX file.  The folder will default to the Mudbox files on your computer, it may be necessary to redirect first.


Go to Maps, Extract Texture Maps, and select New Operation...


Unlike the Renderman process, this time select Displacement Map on the popup window.


Make sure the Target Model is set to level 0 and the Source Model is set to your highest level.
Next to Search distance, click the Best Guess button.
Under Output option, be sure to identify the Base File Name.


In the popup Save As window, be sure to to change the Save as type to .ptx


After hitting Save, click the Extract button on the Extract Texture Maps window.
This may take some time.
Finally, before leaving Mudbox, export your mesh as an .obj at the lowest possible mesh level.

Now, on to Houdini!
For the purposes of this tutorial I will be using Houdini 12.0.543.9, but I am sure the essentials will translate to other versions.

To start things off go ahead and select File, Import, then Geometry and select your .obj model.


This will create a geometry node, my model imported as a very giant scale so you may need to move around to find your sculpt.


Dive into the node by double-clicking it.  Hit the Tab button to bring up the node menu and start typing Reverse.  Connect the Reverse node to your imported file.

This is going to re-arrange the vertex order in the model in order to better orient it for the PTEX textures later.


Jump back up to the object level and select your geometry node.
In the object's pallette, under the Render tab and the Geometry sub-tab, make sure the Polygons As Subdivision tab is checked.


Now that we have our model set up, it is time to customize our shader.
Open up the Material Palette and drag a Mantra Surface material onto the /shop pane.


Click the ball icon on the material to open the attributes above it.
On the Surface tab select the Diffuse tab.  Check the Use Color Map box and load your color map .ptx file into the Base Color Map section.


Inside your geometry node, attach a Material node to the bottom of the Reverse node and point the Material to your Mantra Surface shader.


If you render at this point, the texture will look like a confused game of Tetris.


To fix these issues we have to re-jigger the material.  Jump into the shop network and dive into your mantrasurface node.

 ^^Double-Click this to reveal...^^

^^MADNESS^^




Don't panic.

Press l to organize if you wish, but don't worry too much about aesthetics at this point.  Click the magnifying glass icon in the top right corner of the pane and type the word diffuse.

Then click Select Matches and all your navigation issues are over!
Simply zoom into the newly selected node.

 
The first thing we will do is to Tab a PTexture into existance above our diffuseColor node.


On your diffuseColor node, there are a number of little nibs sticking out the side.  Each of these is a hidden node you can pop out of the larger node.  We are going to be using the hidden node Base Color Map on the diffuse Color.

 Middle mouse button click on the dot next to the Base Color Map to select it, it should light up yellow.  Then right click on the newly colored nib and click Expose Input(s) on the menu that pops up.

It will seperate as a new little node.


There is no need to delete any nodes, just leave them as is and connect the following.

Connect the Base Color Map setting from the baseColorMap node to the PTextu... input on the ptexture1 node.      

Connect the Textur... setting on the ptexture1 node to the Diffuse Color input on the surfaceModel node.  This will automatically detatch the previous connection, that is fine.

                                   
Re-render and you will find the orientation of the texture is now correct.


Now to fix the displacement.

Still in your /shop/mantrasurface network, click the magifying glass icon in the top right corner of the pane.  Type in textureDisp and hit Select Matches.

It should take you here.


Tab in another PTexture node.
Middle mouse click to select the top red nib on the textureDisp node and then right click, extract to reveal the hidden displacementMap node.  Connect the top option (Displacement Map) to the top option on your ptexture2 node (PTextu...).


Now take the output of your ptexture2 node into the only inputs on the luminanceDisp and RGBDispChannel nodes.


We are now done with the shop network.
Go back into the Material Palette and select your Mantra Surface material.
Select the top Displacement tab in the attributes.

Check the Enable Displacement Map box and load your displacement PTEX file.
At this point I am getting results, but they are not good ones.
I suspect this is because the Displacement Bound is linked to the Displacement Scale.


There is an expression set to the bound by default, go ahead and break that.

I set my Displacement Scale to -5 and my bound to 0.
I fiddled with the numbers a great deal, but was unable to pull much detail from it.

Here is the render and what is in the viewport.

Hope this helped get you started, I would much rather use the PTED to Maya Renderman Method (as the results are near perfect) but the Houdini route will suffice if you do not have access to Renderman.

Happy Displacements,
Josh Evans

Tuesday, May 15, 2012

Mudbox PTEX to RenderMan in Maya

Ptex, a fantastic up and coming displacement system utilized in Toy Story 3 in order to allow high polygon models to be animated with ease while in their low-res versions.  The best part being, NO UVs REQUIRED.  That's right, it blows my mind entirely!

 For the uninitiated, here is Pixar presenting a tech demo of exactly what the technique is capable of.



Here is my model in Mudbox at its highest and lowest subdivision levels.


The first thing you'll want to do is set up your model for Ptex.  Navigate to Mesh > PTEX Setup.


This will instantly add an interesting blue diamond grid to your model.  How crisp and clear the edges of this grid are will determine the resolution of the final displacement.  Hit the Decrease and Increase buttons at the top of the screen to taste, raising the resolution too many times will result in a ridiculously large and unwieldy file.




Hit the Done button and your model is fully set up for Ptex.
Next we will send the base mesh to Maya, sometimes the actual Send to Maya options can be a bit squiffy, so I would recommend selecting your mesh and exporting as an .obj to then import into Maya.



Make sure Renderman is your renderer in Maya.


Still in Mudbox, select Maps > Extract Texture Maps > New Operation...


In the following pop-up, you will want to select Vector Displacement Map.














Check to make sure the top box has your model at the lowest possible mesh and the bottom, the highest.

Depending on the model, feel free to change your Image Size and be sure to set the Vector Space to Object.
Click the folder icon next to Base File Name and a Save As window will appear.  This window defaults to .tiff so be sure to manually change the Save as type to Ptex file.


For some reason, selecting this option causes Mudbox to repeat the extension, so be sure to fix that before hitting the Extract button on the bottom of the Ptex window.


Now to Maya.
Select the .obj of the base mesh you imported of the model and, in the Attribute Editor under the shape tab, select Attributes > Renderman > Ptex Support.



Repeat this, only with Subdiv Scheme.


Open Slim using the icon with the S surrounded by yellow boxes in the RenderMan tab.


Once Slim is open, create a new palette and throw down an AllPurpose shader.
Scroll to Displacement and click the little icon next to it that appears to be molded clay.
Select Connect...


Add the Displacement node.


Enter the Displacement node and click the blue arrow icon next to Input Vector and Connect... it to a Ptex Vector.


This will add an option for importing your .ptex file.
Click the newly appeared folder icon and open your file.


Start your Scale off at 1.


In your AllPurpose node, 2.7 is a good start for your Displacement Bound.


Select your object in the viewport and then right click on the AllPurpose.
Choose Attach as surface and then render the scene with Renderman.


I am quite happy with the final results, for this particular model I ended up upping the Displacement Bound to 100 in the All Purpose node and the Scale to 150 in the Displacement node.

The render below took 0:05 to render at 960x720.  That's pretty dang good for a displacement.  It is easy for me to see why this method is so attractive.  


Here is the model rendered in Maya Software...


...and the Mudbox Ptex, rendered using Renderman in Maya



Happy sculpting, animating, and rendering!
Josh Evans