Skip to content

Instantly share code, notes, and snippets.

@saim80
Created June 18, 2015 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saim80/337e6d307e1650f0d6ad to your computer and use it in GitHub Desktop.
Save saim80/337e6d307e1650f0d6ad to your computer and use it in GitHub Desktop.
Image magick script to merge grayscale textures into one image for PBR rendering.
#!/usr/bin/python
import optparse
import subprocess
import os
METALNESS_SUFFIX = "_metalness"
ROUGHNESS_SUFFIX = "_rough"
AO_SUFFIX = "_ao"
EMISSIVE_SUFFIX = "_emissive_power"
COLOR_SUFFIX = "_color"
OUTPUT_SUFFIX = "_combined"
def main(options) :
name, ext = os.path.splitext(options.inputImage)
prefix = name.replace(COLOR_SUFFIX, "")
metalPath = prefix + METALNESS_SUFFIX + ext
roughPath = prefix + ROUGHNESS_SUFFIX + ext
aoPath = prefix + AO_SUFFIX + ext
emissivePath = prefix + EMISSIVE_SUFFIX + ext
if os.path.isfile(options.inputImage) :
output = prefix + OUTPUT_SUFFIX + ext
subprocess.call(["convert", metalPath, roughPath, emissivePath, aoPath, "-channel", "rgba", "-combine", output])
if __name__ == "__main__" :
parser = optparse.OptionParser()
parser.add_option("-i", "--input-image", dest="inputImage", help="A path to input image", default="./input.png")
options, args = parser.parse_args()
main(options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment