Texture Conversion Script (Patreon)
Downloads
Content
Get perfect colors every time by batch converting your Arnold, Karma and RenderMan textures.
Renderers like Arnold, Karma and RenderMan recommend converting textures to their native formats: .tx, .rat and .tex, respectively. This is largely for performance reasons. Conversion creates "mipmapped" textures that contain multiple resolutions to facilitate reducing memory usage. For example, a mipmapped texture will only use a tiny amount of memory when it is far from the camera in a rendered scene. An unoptimized texture would use a fixed, large amount of memory no matter its relation to the camera, leading to major performance problems when there are thousands of textures present.
In small scenes this is a non-issue, but there is another good reason to convert your textures before rendering: color management. Instead of relying on OpenColorIO rules, image metadata, and DCC interface dropdowns you can just "bake" the correct color space into all your images. Have a lot of "data" maps like displacement or roughness? Bake them in Raw format. Have some HDRI environments downloaded from the internet? Bake them as sRGB Linear. Using some old PNGs lying around on your hard drive? sRGB Texture for them!
Doing this in advance takes all the guesswork out of getting the right colors 100% of the time. Plus, you'll be all mipmapped and ready to roll in larger scenes where performance could become a concern.
All renderers have tools to auto-generate optimized textures, but the stumbling block is the "auto" part. We have to rely on the author of the conversion app getting it right in the context of our unique workflow, plus the renderer "guessing" correctly in ambiguous cases. Arnold tends to guess right most of the time, RenderMan less so, and Karma XPU flat out gets it wrong the majority of the time, thanks to current limitations in Hydra and MaterialX.
We can bypass auto generation and instead use the command line utilities that come with each renderer: maketx, imaketx and txmake. Each renderer comes with thorough documentation about how to use these tools, but one issue is that it's not immediately obvious how to process many images at once. These tools are designed to convert one image at a time, so in order to do many we'll need to write a script that loops over all the files we're interested in.
With that in mind, I decided to make the Ultimate Texture Conversion Script to make it as painless an humanly possible to get all your textures in the right color space and mipmapped prior to rendering. Convert once and forget about it!
I wrote the script in PowerShell, so it's possibly Windows-only, though I hear PowerShell works on Linux and Mac. It would be easy to redo this in Python for more universal access, and that's something I may do eventually.
Anyway, for now, download the full txcnv.ps1 script at the end of this article. Before starting you'll need to update a few things. Change the paths to each renderer to be correct on your system. You'll also want to point to your OCIO config. You can change the file name tokens the script looks for, or add your own. In my case, I set it to encode as Raw when the script finds disp, rough, sss or opac tokens in the file names.
That's all there is to it! To convert a folder of textures to the native format of the renderer of your choice simply type ./txcnv a/k/r <folder>, sit back, and relax. (The a/k/r part means a for Arnold, k for Karma or r for RenderMan.) Magic ensues:
Update! I added a feature to check if the file has already been converted and if it's up to date.
Update update! I fixed a couple small syntax things and added a Python version.