As @mnikelsky pointed out in a recent thread on the ASWF Slack, the XYZ_TO_RGB matrix in our GLSL thin-film codebase is taken directly from the original Belcour paper, but this matrix transforms colors to CIE 1931 RGB space, which is not one of the linear rendering spaces supported by MaterialX or commonly used in film and game rendering.
The XYZ_TO_RGB matrix in our GLSL implementation of blackbody emission is slightly closer to the mark, transforming to the common lin_rec709 space, but this matrix is still hardcoded and incapable of adapting to the linear working spaces of different rendering environments.
To address both of these issues, we could add a new shader generation option named xyzToWorkingSpace, representing the matrix33 that transforms from CIE XYZ to the working color space of the renderer.
By default this option would store the transform from CIE XYZ to lin_rec709, but the renderer would have the ability to set another matrix when needed, and because MaterialX shader generators already have access to the working color space, they could store the correct matrix automatically.
We would then swap in this uniform matrix for both of the hardcoded matrices in the GLSL implementations of thin-film iridescence and the blackbody emission node, allowing them to support arbitrary working color spaces in a simple, efficient way.
As @mnikelsky pointed out in a recent thread on the ASWF Slack, the XYZ_TO_RGB matrix in our GLSL thin-film codebase is taken directly from the original Belcour paper, but this matrix transforms colors to CIE 1931 RGB space, which is not one of the linear rendering spaces supported by MaterialX or commonly used in film and game rendering.
The XYZ_TO_RGB matrix in our GLSL implementation of blackbody emission is slightly closer to the mark, transforming to the common
lin_rec709space, but this matrix is still hardcoded and incapable of adapting to the linear working spaces of different rendering environments.To address both of these issues, we could add a new shader generation option named
xyzToWorkingSpace, representing the matrix33 that transforms from CIE XYZ to the working color space of the renderer.By default this option would store the transform from CIE XYZ to
lin_rec709, but the renderer would have the ability to set another matrix when needed, and because MaterialX shader generators already have access to the working color space, they could store the correct matrix automatically.We would then swap in this uniform matrix for both of the hardcoded matrices in the GLSL implementations of thin-film iridescence and the blackbody emission node, allowing them to support arbitrary working color spaces in a simple, efficient way.