Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
337 lines (303 loc) · 21 KB
/
Copy pathindex.html
File metadata and controls
337 lines (303 loc) · 21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Authors: Bernard Kwok and Matthew Kwok. Root site for MaterialX
related resources, libraries and tools. This includes interaction with
related Open Standards: OpenUSD, Khronos glTF, and OpenColorIO.">
<!-- Google tag (gtag.js)
<script async src="https://www.googletagmanager.com/gtag/js?id=G-J7404418VP"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-J7404418VP');
</script>
-->
<style>
model-viewer {
width: 256px;
height: 256px;
background-color: #7d7d7d;
}
.custom-gradient {
background: repeating-radial-gradient(circle, hsl(204, 100%, 8%), #290027 100%); }
.custom-gradient2 {
background: repeating-radial-gradient(circle, hsl(204, 94%, 20%), #96018f 100%); }
.clickable-image {
transition: transform 0.3s;
}
.clickable-image:hover {
transform: scale(1.10);
cursor: pointer;
border: rgb(206, 175, 0) solid 1px;
}
</style>
<!-- <link rel="icon" href="./documents/images/logo3d_icon.png" type="image/x-icon" /> -->
<!--
<link rel="icon" href="./documents/images/logo3d_2_small.png" type="image/x-icon" />
-->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.1.0/css/brands.min.css">
<link rel="stylesheet" href="https://unpkg.com/bs-brain@2.0.4/components/blogs/blog-3/assets/css/blog-3.css">
<link rel="stylesheet" href="./documents/css/style.css">
<link rel="icon" type="images" href="./documents/images/toon_sphere.png" type="image/x-icon" class="img-fluid">
</head>
<body>
<!-- <script src="https://cdn.jsdelivr.net/npm/mermaid@9/dist/mermaid.min.js"></script> -->
<!-- <script src="./documents/js/ui_helpers.js"></script> -->
<!-- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/js/bootstrap.bundle.min.js"></script> -->
<!-- Navigation_Area-->
<nav class="navbar sticky-top navbar-expand-lg bg-dark-subtle" data-bs-theme="dark">
<div class="container-md container-fluid">
<a class="navbar-brand" href="https://kwokcb.github.io/MaterialXLab/">
<h5 class=""><img src="././documents/icons/MX_LAB.svg" alt="MaterialXLab"
class="d-inline-block align-text-center" width="96px"></h5>
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#mainMenuContent"
aria-controls="mainMenuContent" aria-expanded="false" aria-label="Toggle top menu">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="mainMenuContent">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item dropdown">
<a class="nav-link" href="./index.html" role="button">
Home
</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" role="button" data-bs-toggle="dropdown"
aria-expanded="false">Documentation</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="./documents/html/index.html">API Documentation</a></li>
<li><a class="dropdown-item" href="./tests/unit_test_gallery.html">Unit Test Results</a></li>
<li><a class="dropdown-item" href="./tests/usd_mtlx_image_gallery.html">USD RTS Results</a></li>
<li><a class="dropdown-item" href="./tests/usd_physically_based_gallery.html">PhysicallyBased Test Results</a></li>
<li><a class="dropdown-item" href="./tests/glsl_vs_glslfx.html">MaterialX glsl vs USD glslfx</a></li>
<li><a class="dropdown-item" href="./tests/glsl_vs_osl_glslfx.html">GLSL vs OSL vs USD glslfx</a></li>
</ul>
</li>
<!--INDEX_ITEM-->
</ul>
</div>
</div>
</nav>
<!-- Section Information -->
<section class="py-0 px-0 g-0">
<div class="container-fluid p-4">
<h2>MaterialX USD Utilities</h2>
<p><a href="https://github.com/kwokcb/materialxusd/actions">
<img src="https://github.com/kwokcb/materialxusd/actions/workflows/static.yml/badge.svg" alt="GitHub Actions Status">
</a></p>
<p>This is a Github <a href="https://github.com/kwokcb/materialxusd">repository</a> of utilities related to MaterialX and USD.
- The web site can be found <a href="https://kwokcb.github.io/materialxusd/">here</a>
- The <code>PyPi</code> package can be found <a href="https://pypi.org/project/materialxusd/" target="_blank">here</a>.
- The utilities and results currently use the <code>25.05</code> version of OpenUSD which is sync'ed to MaterialX version <code>1.39.3</code>. </p>
<p>This can be hooked into the larger interoperability picture with glTF / MaterialX and USD as shown in the example below:</p>
<p><img src="https://kwokcb.github.io/materialxusd/documents/results/usd_gltf_mtlx_desk_web.png" width=100%></p>
<blockquote>
<p>Figure: MaterialX material from <a href="https://matlib.gpuopen.com/main/materials/all?search=TH%20Cath&material=6e933741-eeb3-4956-b756-0b44f08aa6cf"> AMD GPUOpen library</a>. Converted to USD and displayed in <code>usdview</code> (top left), converted to glTF and display in ThreeJS editor (top right). Display in MaterialX Viewer (bottom left), and Web editor (bottom right)</p>
</blockquote>
<h3>Available Components</h3>
<ul>
<li><code>mtlxdownload.py</code> : Utility to download releases or source folders (such as libraries, or resources) from MaterialX.</li>
<li>
<p><code>mtlx2usd.py</code> : Utility which takes a MaterialX document and creates a corresponding USD document with scene geometry, lights, and camera. </p>
<p>The main intent is currently to be able to consume documents from the MaterialX render test suite but any MaterialX file can be used as input.</p>
</li>
<li>
<p>Options Include:</p>
<ul>
<li>Preprocess the MaterialX file to
attempt to produce valid USD shading network (See Support Utilities)</li>
<li>Input geometry (USD file)</li>
<li>Input camera (USD file)</li>
<li>Skydome light (A latlong HDR file)</li>
<li>Perform USD validation</li>
<li>Export just the materials to a USD file.</li>
<li>Render the corresponding USD file. This uses <code>usdrecord</code> currently. Render arguments can be passed in to specify the render delegate to use for instance. The default is GL. </li>
<li>Misc options for output for test
suite compatibility:<ul>
<li>Use material name for file name</li>
<li>Create in subfolder with name being the input MaterialX name</li>
</ul>
</li>
</ul>
</li>
<li>
<p>Preprocessing Utilities:</p>
<ul>
<li><code>preprocess_mtlx.py</code> : Tries to preprocess a MaterialX document so that it considered valid by USD. Currently this includes logic to:<ul>
<li>Encapsulate <strong>top level nodes</strong> in a MaterialX document into a nodegraph but preserve connections. Only
materials and shading model nodes are valid at the top level in USD. </li>
<li>Resolve any <strong>implicit geometry stream bindings</strong> on <code>inputs</code> and make them explicit by adding geometric stream nodes and binding them to any inputs with implicit bindings. Note that this requires loading in the standard library to get node definitions.</li>
<li>Add a <strong>material node per surface shader</strong> which is not connected to any downstream material. USD only examines materials and not shaders so these shaders are skipped during conversion. </li>
<li>Extract out any surface shaders inside a nodegraph to be outside the graph as this is considered invalid by USD.</li>
<li>If a surface shader input is connected to a nodegraph, add in an <strong>explicit <code>output</code> qualifier</strong>. Seems <code>out</code> is assumed to be the name of the output when there is no explicit qualifier which can be incorrect.</li>
<li><strong>"Flatten" (resolve) all image asset references</strong> using the existing MaterialX utilities for path resolve. This is needed as the MaterialX render tests have assumed search paths which are not explicitly defined -- thus requiring the paths to be passed in as part of preprocessing.<ul>
<li>There is probably a better way to do this using USD asset resolvers, but have not tried. ( Input is welcome on this. )</li>
</ul>
</li>
<li>Remove any <code>value</code> attributes on <code>input</code>s with connections to avoid ambiguity and MaterialX validation errors.</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3>Issues</h3>
<p>Issue logging is being tracked under these "master" issues:
- <a href="https://github.com/AcademySoftwareFoundation/MaterialX/issues/2291">MaterialX</a>
- <a href="https://github.com/PixarAnimationStudios/OpenUSD/issues/3571">OpenUSD</a></p>
<details><summary>Notes</summary>
- Color space and Real World Units:
- Color space meta-data appears to work properly as do explicit color space conversion nodes.
- **Real world unit meta-data is lost during conversion**. Unknown if this is unsupportable or a known issue.
- There appears to be no way to convert shading graphs which have a roots surface shaders which are not the current
shading models: glTF, USDPreviewSurface, OpenPBR ? That is arbitrary PBR shaders. They may translate but are considered invalid root nodes. **It is unclear / undocumented as to what are "valid" root pbr nodes for USD.**
- **Nodes graphs with child nodes that are the same name as the parent graph**, and which are connected will be interpreted improperly by USD as it attempts to connect the incorrect upstream path and returns an error on conversion from MaterialX to USD. These tests have been manually modified for nowt to rename the interior node. This appears to be a USD logic error.
- **Validation is inconsistent between USD and MaterialX for upstream output connections**. If the upstream node / nodegraph has 1 connection then a validation warning is issues if you explicit specify that output. If you do not
specify the output then conversion to USD will skip this link. *It would be useful to remove this inconsistent validation check in MaterialX.*
- `usdMtlx` always tries to add in a `NodeGraphs` scope but this does not necessary contain graphs but nodes which can get confusing. Additionally downstrem port connects are incorrect as the first node's output seems to always be used.
- In generate `usdMtlx` seems to set up incorrect upstream connections for multiple output (`multioutput`) nodes and nodegraphs, assuming to take the first output and assuming the name `out` as opposed to taking the first (compatible) output which is done in MaterialX. **Connection failures result in aborting conversion completely** (instead of converting but leaving out certain connections)
- For rendering HDStorm and the default (GLSL/ OSL / MDL) MaterialX renderers use different sampling logic for environment lighting. e.g. Anisotropy differs.
- For render results: The rendering setup for translucent / transparent shading does not show the environment when it is set to be hidden. There is probably a way to make this show up while hiding the background. **Input is welcome on this**.
</details>
<h2>Usage</h2>
<h3>Installation and Usage</h3>
<p>Install from the root folder:</p>
<div class="codehilite"><pre><span></span><code>pip install .
</code></pre></div>
<p>or install from <code>PyPi</code></p>
<div class="codehilite"><pre><span></span><code>pip install materialxusd
</code></pre></div>
<p>Run using the <code>materialxusd</code> command.
Currently there are two commands for:
- MaterialX to USD conversion which can be run using</p>
<div class="codehilite"><pre><span></span><code>materialxusd m2u
</code></pre></div>
<p>and preprocessing MaterialX documents which can be run using</p>
<div class="codehilite"><pre><span></span><code>materialxusd pmtlx
</code></pre></div>
<p>The <code>tests</code> folder has a script with some command line calls to process an examples subfolder (<code>run_examples.sh</code>) </p>
<div class="codehilite"><pre><span></span><code>echo Convert sample MaterialX files to USD and render
materialxusd m2u -pp -v -sf -mn ./examples/no_materials.mtlx
materialxusd m2u -pp -v -f -sf -mn -r -m ./examples/standard_surface_carpaint.sphere.mtlx
materialxusd m2u -pp -v -sf -mn -r -m ./examples/standard_surface_marble_solid.mtlx
materialxusd m2u -pp -v -sf -mn -r -m ./examples/linepattern.mtlx
echo Preprocess and convert sample MaterialX files to USD
materialxusd pmtlx ./examples/linepattern_orig.mtlx
materialxusd m2u -pp -v -sf -mn -r -m ./examples/linepattern_orig_converted.mtlx
echo Convert ZIP file
materialxusd m2u -pp -v -sf -mn -r -m ./examples/TH_Cathedral_Floor_Tiles_1k_8b_JRHrQHt.zip
</code></pre></div>
<p>Some rendering of resulting USD files are shown below:</p>
<hr />
<table>
<thead>
<tr>
<th style="text-align: center;">Material</th>
<th style="text-align: center;">Pre-processing Required</th>
<th style="text-align: center;">USD Rendering</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">Line Pattern</td>
<td style="text-align: center;">Generate Materials for outputs on NodeGraph</td>
<td style="text-align: center;"><img src="https://raw.githubusercontent.com/kwokcb/materialxusd/refs/heads/main/tests/examples/linepattern/test_crosshatch_glslfx.png" width="128px"></img></td>
</tr>
<tr>
<td style="text-align: center;">Marble</td>
<td style="text-align: center;">Add downstream material + explicit stream bindings</td>
<td style="text-align: center;"><img src="https://raw.githubusercontent.com/kwokcb/materialxusd/refs/heads/main/tests/examples/standard_surface_marble_solid/Marble_3D_glslfx.png" width="128px"></img></td>
</tr>
<tr>
<td style="text-align: center;">Car Paint</td>
<td style="text-align: center;">Add downstream material</td>
<td style="text-align: center;"><img width="128px" src="https://raw.githubusercontent.com/kwokcb/materialxusd/refs/heads/main/tests/examples/standard_surface_carpaint.sphere/Car_Paint_glslfx.png"></img></td>
</tr>
<tr>
<td style="text-align: center;">AMD GPUOpen Wood (Zip)</td>
<td style="text-align: center;">Unzip and resolve asset paths</td>
<td style="text-align: center;"><img width="128px" src="https://raw.githubusercontent.com/kwokcb/materialxusd/refs/heads/main/tests/examples/TH_Cathedral_Floor_Tiles_1k_8b_JRHrQHt/TH_Cathedral_Floor_Tiles/TH_Cathedral_Floor_Tiles_glslfx.png"/></td>
</tr>
<tr>
<td style="text-align: center;">Adobe pattern</td>
<td style="text-align: center;">Wrap top level nodes, create explicit output port connections</td>
<td style="text-align: center;"><img width="128px" src="https://raw.githubusercontent.com/kwokcb/materialxusd/refs/heads/main/tests/examples/parquet_clothes/parquet_clothes/surfacematerial_glslfx.png"/></td>
</tr>
</tbody>
</table>
<hr />
<p>There is additionally a sample script that will traverse a local copy of the MaterialX test suite (<code>render_rts.sh</code>). The script calls the package's Python commands directly.</p>
<div class="codehilite"><pre><span></span><code><span class="nv">folders</span><span class="o">=(</span>
<span class="w"> </span><span class="s2">"./resources/Materials/Examples"</span>
<span class="w"> </span><span class="s2">"./resources/Materials/TestSuite/stdlib/convolution"</span>
<span class="w"> </span><span class="s2">"./resources/Materials/TestSuite/stdlib/color_management"</span>
<span class="w"> </span><span class="s2">"./resources/Materials/TestSuite/stdlib/procedural"</span>
<span class="w"> </span><span class="s2">"./resources/Materials/TestSuite/pbrlib/surfaceshader"</span>
<span class="w"> </span><span class="s2">"./resources/Materials/TestSuite/nprlib"</span>
<span class="o">)</span>
<span class="k">for</span><span class="w"> </span>folder<span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="s2">"</span><span class="si">${</span><span class="nv">folders</span><span class="p">[@]</span><span class="si">}</span><span class="s2">"</span><span class="p">;</span><span class="w"> </span><span class="k">do</span>
<span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">"Rendering </span><span class="nv">$folder</span><span class="s2">"</span>
<span class="w"> </span>python<span class="w"> </span>../source/materialxusd/mtlx2usd.py<span class="w"> </span>-pp<span class="w"> </span>-mn<span class="w"> </span>-sf<span class="w"> </span><span class="s2">"</span><span class="nv">$folder</span><span class="s2">"</span><span class="w"> </span>-r<span class="w"> </span>-g<span class="w"> </span>./data/sphere.usd<span class="w"> </span>-c<span class="w"> </span>./data/camera_sphere.usda<span class="w"> </span>-e<span class="w"> </span>./data/san_giuseppe_bridge.hdr
<span class="k">done</span>
</code></pre></div>
<h3>Documentation</h3>
<p>An overview MaterialX->USD presentation can be found <a href="https://kwokcb.github.io/materialxusd/documents/results/MaterialX_USD_WG_Presentation_March_12_2025.pdf"><img src="https://kwokcb.github.io/materialxusd/documents/results/MaterialX_USD_WG_Presentation_March_12_2025.png" width=100%>here</a></p>
<p>Python API documentation can be found <a href="https://kwokcb.github.io/materialxusd/documents/html/index.html">here</a></p>
<h2>Acceptance</h2>
<p>An initial acceptance criteria is to be able to run MaterialX to USD conversion against the MaterialX render test suite files. Preliminary results are show below:</p>
<h3>Gallery of Example Materials</h3>
<h4>Render Test Suite material Renderings</h4>
<p><a href="https://kwokcb.github.io/materialxusd/tests/usd_mtlx_image_gallery.html" target="_blank">
<img src="https://kwokcb.github.io/materialxusd/documents/images/rts_gallery.png" width=100% alt="USD RTS image gallery">
</a></p>
<h4>Unit Test Renderings</h4>
<p><a href="https://kwokcb.github.io/materialxusd/tests/unit_test_gallery.html" target="_blank" target="_blank">
<img src="https://kwokcb.github.io/materialxusd/documents/images/unit_test_gallery.png" width=100% alt="Unit test image gallery">
</a></p>
<h4><a href="https://physicallybased.info/" target="_blank">Physically Based Material Library</a> Renderings</h4>
<p><a href="https://kwokcb.github.io/materialxusd//tests/usd_physically_based_gallery.html" target="_blank">
<img src="https://kwokcb.github.io/materialxusd/documents/images/physicallyBased_gallery.png" width=100% alt="USD RTS image gallery">
</a></p>
<h3>Comparison: GLSL vs GLSLFX</h3>
<p><a href="https://kwokcb.github.io/materialxusd/tests/glsl_vs_glslfx.html" target="_blank">
<img src="https://kwokcb.github.io/materialxusd/documents/images/glsl_vs_glsfx.png" width=100% alt="GLSL vs GLSLFx image comparison">
</a></p>
<h3>Comparison: GLSL vs OSL vs GLSLFX</h3>
<p><a href="https://kwokcb.github.io/materialxusd/tests/glsl_vs_osl_glslfx.html" target="_blank">
<img src="https://kwokcb.github.io/materialxusd/documents/images/glsl_vs_glsfx_vs_osl.png" width=100% alt="GLSL vs GLSLFx image comparison">
</a></p>
<h2>Design</h2>
<p>An overview of the current package design is shown below. Boxes / lines which are dotted are optional logic which may be executed as desired.</p>
<p><img src="https://kwokcb.github.io/materialxusd/documents/images/design.png" width=100%></p>
</div>
</section>
<script>
document.body.setAttribute('data-bs-theme', 'dark');
</script>
<footer class="bg-dark-subtle footer text-white py-2 pt-2" data-bs-theme="dark">
<div class="container">
<ul class="social-icons">
<button class="btn btn-outline" type="button">
<a href="https://github.com/kwokcb/materialxusd" target="_blank"><b class="fa-brands fa-github fa-2x"
style="color: #ffffff;"></b></a>
</button>
<button class="btn btn-outline " type="button">
<a href="https://www.linkedin.com/in/bernard-kwok/" target="_blank"><b class="fa-brands fa-linkedin-in fa-2x"
style="color: #0082ca;"></b></a>
</button>
</ul>
<p>
<a class="bg-dark p-2 right" rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">
<img alt="Creative Commons License" style="border-width:0"
src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a>
<a href="https://kwokcb.github.io/nanmuconsulting/" target="_blank">
© 2022-2025 NanMu Consulting.</a>
</p>
</div>
</footer>
</body>
</html>