blender/tests/python
Michael B Johnson f913fb6159 USD: Add MaterialX shader export
This change adds the ability to export MaterialX networks into the resulting
USD layer.

Details:

A new export option has been added to the USD export to enable MaterialX
export. It is off by default currently due to reasons in the caveats
section.

When enabled, it exports the MaterialX shading network alongside the
UsdPreviewSurface network, on the same USD Material. This allows the same
material to be used by renderers that don't support MaterialX, using the
USDPreviewSurface as a fallback. This is similar to setups in other DCC
packages, and matches the format we've used in our Reality Composer Pro
asset library.

It uses the existing MaterialX framework used to generate MaterialX
documents for rendering, to act as the basis for the USD graph. In this
process it also re-uses the existing texture export code as well if provided
and necessary.

Once the MaterialX document is created, use usdMtlx to generate a USD
shading network. Unfortunately, usdMtlx generates a graph that is unlike
what other DCCs that support MaterialX-embedded-in-USD generates. It
generates several extra prim hierarchies, and externalizes all shader
inputs, making them difficult to edit in other MaterialX graph editors.

To workaround this, generate the MaterialX shading network onto a
temporary stage, where we then run various pre-processing steps to prevent
prim collisions and to reflow the paths once they're converted.

The PrimSpecs are then copied over to their new path. The resulting prim
hierarchy matches what many artists we've worked with prefer to work with.

Caveats:

The Export MaterialX check is off by default. When using the Principled
BSDF, the resulting graph is very usable. However, when using some of the
other BSDFs, the shading networks generated by the existing MaterialX
framework in Blender generate some shading graphs that are difficult for
usdview and other DCC's to understand. The graph is still correct, but
because we're trying to prioritize compatibility, the default is off.

In future PRs we can aim to make the graphs for those other BSDFs play
better with other DCCs.

Other Implementation Details:

As part of this commit we've also done the following:

* Place some of the materialx graphs inside a passthrough nodegraph to
  avoid node conflicts.
* Better handle some shader output types , and better handle some
  conflict cases.
* Moved the ExportTextureFunction to materials.h due to some difficult
  to resolve header ordering issues. This has no effect on any runtime code.
* There is a test for the MaterialX export that does some basic checking to
  make sure we get an export out the other end that matches our expectations

Authored by Apple: Dhruv Govil

This PR is based on an earlier implementation by Brecht van Lommel , as well
as Brian Savery and his teams' work at AMD to implement the general
MaterialX framework within Blender.

