-
Notifications
You must be signed in to change notification settings - Fork 26
MaterialX in WebGPU #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: adsk/feature/wasm
Are you sure you want to change the base?
MaterialX in WebGPU #24
Conversation
Update minimum cmake version as 4.0+ requires at least 3.5 as minimum version. See https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html#command:cmake_minimum_required
copy pxr/usdImaging/bin/usdviewweb/ to pxr/extras/usd/web so can iterate and enhance a version that is javascript friendly without impacting the original.
Simplifying CMakeLists.txt and renaming files, tailoring to usdweb
…hardcode model. Expose USD viewport functions to javascript * init viewport * set stage * fit camera * remove Knife.usda, instead use generated usd stage as default
* WrapJs for VariantSet and VariantSets * Wrap additional functions in UsdPrim for variants. * Update usdweb.html with sample use.
* Add action buttons:
* hide/show prims
* material variants
* fitCamera
* single-action load CFB variants stage file (dependent file loads)
Switch from Camera to FreeCameraGL FreeCameraGL is a C++ class ported from the python Usdview FreeCamera in freeCamera.py. The behavior for camera manip is much improved and now better aligns with the camera manipulation in usdview. TODO: remove camera.h and camera.cpp
wrap UsdGeomCamera, mostly just stubbed out.
* Support Z-Up for camera stages * Move around functions (setupDefaults, getStageBBox, fit_camera) * encapsulate param setup when loading new stage with initParamsForWebStage()
* Add contrib.glfw3 CMake option: EMSCRIPTEN_USE_CONTRIB_GLFW3 * Clean up headers in usdweb * Add logging notes for debugging NOTE: contrib.glfw3 still has errors, so more work needed.
* Add code comments * WIP for EMSCRIPTEN_USE_CONTRIB_GLFW3 * Remove unneeded fit_camera() since already initialized elsewhere.
A fix was added to the experimental MaterialX 1.39.x branch that addresses the issue preventing more advanced MaterialX shaders like procedural brick from being displayed properly. README.md docs updated to reflect this fix.
The WGSL pull request landed in the main branch of MaterialX today and slated for the full 1.39.4 release. Update the README.md and build_usd.py to use the main branch as of that pull request.
Streamline the code and remove the need for additional tokenSubstitutions from MaterialX.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds WebGPU and MaterialX support across USD's JavaScript bindings, shader generation, and a new browser-based USD Web Viewer.
- Introduces new Emscripten wrappers for UsdUtils and various USD, UsdShade, and UsdGeom APIs
- Extends HdSt MaterialX shader generator with a new templated base, WGSL support, and version‐based branching
- Adds a complete WebGPU‐based web application (
usdweb.html+usdweb.cpp) with UI, camera controls, and asset loading
Reviewed Changes
Copilot reviewed 59 out of 68 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pxr/usd/usdUtils/wrapDependenciesJs.cpp | New Emscripten wrapper for UsdUtilsExtractExternalReferences |
| pxr/imaging/hdSt/materialXShaderGen.h / materialXShaderGen.cpp | Refactored MaterialX shader generator with WGSL support |
| extras/usd/web/usdweb.html / usdweb.cpp | New WebGPU viewer HTML and Emscripten C++ entry points |
Comments suppressed due to low confidence (4)
extras/usd/web/freeCameraGL.h:6
- [nitpick] Duplicate inclusion of
<pxr/base/gf/matrix4d.h>. You can remove one of the two identical includes to reduce redundancy.
// compliance with the Apache License and the following modification to it:
pxr/usd/usdUtils/wrapDependenciesJs.cpp:32
- Consider adding unit tests for
wrap_UsdUtilsExtractExternalReferencesto verify the combined list of external references is returned correctly for various USD files.
std::vector<std::string> wrap_UsdUtilsExtractExternalReferences(const std::string &filePath)
extras/usd/web/usdweb.html:26
- The CSS property
translateis not valid. Usetransform: translate(-50px, -50px);instead to correctly center the spinner.
translate: -50px -50px;
extras/usd/web/usdweb.html:11
- The CSS
paddingproperty does not acceptnone. Usepadding: 0;for no padding.
padding: none;
| //#define WGSL_MATERIALX_138_SHADERCODE_HACK | ||
| #ifdef WGSL_MATERIALX_138_SHADERCODE_HACK | ||
| #include <regex> // HACK [sbrew] for LightData.type -> LightData.lightType |
Copilot
AI
Jul 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This large hack block guarded by WGSL_MATERIALX_138_SHADERCODE_HACK is difficult to maintain. Consider controlling it via a MaterialX version check or feature flag and document its intended removal.
| //#define WGSL_MATERIALX_138_SHADERCODE_HACK | |
| #ifdef WGSL_MATERIALX_138_SHADERCODE_HACK | |
| #include <regex> // HACK [sbrew] for LightData.type -> LightData.lightType | |
| // Feature flag to enable the MaterialX 1.3.8 shader code workaround. | |
| #define ENABLE_MATERIALX_138_WORKAROUND 1 | |
| #if ENABLE_MATERIALX_138_WORKAROUND | |
| #include <regex> // Workaround for LightData.type -> LightData.lightType in MaterialX 1.3.8 | |
| // TODO: Remove this workaround once MaterialX 1.3.9 or later is adopted. |
Adding documentation for useful functions in usdweb.html.
Description of Change(s)
Link to proposal (if applicable)
Fixes Issue(s)
Checklist
I have created this PR based on the dev branch
I have followed the coding conventions
I have added unit tests that exercise this functionality (Reference:
testing guidelines)
I have verified that all unit tests pass with the proposed changes
I have submitted a signed Contributor License Agreement (Reference:
Contributor License Agreement instructions)