Skip to content

Commit a6d5348

Browse files
Optimizations to Standard Surface graph (AcademySoftwareFoundation#2483)
This changelist implements optimizations to the graph for Standard Surface, replacing `mix` operations on leaf BSDFs with pre-multiplied `add` operations. Pre-multiplied `add` operations take better advantage of dynamic branching in hardware shading languages, and should have a neutral or positive impact on software shading languages. Performance tests were conducted on an NVIDIA RTX A6000 at 4K resolution, and the following timing improvements were seen: Standard Surface Marble: 3ms -> 1ms Standard Surface Carpaint: 3ms -> 1ms Standard Surface Glass: 5ms -> 3ms Standard Surface Plastic: 2ms -> 1ms Standard Surface Brushed Metal: 2ms -> 1ms Standard Surface Chess Set: 9ms -> 4ms
1 parent 0e12b19 commit a6d5348

1 file changed

Lines changed: 40 additions & 22 deletions

File tree

libraries/bxdf/standard_surface.mtlx

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226
<input name="normal" type="vector3" interfacename="normal" />
227227
</oren_nayar_diffuse_bsdf>
228228
<translucent_bsdf name="translucent_bsdf" type="BSDF">
229-
<input name="weight" type="float" value="1.0" />
229+
<input name="weight" type="float" interfacename="subsurface" />
230230
<input name="color" type="color3" nodename="coat_affected_subsurface_color" />
231231
<input name="normal" type="vector3" interfacename="normal" />
232232
</translucent_bsdf>
@@ -235,7 +235,7 @@
235235
<input name="in2" type="float" interfacename="subsurface_scale" />
236236
</multiply>
237237
<subsurface_bsdf name="subsurface_bsdf" type="BSDF">
238-
<input name="weight" type="float" value="1.0" />
238+
<input name="weight" type="float" interfacename="subsurface" />
239239
<input name="color" type="color3" nodename="coat_affected_subsurface_color" />
240240
<input name="radius" type="color3" nodename="subsurface_radius_scaled" />
241241
<input name="anisotropy" type="float" interfacename="subsurface_anisotropy" />
@@ -249,11 +249,17 @@
249249
<input name="bg" type="BSDF" nodename="subsurface_bsdf" />
250250
<input name="mix" type="float" nodename="subsurface_selector" />
251251
</mix>
252-
<mix name="subsurface_mix" type="BSDF">
253-
<input name="fg" type="BSDF" nodename="selected_subsurface_bsdf" />
254-
<input name="bg" type="BSDF" nodename="diffuse_bsdf" />
255-
<input name="mix" type="float" interfacename="subsurface" />
256-
</mix>
252+
<invert name="subsurface_inv" type="float">
253+
<input name="in" type="float" interfacename="subsurface" />
254+
</invert>
255+
<multiply name="diffuse_bsdf_non_subsurface" type="BSDF">
256+
<input name="in1" type="BSDF" nodename="diffuse_bsdf" />
257+
<input name="in2" type="float" nodename="subsurface_inv" />
258+
</multiply>
259+
<add name="subsurface_blend" type="BSDF">
260+
<input name="in1" type="BSDF" nodename="selected_subsurface_bsdf" />
261+
<input name="in2" type="BSDF" nodename="diffuse_bsdf_non_subsurface" />
262+
</add>
257263

258264
<!-- Sheen Layer -->
259265
<sheen_bsdf name="sheen_bsdf" type="BSDF">
@@ -264,12 +270,12 @@
264270
</sheen_bsdf>
265271
<layer name="sheen_layer" type="BSDF">
266272
<input name="top" type="BSDF" nodename="sheen_bsdf" />
267-
<input name="base" type="BSDF" nodename="subsurface_mix" />
273+
<input name="base" type="BSDF" nodename="subsurface_blend" />
268274
</layer>
269275

270276
<!-- Transmission Layer -->
271277
<dielectric_bsdf name="transmission_bsdf" type="BSDF">
272-
<input name="weight" type="float" value="1.0" />
278+
<input name="weight" type="float" interfacename="transmission" />
273279
<input name="tint" type="color3" interfacename="transmission_color" />
274280
<input name="ior" type="float" interfacename="specular_IOR" />
275281
<input name="roughness" type="vector2" nodename="transmission_roughness" />
@@ -278,11 +284,17 @@
278284
<input name="distribution" type="string" value="ggx" />
279285
<input name="scatter_mode" type="string" value="T" />
280286
</dielectric_bsdf>
281-
<mix name="transmission_mix" type="BSDF">
282-
<input name="fg" type="BSDF" nodename="transmission_bsdf" />
283-
<input name="bg" type="BSDF" nodename="sheen_layer" />
284-
<input name="mix" type="float" interfacename="transmission" />
285-
</mix>
287+
<invert name="transmission_inv" type="float">
288+
<input name="in" type="float" interfacename="transmission" />
289+
</invert>
290+
<multiply name="sheen_layer_non_transmission" type="BSDF">
291+
<input name="in1" type="BSDF" nodename="sheen_layer" />
292+
<input name="in2" type="float" nodename="transmission_inv" />
293+
</multiply>
294+
<add name="transmission_blend" type="BSDF">
295+
<input name="in1" type="BSDF" nodename="transmission_bsdf" />
296+
<input name="in2" type="BSDF" nodename="sheen_layer_non_transmission" />
297+
</add>
286298

287299
<!-- Specular Layer -->
288300
<dielectric_bsdf name="specular_bsdf" type="BSDF">
@@ -299,7 +311,7 @@
299311
</dielectric_bsdf>
300312
<layer name="specular_layer" type="BSDF">
301313
<input name="top" type="BSDF" nodename="specular_bsdf" />
302-
<input name="base" type="BSDF" nodename="transmission_mix" />
314+
<input name="base" type="BSDF" nodename="transmission_blend" />
303315
</layer>
304316

305317
<!-- Metal Layer -->
@@ -316,7 +328,7 @@
316328
<input name="edge_color" type="color3" nodename="metal_edgecolor" />
317329
</artistic_ior>
318330
<conductor_bsdf name="metal_bsdf" type="BSDF">
319-
<input name="weight" type="float" value="1.0" />
331+
<input name="weight" type="float" interfacename="metalness" />
320332
<input name="ior" type="color3" nodename="artistic_ior" output="ior" />
321333
<input name="extinction" type="color3" nodename="artistic_ior" output="extinction" />
322334
<input name="roughness" type="vector2" nodename="main_roughness" />
@@ -326,11 +338,17 @@
326338
<input name="thinfilm_thickness" type="float" interfacename="thin_film_thickness" />
327339
<input name="thinfilm_ior" type="float" interfacename="thin_film_IOR" />
328340
</conductor_bsdf>
329-
<mix name="metalness_mix" type="BSDF">
330-
<input name="fg" type="BSDF" nodename="metal_bsdf" />
331-
<input name="bg" type="BSDF" nodename="specular_layer" />
332-
<input name="mix" type="float" interfacename="metalness" />
333-
</mix>
341+
<invert name="metalness_inv" type="float">
342+
<input name="in" type="float" interfacename="metalness" />
343+
</invert>
344+
<multiply name="specular_layer_non_metal" type="BSDF">
345+
<input name="in1" type="BSDF" nodename="specular_layer" />
346+
<input name="in2" type="float" nodename="metalness_inv" />
347+
</multiply>
348+
<add name="metalness_blend" type="BSDF">
349+
<input name="in1" type="BSDF" nodename="metal_bsdf" />
350+
<input name="in2" type="BSDF" nodename="specular_layer_non_metal" />
351+
</add>
334352

335353
<!-- Coat Layer -->
336354
<mix name="coat_attenuation" type="color3">
@@ -339,7 +357,7 @@
339357
<input name="mix" type="float" interfacename="coat" />
340358
</mix>
341359
<multiply name="thin_film_layer_attenuated" type="BSDF">
342-
<input name="in1" type="BSDF" nodename="metalness_mix" />
360+
<input name="in1" type="BSDF" nodename="metalness_blend" />
343361
<input name="in2" type="color3" nodename="coat_attenuation" />
344362
</multiply>
345363
<roughness_anisotropy name="coat_roughness_vector" type="vector2">

0 commit comments

Comments
 (0)