Ptex is a texture mapping system originally developed by Walt Disney Animation Studios.
When utilized properly, Ptex can save you a lot of time and effort
by completely bypassing the UV unfolding portion of the texturing workflow,
while also affording superior painting results since Ptex doesn’t suffer from texture stretching
or UV Shell seams.
It foregoes the typical UV workflow in favor of assigning a separate texture
to each face of a subdivision or polygon mesh.
An adjacency map then determines how to arrange these faces on the mesh surface.
In this movie, we’ll show you how to export both a diffuse color
and displacement map in Ptex using Mudbox…
…and then import those maps in Maya for rendering in mental ray 3.10.
Before we start, we’ll need to activate mental ray’s Ptex recognition in Maya.
Go to your Maya install folder and navigate to the “mentalray” folder.
Open the maya.rayrc file in a text editor and add the following line at the end.
Make sure to save the file.
Now before working in Maya, we’ll need a model to work with.
Open the “Dragon_Head.mud” file in Mudbox.
This opens a high resolution, sculpted mesh.
However, the resolution of this mesh is too high for most practical purposes.
Ideally, we’d want to paint our texture map onto this mesh,
then export the “base” version of it to Maya and apply these finer details,
like these scars and scales, as a normal map, displacement map, or vector displacement map.
To learn more about the way Mudbox and Maya interact, see our tutorial series on
“Working with Maya and Mudbox”.
The UVs on this model are a mess.
If we attempted to paint a texture it or export a displacement map based on them,
they wouldn’t turn out correctly.
Luckily, Ptex doesn’t require the use of UVs at all.
First, let’s turn on the wireframe mode to give us an idea of the topology.
Now select the head geometry and use the Page Down key
to step this model down to its lowest subdivision level.
We must prepare our model for Ptex at Level 0.
Making sure the head is selected, go to the Mesh > PTEX Setup… command.
Mudbox will ask you if you’d like to convert the current UV paint layer to a Ptex paint layer.
Feel free to, though you’ll probably create additional paint layers later anyway.
Mudbox displays the PTEX Setup window
and covers the dragon head in small squares known as texels.
These texels are a visual representation of the resolution of the texture
that will be laid out onto your mesh.
If you zoom in close, notice the edges of each texel are quite jagged.
If you set up Ptex at this resolution, it would result in a texture less than 1024 x 1024 pixels,
which not even close to enough to display the high amount of detail in our mesh.
To ensure that our textures and displacement details will be crisp and clear,
we’ll want to increase the texel resolution via the PTEX Setup window.
Note that every time we increase the texel resolution, the larger the Ptex file will become
and the more RAM intensive it will be to load.
It is also possible to increase the texel resolution in specific areas,
which is useful if some areas are more detailed than others.
However, since the spread of our detail is pretty even, we won’t bother with that now.
Let’s increase it to about 14 million texels. Then click “Done”.
When Mudbox finishes converting, you can use the Page Up button
to step back up to full resolution.
Now use the Mudbox Paint Tools to add some color to your dragon head.
Unlike before, the painting now occurs properly across the mesh.
If you go to the UV View, Mudbox confirms that it is no longer relying on a UV mesh
to place the painted texture across your model.
Once you’ve finished painting your mesh,
you just need to export the painted textures and displacement map.
First go to the Layers tab and merge all the paint layers into one.
Right-click the merged layer and select “Export Selected”.
You can then save an 8, 16, or 32-bit .ptx file to your hard drive.
Now that the colors of our head are saved, we just need to export the details.
Go to Maps > Extract Texture Maps > New Operation.
We’re going to export our details as a Displacement Map.
Using the Object List, assign the Level 0 mesh as our Target Model,
and the Level 4 mesh as our Source Model.
Set the Method to Subdivision, since the Source and Target are based on the same topology.
Set the the Map Type to “Ptex”, and then then Texel Distribution to “Use PTEX Setup”.
Finally, set the File Name to the same location that you saved your texture from earlier.
Click Extract.
Your two .ptx files are ready for Maya.
All that’s left to do is to export a low res version of our model.
Like before, use the Page Down key to step this model down to its lowest subdivision level.
This is the model we’ll want to use in Maya, so go ahead and select the layers for the head, eyes,
and teeth, and export them to a new Maya scene using the File > Send to Maya command.
Since we’re going to be rendering our Ptex maps using mental ray,
you’ll need to make sure the appropriate plug-in is loaded in the Plug-in Manager.
Next, we need to prepare our Maya mesh for Ptex.
The mental ray implementation of Ptex requires a subdivision surface.
However, our model is a polygon mesh, so we’ll need to use a subdivision approximation instead.
Select the head, then go to Window > Rendering Editors > mental ray > Approximation Editor.
In the Subdivisions (Polygons and Subd. Surfaces) section, click Create.
This creates a “mentalraySubdivApprox1” node connected to the head mesh’s shape node.
Now that our model is ready, we just need to assign the shaders.
Open the Hypershade. We’ll be using a "mia_material_x" as our base material,
so create one and drag it onto the model.
In order to read in our .ptx files, we need to leverage a special node,
called "mib_ptex_lookup", specifically designed for it.
Create one of these nodes and point it to your “dragon-diffuse.ptx” file.
Note that the path name for the ptx file must be absolute.
Name the node “dragon_diffuse”.
We can feed the output of the "dragon_diffuse" node straight into the Diffuse attribute
of your "mia_material_x" to assign the Ptex texture to our model.
You can confirm this by setting the renderer to “mental ray” and then rendering the scene.
Now we’re just missing the added detail of our displacement map.
In order to access the displacement map attribute for the "mia_material_x" node,
you must first go to its shading group via the Shading Groups tab in the Hypershade.
In the Attribute Editor, scroll down to the Displacement Shader section
and click the map button.
Because a displacement map actually uses grayscale values
to calculate the height displacement on a model’s surface,
we’ll first need to convert the output of our "mib_ptex_lookup" node
into grayscale using an “mib_color_intensity” node.
Once you’ve connected that to the Displacement Shader attribute,
you can then create another "mib_ptex_lookup node" like we did for the diffuse color,
and feed that value into the mib_color_intensity node's input port.
Now if you render the scene again,
you can see that our details from the high res mesh in mudbox have carried over.
Due to our use of the color intensity node,
we can actually increase or decrease the intensity of our displacement map
by adjusting the “Factor” attribute of the mib_color_intensity node.
And of course we can adjust the reflectivity, glossiness,
and other attributes of the base material itself.
Just like the original mesh in Mudbox,
we managed to accomplish all this without ever unwrapping the UV mesh.
Currently Ptex is not an approach you’d want to use for all productions.
Not all renderers support Ptex as of now.
Additionally, Ptex files are quite large and thus not efficient enough
to be used in games pipelines yet.
In cases like these, you can bake your Ptex to UVs in Mudbox
using the Transfer Paint Layers option of the Extract Texture Maps command.
There are also certain patterns, for example a weave on a cloth,
that make much more sense to paint onto a 2D UV mesh.
However, for organic meshes, Ptex is gaining steam
and is already being put to use in various beauty renders, short films, and even full-length movies.