Commit Graph

15 Commits

Author SHA1 Message Date
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
Jesse Yurkovich
05f8d35652 Fix #122606: fully map Blender's INT8 type to USD's UChar
While USD does not have a signed, 8-bit, integer type we can use its
UChar type instead.

Pull Request: https://projects.blender.org/blender/blender/pulls/122610
2024-06-02 22:26:12 +02:00
Charles Wardlaw
e1a6749b3d USD: dome light IO
This commit adds logic to convert between USD dome lights and Blender
world materials.

The USD dome light rotation is represented in a mapping node input to the
environment texture.  If the dome light has a color specified in addition to
the texture map, the color will be converted to a vector multiply on the
the environment texture output.

I the imported USD has multiple dome lights, only the first dome light will
be converted to a world material.

Co-authored-by: kiki <charles@skeletalstudios.com>
Co-authored-by: Michael Kowalski <makowalski@nvidia.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/121800
2024-05-30 20:48:43 +02:00
Jesse Yurkovich
9daded5d87 USD: Use nodes for alpha-clip behavior instead of material properties
EEVEE-next has removed the MA_BM_CLIP / alpha_threshold material
properties in favor of using nodes for equivalent functionality. This
changes USD to build and traverse node graphs during import and export
accordingly. Indirectly this allows Cycles to correctly render such
materials now too.

A complicating factor is that the UsdPreviewSurface defines its opacity
threshold using greater-than-equals[1], which Blender does not support
(and for which was technically already incorrect as EEVEE-legacy only
used greater-than for its shaders). Due to this we actually need to use
2 nodes: A less-than, followed by a one-minus invert, to arrive at the
proper value. We'll translate UsdPreviewSurface to this form on Import.

For Export we will look for either this 2-node pattern or a Round
node plugged into Alpha. Looking for Round is a result of the glTF
documentation which recommended the use of this node for thresholds of
0.5[2]. It's a tiny addition that seems reasonable to accommodate.

[1] https://openusd.org/release/spec_usdpreviewsurface.html (search for "opacityThreshold")
[2] https://docs.blender.org/manual/en/4.2/addons/import_export/scene_gltf2.html#alpha-modes

See PR for example images

Pull Request: https://projects.blender.org/blender/blender/pulls/122025
2024-05-25 23:30:13 +02:00
Jesse Yurkovich
21db0daa4e USD: Read and write custom attributes for Curves
Add support for reading and writing custom `Curves` attributes.

This allows us to roundtrip Blender's Hair grooms containing UVs and
other attribute data. Note that animated attribute values are not
supported with this change.

This will also address #120042

Pull Request: https://projects.blender.org/blender/blender/pulls/121928
2024-05-25 22:23:40 +02:00
Jesse Yurkovich
7dae89d276 USD: Add test to cover import of mesh attributes
Adds a test to validate the import of Mesh attributes for USD.

It reuses the recently added export attribute test file to generate the
USD file to load.

The test validates the current behavior in `main`. Missing data and bugs
are noted in comments and can be addressed afterwards.

Pull Request: https://projects.blender.org/blender/blender/pulls/121327
2024-05-02 03:57:25 +02:00
Jesse Yurkovich
16a29a7a75 USD: Add test to cover export of mesh attributes
Adds a test to validate the export of Mesh attributes for USD.

It tests that all domains and types for a Mesh object are written to the
USD file correctly.

Pull Request: https://projects.blender.org/blender/blender/pulls/121180
2024-04-28 03:53:20 +02:00
Michael B Johnson
b262655d39 USD: export to a single root prim by default
This PR adds the following changes:

A single root is always set as default. After talking to Wave and
Spiff, we settled on root being the best default. Users who don't
want a single root prim inserted, can choose to clear the field
The root prim no longer requires the user to prefix the field with /.
It will implicitly insert that for them.

On export, the root_prim hierarchy is now defined all as Xform
instead of just the final prim in the path. Each prim also has
custom metadata added to show that it was generated by Blender.
This follows convention in other DCCs as well.

On import, the code now finds the hierarchy of generated prims
using that metadata. It then skips importing them. This means that
you can roundtrip hierarchies even with an inserted root.

Co-authored-by: Dhruv Govil <dgovil2@apple.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/113187
2023-10-20 10:58:40 -04:00
Campbell Barton
e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00
Campbell Barton
89811cb96f Cleanup: unused-imports in tests/ 2023-07-25 21:43:53 +10:00
Campbell Barton
65f99397ec License headers: use SPDX-FileCopyrightText in all sources 2023-06-15 13:35:34 +10:00
Campbell Barton
6a5ab77dcc Cleanup: format 2023-05-02 08:41:10 +10:00
Michael B Johnson
3c74575dac Fix #107062: support opacityThreshold when exporting USD
This PR addresses issue “USD export does not respect opacity threshold for clip alpha blend mode #107062”

This commit extends the USD Preview Surface material support to author the opacityThreshold attribute of materials on export, when the Alpha Clip blend mode is selected.

When authoring alpha cutouts in Blender, one sets the Blend Mode to "Alpha Clip", and the Clip Threshold to some value greater than zero.
When this case is detected on export, we now author the opacityThreshold attribute to match the specified clip threshold.

Note that opacityThreshold is already handled correctly on import, so this change allows the feature to be fully round-tripped.

Co-authored-by: Matt McLin <mmclin@apple.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/107149
2023-05-01 17:28:23 +02:00
Hans Goudey
d465b92823 Cleanup: Make format, fix missing static warning 2023-02-15 17:39:53 -05:00
Michael B Johnson
5040c39d1a Fix T103354: Author extents on UsdGeomMesh
A properly authored USD file will have the extent attribute authored on all prims conforming to UsdGeomBoundable.
This cached extent information is useful because it allows the 3D range of prims to be quickly understood without reading potentially large arrays of data. Note that because the shape of prims may change over time, extent attributes are always evaluated for a given timecode.

This patch introduces support for authoring extents on meshes and volumes during export to USD.

Because extents are common to multiple kinds of geometries, the main support for authoring extents has been placed in USDAbstractWriter, whose new author_extent method can operate on any prim conforming to pxr::UsdGeomBoundable. The USD library already provides us the code necessary to compute the bounds for a given prim, in pxr::UsdGeomBBoxCache::ComputeLocalBound.
Note that not all prims that are imageable are boundable, such as transforms and cameras.

For more details on extents, see https://graphics.pixar.com/usd/release/api/class_usd_geom_boundable.html#details.

Note that when new types of geometries are introduced, such as curves in https://developer.blender.org/D16545, we will need to update the USD writer for that geometry such that it calls this->author_extent.

Update on Feb 2: This patch has been updated to include a unit test to ensure authored extents are valid. This test requires new test assets that will need to be submitted via svn. The test assets are attached in the d16837_usd_test_assets.zip file. To use, unzip and merge the contents of this zip into the lib/tests/usd folder.

This unit test also addresses #104269 by validating compliance of exported USD via UsdUtils.ComplianceChecker.

Pull Request #104676
2023-02-14 12:11:53 +01:00