Pull Request: https://projects.blender.org/blender/blender/pulls/122575
2024-06-05 20:43:44 +02:00
..
collada Cleanup: remove redundant string formatting 2024-04-12 10:04:07 +10:00
modules Cleanup: remove unused variables 2024-03-21 10:11:54 +11:00
ui_simulate UI: fix and improve a few messages 2024-02-05 17:08:17 +01:00
view_layer Merge branch 'blender-v4.1-release' 2024-02-22 16:52:32 +01:00
alembic_export_tests.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
batch_import.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
bevel_operator.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
bl_alembic_io_test.py Merge branch 'blender-v4.1-release' into main 2024-02-22 14:36:13 +01:00
bl_animation_action.py Anim: add RNA guards to prevent mixing legacy/layered action operations 2024-05-30 13:19:21 +02:00
bl_animation_armature.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00
bl_animation_drivers.py Merge branch 'blender-v4.1-release' into main 2024-02-22 14:36:13 +01:00
bl_animation_fcurves.py Anim: add keytype argument to keyframe_insert() RNA function 2024-04-15 11:36:38 +02:00
bl_animation_keyframing.py Anim: Add unit tests for keying custom properties 2024-04-23 09:36:38 +02:00
bl_animation_nla_strip.py Anim: Add regression tests for NLA strip evaluation 2023-11-20 17:52:28 +01:00
bl_blendfile_io.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00
bl_blendfile_liblink.py Merge branch 'blender-v4.1-release' 2024-03-06 11:16:00 +01:00
bl_blendfile_library_overrides.py LibOverride: Cleanup unused&missing data after resync. 2024-02-27 16:43:31 +01:00
bl_blendfile_utils.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
bl_blendfile_versioning.py Cleanup: Formatting 2024-05-10 17:58:56 +02:00
bl_bundled_modules.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
bl_constraints.py Merge branch 'blender-v4.1-release' into main 2024-02-22 14:36:13 +01:00
bl_id_management.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00
bl_imbuf_load.py Render Tests: Separate difference of Color and Alpha 2024-01-25 10:04:16 +01:00
bl_imbuf_save.py Render Tests: Separate difference of Color and Alpha 2024-01-25 10:04:16 +01:00
bl_io_curve_svg_test.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00
bl_keymap_completeness.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
bl_keymap_validate.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00
bl_load_addons.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00
bl_load_py_modules.py Cleanup: restore error, exclude extensions tests from bl_load_py_modules 2024-05-16 16:02:25 +10:00
bl_mesh_modifiers.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
bl_mesh_validate.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
bl_node_field_type_inference.py Cleanup: unused imports 2024-04-19 16:09:30 +10:00
bl_node_group_compat.py Fix #116477: Node group sockets with subtypes have broken idnames 2024-01-16 15:32:33 +01:00
bl_node_group_interface.py Fix #118769: Remove parent parameter from new_panel function 2024-02-27 13:30:13 +01:00
bl_pyapi_bpy_driver_secure_eval.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00
bl_pyapi_bpy_path.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00
bl_pyapi_bpy_utils_units.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00
bl_pyapi_idprop_datablock.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00
bl_pyapi_idprop.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00
bl_pyapi_mathutils.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00
bl_pyapi_prop_array.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00
bl_pyapi_text.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00
bl_rigging_symmetrize.py Merge branch 'blender-v4.1-release' into main 2024-02-22 14:36:13 +01:00
bl_rna_defaults.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00
bl_rna_manual_reference.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00
bl_rst_completeness.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00
bl_test.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
bl_usd_export_test.py USD: Add MaterialX shader export 2024-06-05 20:43:44 +02:00
bl_usd_import_test.py Fix #122606: fully map Blender's INT8 type to USD's UChar 2024-06-02 22:26:12 +02:00
boolean_operator.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
CMakeLists.txt EEVEE: Remove EEVEE-Legacy 2024-06-04 14:17:58 +02:00
compositor_cpu_render_tests.py Compositor: Explicitly set device in test scripts 2024-05-14 19:03:55 +03:00
compositor_realtime_render_tests.py Compositor: Explicitly set device in test scripts 2024-05-14 19:03:55 +03:00
curve_to_mesh.py Fix: Update tests data path to new directory 2024-02-22 14:25:54 +01:00
curves_extrude.py Fix: Curves extrude with all points selected 2024-01-16 21:59:15 +01:00
cycles_render_tests.py Merge branch 'blender-v4.1-release' 2024-03-07 20:16:51 +01:00
deform_modifiers.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
eevee_next_render_tests.py EEVEE-Next: Light Probe RNA 2024-06-04 15:05:22 +02:00
ffmpeg_tests.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
geo_node_sim_test.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
geo_node_test.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
gpu_info.py Fix: GPU test errors importing gpu module 2024-03-26 20:16:02 +01:00
modifiers.py Tests: Add modifier tests for shrinkwrap target normal project 2024-03-29 10:11:22 -04:00
opengl_draw_tests.py Render Tests: Separate difference of Color and Alpha 2024-01-25 10:04:16 +01:00
operators.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
pep8.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
physics_cloth.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
physics_dynamic_paint.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
physics_ocean.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
physics_particle_instance.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
physics_particle_system.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
physics_softbody.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
rna_array.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
rna_info_dump.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00
rst_to_doctree_mini.py License Headers: Set copyright to "Blender Authors", add AUTHORS 2023-08-16 00:20:26 +10:00
sequencer_render_tests.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00
storm_render_tests.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00
workbench_render_tests.py Revert changes from main commits that were merged into blender-v4.1-release 2024-02-19 15:59:59 +01:00