A quite simple Python script that automates a task that can be useful when working with PBR textures (used for realistic rendering in video games, architecture, movies, etc).
When you can't re-export a PBR texture especially for the workflow needed by the shaders of the game engine you're using. This is a quite common case when you download "as is" a PBR texture that has been already exported as a predefined set of image files, and then you definitely can't re-export it as you'd want.
For example, Unity and its PBR materials (no matter Standard, HDRP or URP) prefer to have a Smoothness texture (which is the opposite of a Roughness texture) inside the alpha channel of either the Albedo or the Metallic textures.
Unreal Engine 4, for its PBR materials, prefer to have a Roughness texture.
So, if you're willing to use in Unity a PBR texture that have its Rougness as a separate file, then this script would be useful.
It takes a Roughness texture, inverts its color to obtain a Smoothness texture, and injects it as the alpha channel of either an Albedo or a Metallic texture (it depends on what you have).
Here it is explained with a beautiful chart.
Textures shown in the chart are courtesy of CC0 Textures.
I couldn't find a easy way to do this and got pissed off enough to finally do it myself.
- Clone the git repository or download and extract it somewhere.
- Install Pillow. You can try with
pip install -r requirements.txt
but if it doesn't work, take a look at the Pillow website.
Tested on :
- Python 3.7.3 - Ubuntu 18.04.1 LTS on Windows 10 (WSL1)
- Python 3.7.3 - Windows 10 (1909)
This can be used as a standalone script or as a Python module.
It may take a few seconds to complete when using it on high resolution textures (which is being common in video games using PBR textures)
If you have a Roughness texture that you wish to insert as the alpha channel of a Metalness texture :
$ python rough2alpha.py Metal003_2K_Roughness.jpg Metal003_2K_Metalness.jpg
If you have a Roughness texture that you wish to insert as the alpha channel of an Albedo (Color) texture :
python rough2alpha.py Terrazo003_2K_Roughness.jpg Terrazo003_2K_Color.jpg
Also, you can customize the filename of the generated texture by passing a suffix
argument.
$ python rough2alpha.py --suffix Unity Metal003_2K_Roughness.jpg Metal003_2K_Metalness.jpg
Looks pretty much like its usage as a standalone script. The optional suffix
argument is now a keyword argument.
import rough2alpha
rough2alpha.convert('Metal003_2K_Roughness.jpg', 'Metal003_2K_Metalness.jpg', suffix='Unity')
The code is made available under the MIT license.
For your knowledge, here are some useful links about PBR and its workflows :
- PBR Texture Conversion, Marmoset
- The Differences Between Metalness and Specular Workflows, Poliigon