Monday, June 30, 2014

Pipeline for Mari

Problem: On previous BYU animations, shader artists have made use of Mari by The Foundry, but there have never been pipeline tools that support any of its operations or enforcing any of our standards. 

Solution: Starting this year, working with Andrew Rasmussen, we wrote a set of tools that supported the essential functions that shader artists find themselves using often. 

Andrew began development by interfacing with the Mari API and generating buttons in a custom pane without any functionality (see below).

New BYU Pipeline Tools for Mari (Upper Left Corner)

Export Selected Map/Export All Maps:

Problem:
Probably one of the most complex operations that these pipeline tools would have to support was the exporting of the image maps to the right format.

First, we would need to take all the channel layers and flatten them to prepare them for export while keeping the channel layers separate for further editing.

Second, and perhaps the most difficult challenge, is that in our past experience with dealing with image maps in Houdini, we've found that any other format other than the Houdini native image format, RAT, result in undesirable memory problems in the final render. However, since it is a file format that is native to Houdini, Mari doesn't naturally support conversion to this format.

Third, we would need to define an export destination when the project files aren't in a place that we can easily navigate to the ideal export directory where the corresponding model resides. Due to the average size and memory consumption of project files, we determined that it was most effective to store the project files on an external server from the rest of the project files we had in the film. This way, our shader artists could freely edit their shaders and then only bring them into the server when we had converted them to memory efficient RAT files, but it also made finding the export directory a difficult challenge.

Solution: First of all, Mari is very friendly when dealing with the data in its channels. All we need to do, once we confirm a project is loaded, is query for all the channels defined in the file. Typically this would come back with three results, Diffuse, Bump, and Specular. Once these channels are found, Flattening them and exporting them turns out to be a simple operation. Mari actually has a build in method that takes care of the flattening and exporting in one method and so we make good use of that method.

It turns out prompting the user for an export path is a relatively simple task. The mari.utils library provides a method to prompt for an existing directory:

Export Map Dialog
So, for each channel, we prompt the shader artist for the directory they want to save their image maps to. From there, all that they have to do is wait for the export and soon enough it succeeds!

Successful Export Message
However, the operations aren't quite done from a functionality standpoint. We used the method on the channel mentioned before to export maps as flattened, but we could not export it as a RAT file because its native to Houdini only.

So, we opted for a two step approach to the export. We would first export the maps as flattened PNG files, then we would use the Houdini image convert command from the shell to convert the PNG files to RAT files. And with that the export is completed.

Exported and Converted to RAT files
However, with the frequent export operations that a shader artist would need, defining one path for each exported image map would get rather tedious. So, we needed to remember where the artist had saved the file last. The solution comes in the form of a hidden file that will be able to store such metadata without bothering the artist. After the export location of the image map is designated for the first time, we store the result in a .projectInfo file. This way all we need to do when these buttons are clicked again is to open up the file and find the export path there.

Startup Script

Problem: When starting a new project in Mari, we needed to make sure that all the shader artists were painting with the same color settings that will work well with lighting and rendering in the final film. Naturally, the color settings that were best for our situation were slightly different than the defaults in Mari. We needed the Color Space to be Linear and the Gamma set to 0.45.

Mari Default Color Settings
Solution: It was a bit difficult to find the settings that would be able to adjust these parameters on startup, but it turns out that this toolbar is actually for Open Color IO, a library from Sony Imageworks for Color Management. Once we found the place where the settings for this toolbar was hiding, the procedure was relatively simple:

Automatic Color Settings Code
So, we run this simple script at startup and anytime an artist opens a new file, making the color settings correct without the shader artist to have to bother resetting them all the time!

Resulting Color Settings
Display Asset Info

This was probably one of the surprising bits of the pipeline for me, when I got to this button it was already done! Great job Andrew!