svictor
Registered
In this post I will be sharing scripts that will hopefully help with preparing PBR texture, especially for updating none PBR mod or conversion which often lack of certain required material textures, and often have to create new material texture using diffuse map texture.
The main tool used for scripting is ImageMagick: https://imagemagick.org/
Important Notice:
None of the scripts are meant to be one-button solution for creating PBR material (it's impossible). They are used to avoid some of the repetitive process and save time for preparing certain PBR materials.
It is almost absolutely required to do further manual editing on individual processed textures to achieve realistic results (depending on different materials).
Lastly, official PBR texture guide is still the best way for understanding and doing PBR properly.
Download Script:
Batching script is now provided for easy access, see in attachment.
Script can be opened by any text editor for further editing.
Here is how it looks like:
How to use:
The easiest way is to download batch script file as above mentioned. Extract and place script in a folder. Then put all original images into the same folder with script, then run the script & follow the instruction.
After processing finished, new textures will appear in the same folder, with corresponding material suffix, which can be opened in GIMP for further editing. You can easily sort those files by extension.
It is best to move those newly generated TGA files to another folder before further editing in GIMP or other software, so they won't accidentally be overridden if later runs batch script again for similar task.
Once all done, use official MapConverter tool to convert all TGA files to DDS, and ready to be assigned to a material and tested in game.
You can also run commands (which is provided in the following sections) manually. Here is step to do it manually:
Preparing Albedo map
Albedo map
Explain:
The above command creates base Albedo map using old diffuse map (the main texture of a material). The command follows the light-removal concept in official PBR texture guide. It first make a layer copy of original image and convert it to grayscale and invert color. Then apply layer multiply effect to remove lighting. And last, save processed file with _Alb.tga suffix in the same folder. (You may need to change file suffix to _Alba.tga if the texture has alpha channel)
You will still need to adjust Luminosity as official PBR texture guide has suggested.
Note about grayscale:
ImageMagick has many ways for converting grayscale, and affects the result of lighting removal. You can test and see which one of them works best:
-set colorspace Gray -separate -average
-grayscale Rec709Luma
-grayscale Rec709Luminance
-colorspace Gray
-modulate 100,0,100
See "Reference Link" at the end of post for more info about grayscale. Metal & Rough map commands also use those grayscale code.
Note about luminosity:
It is possible to add additional command after -composite to batch manipulate luminosity/brightness, such as one of the three follow command, by adjusting value highlighted in red (may require tests):
-gamma 1.2
-modulate 120,100,100
+level 0%,150%
Preparing Metal & Rough map
Metal & Rough map
Rough map only:
Metal map only (this option is probably useless):
Explain:
The above commands create base Metal & Rough map using old diffuse map (the main texture of a material). It will first convert image to grayscale and invert all color. Then remove color from blue (and also red if it's rough map only) channel by filling with black color, and save processed file with _Mr.tga suffix in the same folder. (Green channel is used for Rough map; Red channel is used for Metal map.)
General tip for further adjusting rough map (similar applies to metal map):
1. In GIMP, open _Mr.tga file that you have just generated from script.
2. Switch to Channels tab, click once on red & blue channel so that they are deselected. The idea is to only edit one channel at a time, and left other channel untouched.
3. From main menu Colors open Levels, adjust input & output levels as desired (darker = more smoothness; brighter = more roughness). As below:
Note: For some textures, inverted color may not be desired. You may want to re-invert the color or channel, or adjust certain area separately.
For example, the above image has a glass window, which should be smoother than the wall, but is darker in the original photo and has less smoothness after processing, so it needs manual editing and adjusting, same with other elements.
Reference Link:
https://docs.studio-397.com/developers-guide/general-reference/pbr-an-introduction-authoring-guide
https://docs.studio-397.com/developers-guide/track-development/general-tracks/naming-conventions
https://legacy.imagemagick.org/Usage/windows/#dos
https://imagemagick.org/script/command-line-options.php
https://imagemagick.org/script/color-management.php
https://imagemagick.org/script/command-line-processing.php#grayscale
https://stackoverflow.com/questions/13317753/convert-rgb-to-grayscale-in-imagemagick-command-line
Script Changelog:
The main tool used for scripting is ImageMagick: https://imagemagick.org/
Important Notice:
None of the scripts are meant to be one-button solution for creating PBR material (it's impossible). They are used to avoid some of the repetitive process and save time for preparing certain PBR materials.
It is almost absolutely required to do further manual editing on individual processed textures to achieve realistic results (depending on different materials).
Lastly, official PBR texture guide is still the best way for understanding and doing PBR properly.
Download Script:
Batching script is now provided for easy access, see in attachment.
Script can be opened by any text editor for further editing.
Here is how it looks like:
How to use:
The easiest way is to download batch script file as above mentioned. Extract and place script in a folder. Then put all original images into the same folder with script, then run the script & follow the instruction.
After processing finished, new textures will appear in the same folder, with corresponding material suffix, which can be opened in GIMP for further editing. You can easily sort those files by extension.
It is best to move those newly generated TGA files to another folder before further editing in GIMP or other software, so they won't accidentally be overridden if later runs batch script again for similar task.
Once all done, use official MapConverter tool to convert all TGA files to DDS, and ready to be assigned to a material and tested in game.
You can also run commands (which is provided in the following sections) manually. Here is step to do it manually:
1. Open console Command Prompt (DOS shell) from the folder that contains image (unfortunately there is not easy way to do it under WIN10).
Note: If the image is not PNG, you will have to change the png letters in command to the same format of your image. For example, if original image is DDS format, then change all *.png to *.dds
2. Copy the command line into console, hit Enter, and wait for finish.
Note: If the image is not PNG, you will have to change the png letters in command to the same format of your image. For example, if original image is DDS format, then change all *.png to *.dds
2. Copy the command line into console, hit Enter, and wait for finish.
Preparing Albedo map
Albedo map
Code:
FOR %a IN (*.png) DO magick convert "%~a" -channel RGB ( -clone 0 -set colorspace Gray -separate -average -negate ) ( -clone 0 ) -compose multiply -composite "%~dpna_Alb.tga"
Explain:
The above command creates base Albedo map using old diffuse map (the main texture of a material). The command follows the light-removal concept in official PBR texture guide. It first make a layer copy of original image and convert it to grayscale and invert color. Then apply layer multiply effect to remove lighting. And last, save processed file with _Alb.tga suffix in the same folder. (You may need to change file suffix to _Alba.tga if the texture has alpha channel)
You will still need to adjust Luminosity as official PBR texture guide has suggested.
Note about grayscale:
ImageMagick has many ways for converting grayscale, and affects the result of lighting removal. You can test and see which one of them works best:
-set colorspace Gray -separate -average
-grayscale Rec709Luma
-grayscale Rec709Luminance
-colorspace Gray
-modulate 100,0,100
See "Reference Link" at the end of post for more info about grayscale. Metal & Rough map commands also use those grayscale code.
Note about luminosity:
It is possible to add additional command after -composite to batch manipulate luminosity/brightness, such as one of the three follow command, by adjusting value highlighted in red (may require tests):
-gamma 1.2
-modulate 120,100,100
+level 0%,150%
Preparing Metal & Rough map
Metal & Rough map
Code:
FOR %a IN (*.png) DO magick convert "%~a" -channel RGB -set colorspace Gray -separate -average -negate -fill black -colorize 0,0,100% "%~dpna_Mr.tga"
Rough map only:
Code:
FOR %a IN (*.png) DO magick convert "%~a" -channel RGB -set colorspace Gray -separate -average -negate -fill black -colorize 100%,0,100% "%~dpna_Mr.tga"
Metal map only (this option is probably useless):
Code:
FOR %a IN (*.png) DO magick convert "%~a" -channel RGB -set colorspace Gray -separate -average -negate -fill black -colorize 0,0,100% -fill white -colorize 0,100%,0 "%~dpna_Mr.tga
Explain:
The above commands create base Metal & Rough map using old diffuse map (the main texture of a material). It will first convert image to grayscale and invert all color. Then remove color from blue (and also red if it's rough map only) channel by filling with black color, and save processed file with _Mr.tga suffix in the same folder. (Green channel is used for Rough map; Red channel is used for Metal map.)
General tip for further adjusting rough map (similar applies to metal map):
1. In GIMP, open _Mr.tga file that you have just generated from script.
2. Switch to Channels tab, click once on red & blue channel so that they are deselected. The idea is to only edit one channel at a time, and left other channel untouched.
3. From main menu Colors open Levels, adjust input & output levels as desired (darker = more smoothness; brighter = more roughness). As below:
Note: For some textures, inverted color may not be desired. You may want to re-invert the color or channel, or adjust certain area separately.
For example, the above image has a glass window, which should be smoother than the wall, but is darker in the original photo and has less smoothness after processing, so it needs manual editing and adjusting, same with other elements.
Reference Link:
https://docs.studio-397.com/developers-guide/general-reference/pbr-an-introduction-authoring-guide
https://docs.studio-397.com/developers-guide/track-development/general-tracks/naming-conventions
https://legacy.imagemagick.org/Usage/windows/#dos
https://imagemagick.org/script/command-line-options.php
https://imagemagick.org/script/color-management.php
https://imagemagick.org/script/command-line-processing.php#grayscale
https://stackoverflow.com/questions/13317753/convert-rgb-to-grayscale-in-imagemagick-command-line
Script Changelog:
v2022-04-01 hotfix1
- Fixed "Metal map only" option which had set wrong channel color.
v2022-04-01
- Now user can type in file extension in console before processing.
- Add new option to generate Albedo Map with Alpha Channel (only affect suffix name, which is required by MapConverter).
- Now displays processing text.
v2022-03-31
- Initial version
- Fixed "Metal map only" option which had set wrong channel color.
v2022-04-01
- Now user can type in file extension in console before processing.
- Add new option to generate Albedo Map with Alpha Channel (only affect suffix name, which is required by MapConverter).
- Now displays processing text.
v2022-03-31
- Initial version
Attachments
Last edited: