Converting Blender Filmic LUTs for use in Substance Painter

with the new Filmic Blender color management options getting a lot of attention I wanted to get the exact same looks when creating textures in Substance Painter.
Substance Painter supports LUTs in so called 3d format which are stored in .exr files. So our challenge is twofold: convert the bundled Blender Filmic LUTs to this format and of course to get results in Substance that match Blender as closely as possible.
The results of 3 of the filmic LUTs are compared side by side in the image below:

I made this comparison collage by keeping parameters like exposure (1) and gamma (also 1) the same in both Blender and Substance Painter and then took screenshots. I glued the screenshots together in GIMP. This way I could see all images on the same monitor. This is important because if the applied profiles are the same and both displays are sRGB, two monitors will still differ in their color response and it is fiendishly difficult to calibrate them (unless you have a very expensive monitor with the associated color calibration kit). My own monitors are not even the same brand so it is an easy trap to fall into if you compare images on two different monitors side by side.
Anyway, even this way when you have a close look the images are close in tone but not 100% identical and I am not sure what is causing this. There might be slight differences in camera aperture, focal blur and multiple importance sampling of the environment and of course Cycles' ray model is not the same as Iray's Substance painting mode renderer. Still, I think this is pretty close and useful to compare textures in Substance under different looks before transferring them to Blender.

How the LUTs were generated

I used the Python bindings of the OpenColorIO and OpenImageIO libraries to create a small script (code below). These are in fact the libraries Blender uses to work with color conversions.

The script takes a linear to linear transform that is encoded as an .exr image and creates a new .exr for each 'Look' in Blender's OCIO config file that is defined in the 'Filmic Log' process space.
The docs for the Python bindings for both libraries are not an easy read and the APIs have some small inconsistencies so it took some time to get it working. The code is far from beautiful but i commented the relevant parts. I am open to any critique that can help to improve the transforms.
Note that the code is not plug and play and i have no intention of improving that :-)

The Substance LUTs

They can be downloaded from my GitHub repository. They are bundled in one .zip file and should be unpacked before importing them in Substance Painter.

The code

#export LD_LIBRARY_PATH=/home/michel/ocio/lib
#export OCIO=/home/michel/Downloads/blender-2.78-b94a433ca34-linux-glibc219-x86_64/2.78/datafiles/colormanagement/config.ocio
#python 2.7
#
# run as
# python transformlook.py
#
# expects linear_to_linear.exr in the current directory and will write the transform there too

import OpenImageIO as OIIO  #  already installed using Ubuntu pkg manager
from sys import path
from array import array
path.append('/home/michel/ocio/lib/python2.7/site-packages/')
import PyOpenColorIO as OCIO

config = OCIO.GetCurrentConfig()

for look in config.getLooks():
 if look.getProcessSpace() == 'Filmic Log':
  lookname = look.getName()
  print(lookname)

  transform = OCIO.DisplayTransform()
  transform.setInputColorSpaceName(OCIO.Constants.ROLE_SCENE_LINEAR)
  transform.setView('Filmic')
  transform.setLooksOverrideEnabled(True)
  transform.setLooksOverride(lookname)
  transform.setDisplay('sRGB')
  processor = config.getProcessor(transform)

  # indentiy transform from https://support.allegorithmic.com/documentation/display/SPDOC/Color+Profile
  img = OIIO.ImageInput.open('linear_to_linear.exr')
  spec = img.spec()
  spec.set_format(OIIO.FLOAT) # for some reason this is not extracted from the image
  pixels = img.read_image()
  img.close()

  outfile = lookname + '.exr'
  transformedpixels = processor.applyRGB(pixels)
  imgout = OIIO.ImageOutput.create(outfile)
  ok=imgout.open(outfile, spec, OIIO.Create)
  if not ok:
   print(OIIO.geterror())
   break
  # ImageInput.read_image() returns a list of floats, and applyRGB(0 returns one too, but ImgOutput.write_image
  # expects an array of float and will die when passed a list. Bit inconsistent I think.
  a = array('d')
  a.fromlist(transformedpixels)
  imgout.write_image(a)
  imgout.close()


Nodeset: add a principled shader

NodeSet is now also available in a Pro version. Read all about it in this article or check out my BlenderMarket shop if you are interested.

Even though there are better paid and free PBR nodegroups/shaders available for Blender (for example from Jeffrey Hepburn or Remington Graphics) the new Principled BSDF (a.k.a. Disney shader or PBR shader) will no doubt prove popular with Blenderheads because it is so simple to use and gives decent results.

So I added an option to add this shader along with all the imported texture sets as well as a normal map node, basically giving you a one-click (almost) option to add a PBR material based on a set of textures from your favorite texturing tool. The new functionality is a available from Add -> Texture menu in the Node editor and sits alongside the original Set of images entry:

The resulting node setup (after selecting a set of textures) will look like this:
Note that this will of course only work with the new Blender 2.79 or with a recent daily build. If the Principled BSDF is not available in your version of Blender it will simply be omitted.

Code availability

The latest version of the code (201706251223) is available on GitHub (right click and select save as ... , then in Blender File -> user preferences ... -> Add-ons -> Install from file .... Don't forget to remove the previously installed version first!)

A short video demo:

Previous articles

Previous articles about the Nodeset add-on:
NODESET: IMPORT SUBSTANCE PAINTER TEXTURES INTO BLENDER
NODESET: TINY UPDATE MIGHT SAVE EVEN SOME MORE TIME
NODESET: SUPPORT FOR AMBIENT OCCLUSION MAPS
NODESET: MORE FLEXIBILITY

Substance Painter experiment



Inspired by a real life flower pot in our garden but weathered quite a lot more:


Sale: Blender Market turns 3


There is something to celebrate: Friday June 9 Blender Market turns 3.
To celebrate, many products will carry a 25% discount that day up til Sunday 11 (applied at checkout, and remember they are on Chicago time), including all products is my shop :-)