Automated optimization of shading model graphs
Two recent PRs to MaterialX demonstrated that shading model graphs can be significantly optimized, especially in the context of real-time and interactive rendering, by applying a set of visually invariant refactor steps:
- https://github.com/AcademySoftwareFoundation/MaterialX/pull/2459 (OpenPBR Surface)
- https://github.com/AcademySoftwareFoundation/MaterialX/pull/2467 (glTF PBR)
It would be ideal if we could implement this category of graph optimization automatically, e.g. at the level of our shader code generation, allowing all shading models to benefit without manual analysis or modification of their graphs being required.
So far, our most successful shading model graph optimizations have been based on the following two observations:
- Because BSDF
mixandlayernodes are linear operations, they can be reordered as long as the author is careful to preserve the exact visual meaning of the graph. - A
mixof two leaf BSDF nodes can be refactored as anaddof two pre-multiplied BSDF nodes, as long as the author is careful to preserve the exact visual meaning of the graph.
In combination, these two observations can be used to make a shading model graph more amenable to common renderer optimizations that skip the computations associated with a BSDF node when its weight is less than epsilon.
This GitHub Issue is a call for interested developers to propose and implement an automated solution that applies this category of optimizations to shading model graphs.
This project would likely require a non-trivial research and development effort, but the benefits to the community could be enormous, speeding up virtually all shading models that the industry renders in the context of MaterialX or USD.