MaterialX icon indicating copy to clipboard operation
MaterialX copied to clipboard

Color-space awareness in thin-film iridescence and blackbody emission

Open jstone-lucasfilm opened this issue 7 months ago • 3 comments

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.

jstone-lucasfilm avatar Apr 09 '26 18:04 jstone-lucasfilm

Hi, I would like to work on this.

My understanding is that the intended change is to add a Matrix33 field named xyzToWorkingSpace to GenOptions, defaulting to the CIE XYZ -> lin_rec709 transform; expose it as a private uniform in generated hardware shaders; and replace the hardcoded XYZ_TO_RGB matrices in mx_microfacet_specular.glsl and mx_blackbody.glsl with that uniform.

I will begin with the GLSL/ESSL path described in the issue. If you would prefer the same option to be wired through the MSL/WGSL backends where applicable as part of the initial PR, please let me know.

r800360 avatar Jul 13 '26 21:07 r800360

Welcome, @r800360, and reach out if you have any questions about this!

jstone-lucasfilm avatar Jul 13 '26 22:07 jstone-lucasfilm

Thank you @jstone-lucasfilm. I have opened #3005 implementing the XYZ-to-working-space transform.

The PR adds the GenOptions field and private hardware-shader uniform, updates both blackbody emission and thin-film iridescence, and includes focused shader-generation coverage for the default and overridden transforms. The full MaterialXTest suite passes.

Let me know if you would like me to make any changes or additions. I would appreciate any feedback as this is my first time contributing to the project.

r800360 avatar Jul 14 '26 02:07 r800360