From 6211e9a669c9bc93ccabf833ee4c50bd0e6720e0 Mon Sep 17 00:00:00 2001 From: krohmerNV <42233792+krohmerNV@users.noreply.github.com> Date: Wed, 12 Jul 2023 18:24:52 +0200 Subject: [PATCH 1/7] Fix volume mixes in MDL (#1395) Change the implementation of the volume mix functions in MDL. The mix weight is now interpreted as probability to encounter a particle of one of the mixed media. --- .../MaterialXGenMdl/mdl/materialx/pbrlib.mdl | 79 +++++++++++++------ .../MaterialXGenMdl/mdl/materialx/stdlib.mdl | 4 +- 2 files changed, 58 insertions(+), 25 deletions(-) diff --git a/source/MaterialXGenMdl/mdl/materialx/pbrlib.mdl b/source/MaterialXGenMdl/mdl/materialx/pbrlib.mdl index 9c166f7468..61234c4037 100644 --- a/source/MaterialXGenMdl/mdl/materialx/pbrlib.mdl +++ b/source/MaterialXGenMdl/mdl/materialx/pbrlib.mdl @@ -669,6 +669,27 @@ export material mx_displacement_vector3( ); +// helper function to mix two scattering volumes: +// - combined scattering coefficient is just the sum of the two +// - VDF mixer weight is the relative probability of encountering the corresponding +// particle type +// NOTE: mixer weight should be a color, but due to a bug in current MDL compilers +// the color mixers don't accept non-uniform weights yet +struct volume_mix_return { + color scattering_coefficient; + float mix_weight1; // mix_weight2 = 1.0 - mix_weight1, can use any mixer +}; +volume_mix_return volume_mix( + color scattering_coefficient1, + float weight1, + color scattering_coefficient2, + float weight2) +{ + color s1 = weight1 * scattering_coefficient1; + color s = s1 + weight2 * scattering_coefficient2; + return volume_mix_return(scattering_coefficient: s, mix_weight1: math::average(s1 / s)); +} + export material mx_mix_bsdf( material mxp_fg = material() [[ anno::usage( "materialx:bsdf") ]], material mxp_bg = material() [[ anno::usage( "materialx:bsdf") ]], @@ -676,7 +697,11 @@ export material mx_mix_bsdf( ) [[ anno::usage( "materialx:bsdf") ]] -= material( += let { + volume_mix_return v = volume_mix( + mxp_fg.volume.scattering_coefficient, mxp_mix, + mxp_bg.volume.scattering_coefficient, (1.0f - mxp_mix)); +} in material( surface: material_surface( scattering: df::weighted_layer( weight: mxp_mix, @@ -687,15 +712,14 @@ export material mx_mix_bsdf( // we need to carry volume properties along for SSS ior: mxp_fg.ior, // NOTE: IOR is uniform, cannot mix here volume: material_volume( - scattering: df::clamped_mix( + scattering: df::unbounded_mix( df::vdf_component[]( - df::vdf_component( mxp_mix, mxp_fg.volume.scattering), - df::vdf_component( 1.0 - mxp_mix, mxp_bg.volume.scattering)) + df::vdf_component(v.mix_weight1, mxp_fg.volume.scattering), + df::vdf_component(1.0 - v.mix_weight1, mxp_bg.volume.scattering)) ), absorption_coefficient: mxp_mix * mxp_fg.volume.absorption_coefficient + (1.0 - mxp_mix) * mxp_bg.volume.absorption_coefficient, - scattering_coefficient: mxp_mix * mxp_fg.volume.scattering_coefficient + - (1.0 - mxp_mix) * mxp_bg.volume.scattering_coefficient + scattering_coefficient: v.scattering_coefficient ) ); @@ -709,7 +733,7 @@ export material mx_mix_edf( = material( surface: material_surface( emission: material_emission( - emission: df::clamped_mix( + emission: df::unbounded_mix( // unbounded_mix is cheaper df::edf_component[]( df::edf_component( mxp_mix, mxp_fg.surface.emission.emission), df::edf_component( 1.0 - mxp_mix, mxp_bg.surface.emission.emission)) @@ -727,18 +751,21 @@ export material mx_mix_vdf( ) [[ anno::usage( "materialx:vdf") ]] -= material( += let { + volume_mix_return v = volume_mix( + mxp_fg.volume.scattering_coefficient, mxp_mix, + mxp_bg.volume.scattering_coefficient, (1.0f - mxp_mix)); +} in material( ior: mxp_fg.ior, // NOTE: IOR is uniform, cannot mix here volume: material_volume( - scattering: df::clamped_mix( + scattering: df::unbounded_mix( df::vdf_component[]( - df::vdf_component( mxp_mix, mxp_fg.volume.scattering), - df::vdf_component( 1.0 - mxp_mix, mxp_bg.volume.scattering)) + df::vdf_component( v.mix_weight1, mxp_fg.volume.scattering), + df::vdf_component( 1.0 - v.mix_weight1, mxp_bg.volume.scattering)) ), absorption_coefficient: mxp_mix * mxp_fg.volume.absorption_coefficient + (1.0 - mxp_mix) * mxp_bg.volume.absorption_coefficient, - scattering_coefficient: mxp_mix * mxp_fg.volume.scattering_coefficient + - (1.0 - mxp_mix) * mxp_bg.volume.scattering_coefficient + scattering_coefficient: v.scattering_coefficient ) ); @@ -751,7 +778,11 @@ export material mx_add_bsdf( ) [[ anno::usage( "materialx:bsdf") ]] -= material( += let { + volume_mix_return v = volume_mix( + mxp_in1.volume.scattering_coefficient, 1.0f, + mxp_in2.volume.scattering_coefficient, 1.0f); +} in material( surface: material_surface( scattering: df::unbounded_mix( df::bsdf_component[]( @@ -764,13 +795,12 @@ export material mx_add_bsdf( volume: material_volume( scattering: df::unbounded_mix( df::vdf_component[]( - df::vdf_component( 1.0, mxp_in1.volume.scattering), - df::vdf_component( 1.0, mxp_in2.volume.scattering)) + df::vdf_component( v.mix_weight1, mxp_in1.volume.scattering), + df::vdf_component( 1.0 - v.mix_weight1, mxp_in2.volume.scattering)) ), absorption_coefficient: mxp_in1.volume.absorption_coefficient + mxp_in2.volume.absorption_coefficient, - scattering_coefficient: mxp_in1.volume.scattering_coefficient + - mxp_in2.volume.scattering_coefficient + scattering_coefficient: v.scattering_coefficient ) ); @@ -806,19 +836,22 @@ export material mx_add_vdf( ) [[ anno::usage( "materialx:vdf") ]] -= material( += let { + volume_mix_return v = volume_mix( + mxp_in1.volume.scattering_coefficient, 1.0f, + mxp_in2.volume.scattering_coefficient, 1.0f); +} in material( // assuming mixing the IOR is the best we can do here ior: 0.5 * mxp_in1.ior + 0.5 * mxp_in2.ior, volume: material_volume( scattering: df::unbounded_mix( df::vdf_component[]( - df::vdf_component( 1.0, mxp_in1.volume.scattering), - df::vdf_component( 1.0, mxp_in2.volume.scattering)) + df::vdf_component( v.mix_weight1, mxp_in1.volume.scattering), + df::vdf_component( 1.0 - v.mix_weight1, mxp_in2.volume.scattering)) ), absorption_coefficient: mxp_in1.volume.absorption_coefficient + mxp_in2.volume.absorption_coefficient, - scattering_coefficient: mxp_in1.volume.scattering_coefficient + - mxp_in2.volume.scattering_coefficient + scattering_coefficient: v.scattering_coefficient ) ); diff --git a/source/MaterialXGenMdl/mdl/materialx/stdlib.mdl b/source/MaterialXGenMdl/mdl/materialx/stdlib.mdl index 2cb313221c..bce4a44ea5 100644 --- a/source/MaterialXGenMdl/mdl/materialx/stdlib.mdl +++ b/source/MaterialXGenMdl/mdl/materialx/stdlib.mdl @@ -2981,7 +2981,7 @@ export material mx_mix_surfaceshader( base: mxp_bg.surface.scattering ), emission: material_emission( - emission: df::clamped_mix( + emission: df::unbounded_mix( // unbounded_mix is cheaper df::edf_component[]( df::edf_component( mxp_mix, mxp_fg.surface.emission.emission), df::edf_component( 1.0 - mxp_mix, mxp_bg.surface.emission.emission)) @@ -2994,7 +2994,7 @@ export material mx_mix_surfaceshader( // we need to carry volume properties along for SSS ior: mxp_fg.ior, // NOTE: IOR is uniform, cannot mix here volume: material_volume( - scattering: df::clamped_mix( + scattering: df::unbounded_mix( // unbounded_mix is cheaper df::vdf_component[]( df::vdf_component( mxp_mix, mxp_fg.volume.scattering), df::vdf_component( 1.0 - mxp_mix, mxp_bg.volume.scattering)) From 2c0c7ea713b72de0d1c8e926b835240325344972 Mon Sep 17 00:00:00 2001 From: Mostafa Azab <31315913+Cinifreak@users.noreply.github.com> Date: Wed, 12 Jul 2023 20:23:29 +0300 Subject: [PATCH 2/7] Add triangle wave node (#1334) This node generates values from zero to one based on the input value. --- libraries/stdlib/stdlib_defs.mtlx | 10 ++++++++++ libraries/stdlib/stdlib_ng.mtlx | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/libraries/stdlib/stdlib_defs.mtlx b/libraries/stdlib/stdlib_defs.mtlx index e3b4344ff2..bc1240e574 100644 --- a/libraries/stdlib/stdlib_defs.mtlx +++ b/libraries/stdlib/stdlib_defs.mtlx @@ -2546,6 +2546,16 @@ + + + + + + diff --git a/libraries/stdlib/stdlib_ng.mtlx b/libraries/stdlib/stdlib_ng.mtlx index 31c5eea740..f40001e14d 100644 --- a/libraries/stdlib/stdlib_ng.mtlx +++ b/libraries/stdlib/stdlib_ng.mtlx @@ -1540,6 +1540,32 @@ + + + + + + + + + + + + + + + + + + + + + + From 3e838e2f4b4bcc434bd0e99f0e382c8d475b322a Mon Sep 17 00:00:00 2001 From: nicolassavva-autodesk <61437351+nicolassavva-autodesk@users.noreply.github.com> Date: Wed, 12 Jul 2023 10:26:22 -0700 Subject: [PATCH 3/7] Add blackbody PBR node implementations (#1367) Address the missing targets for the PBR blackbody node implementation using the following approximation: Wikipedia: Planckian Locus Approximation Add a simple unlit surface material example using the above blackbody node for emission. Reenable blackbody node tests. --- libraries/pbrlib/genglsl/mx_blackbody.glsl | 48 +++++++++++++++++++ .../pbrlib/genglsl/pbrlib_genglsl_impl.mtlx | 3 ++ .../pbrlib/genmsl/pbrlib_genmsl_impl.mtlx | 3 ++ libraries/pbrlib/genosl/mx_blackbody.osl | 48 +++++++++++++++++++ .../pbrlib/genosl/pbrlib_genosl_impl.legacy | 3 ++ .../pbrlib/genosl/pbrlib_genosl_impl.mtlx | 3 ++ .../TestSuite/pbrlib/bsdf/blackbody.mtlx | 16 +++++++ .../MaterialXGenGlsl/GenGlsl.cpp | 2 +- .../MaterialXTest/MaterialXGenMdl/GenMdl.cpp | 2 +- .../MaterialXTest/MaterialXGenMsl/GenMsl.cpp | 2 +- .../MaterialXTest/MaterialXGenOsl/GenOsl.cpp | 2 +- .../MaterialXGenShader/GenShaderUtil.cpp | 1 - source/MaterialXView/Editor.cpp | 2 +- 13 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 libraries/pbrlib/genglsl/mx_blackbody.glsl create mode 100644 libraries/pbrlib/genosl/mx_blackbody.osl create mode 100644 resources/Materials/TestSuite/pbrlib/bsdf/blackbody.mtlx diff --git a/libraries/pbrlib/genglsl/mx_blackbody.glsl b/libraries/pbrlib/genglsl/mx_blackbody.glsl new file mode 100644 index 0000000000..55d5c87541 --- /dev/null +++ b/libraries/pbrlib/genglsl/mx_blackbody.glsl @@ -0,0 +1,48 @@ +/// XYZ to Rec.709 RGB colorspace conversion +const mat3 XYZ_to_RGB = mat3( 3.2406, -0.9689, 0.0557, + -1.5372, 1.8758, -0.2040, + -0.4986, 0.0415, 1.0570); + +void mx_blackbody(float temperatureKelvin, out vec3 colorValue) +{ + float xc, yc; + float t, t2, t3, xc2, xc3; + + // if value outside valid range of approximation clamp to accepted temperature range + temperatureKelvin = clamp(temperatureKelvin, 1667.0, 25000.0); + + t = 1000.0 / temperatureKelvin; + t2 = t * t; + t3 = t * t * t; + + // Cubic spline approximation for Kelvin temperature to sRGB conversion + // (https://en.wikipedia.org/wiki/Planckian_locus#Approximation) + if (temperatureKelvin < 4000.0) { // 1667K <= temperatureKelvin < 4000K + xc = -0.2661239 * t3 - 0.2343580 * t2 + 0.8776956 * t + 0.179910; + } + else { // 4000K <= temperatureKelvin <= 25000K + xc = -3.0258469 * t3 + 2.1070379 * t2 + 0.2226347 * t + 0.240390; + } + xc2 = xc * xc; + xc3 = xc * xc * xc; + + if (temperatureKelvin < 2222.0) { // 1667K <= temperatureKelvin < 2222K + yc = -1.1063814 * xc3 - 1.34811020 * xc2 + 2.18555832 * xc - 0.20219683; + } + else if (temperatureKelvin < 4000.0) { // 2222K <= temperatureKelvin < 4000K + yc = -0.9549476 * xc3 - 1.37418593 * xc2 + 2.09137015 * xc - 0.16748867; + } + else { // 4000K <= temperatureKelvin <= 25000K + yc = 3.0817580 * xc3 - 5.87338670 * xc2 + 3.75112997 * xc - 0.37001483; + } + + if (yc <= 0.0) { // avoid division by zero + colorValue = vec3(1.0); + return; + } + + vec3 XYZ = vec3(xc / yc, 1.0, (1.0 - xc - yc) / yc); + + colorValue = XYZ_to_RGB * XYZ; + colorValue = max(colorValue, vec3(0.0)); +} diff --git a/libraries/pbrlib/genglsl/pbrlib_genglsl_impl.mtlx b/libraries/pbrlib/genglsl/pbrlib_genglsl_impl.mtlx index b94f513d82..fa4617375f 100644 --- a/libraries/pbrlib/genglsl/pbrlib_genglsl_impl.mtlx +++ b/libraries/pbrlib/genglsl/pbrlib_genglsl_impl.mtlx @@ -74,4 +74,7 @@ + + + diff --git a/libraries/pbrlib/genmsl/pbrlib_genmsl_impl.mtlx b/libraries/pbrlib/genmsl/pbrlib_genmsl_impl.mtlx index 1900f1e824..8d1d2a4729 100644 --- a/libraries/pbrlib/genmsl/pbrlib_genmsl_impl.mtlx +++ b/libraries/pbrlib/genmsl/pbrlib_genmsl_impl.mtlx @@ -71,4 +71,7 @@ + + + diff --git a/libraries/pbrlib/genosl/mx_blackbody.osl b/libraries/pbrlib/genosl/mx_blackbody.osl new file mode 100644 index 0000000000..8b4de5ba9f --- /dev/null +++ b/libraries/pbrlib/genosl/mx_blackbody.osl @@ -0,0 +1,48 @@ +void mx_blackbody(float temperature, output color color_value) +{ + float xc, yc; + float t, t2, t3, xc2, xc3; + + // if value outside valid range of approximation clamp to accepted temperature range + temperature = clamp(temperature, 1667.0, 25000.0); + + t = 1000.0 / temperature; + t2 = t * t; + t3 = t * t * t; + + // Cubic spline approximation for Kelvin temperature to sRGB conversion + // (https://en.wikipedia.org/wiki/Planckian_locus#Approximation) + if (temperature < 4000.0) { // 1667K <= temperature < 4000K + xc = -0.2661239 * t3 - 0.2343580 * t2 + 0.8776956 * t + 0.179910; + } + else { // 4000K <= temperature <= 25000K + xc = -3.0258469 * t3 + 2.1070379 * t2 + 0.2226347 * t + 0.240390; + } + xc2 = xc * xc; + xc3 = xc * xc * xc; + + if (temperature < 2222.0) { // 1667K <= temperature < 2222K + yc = -1.1063814 * xc3 - 1.34811020 * xc2 + 2.18555832 * xc - 0.20219683; + } + else if (temperature < 4000.0) { // 2222K <= temperature < 4000K + yc = -0.9549476 * xc3 - 1.37418593 * xc2 + 2.09137015 * xc - 0.16748867; + } + else { // 4000K <= temperature <= 25000K + yc = 3.0817580 * xc3 - 5.87338670 * xc2 + 3.75112997 * xc - 0.37001483; + } + + if (yc <= 0.0) { // avoid division by zero + color_value = color(1.0); + return; + } + + vector XYZ = vector(xc / yc, 1.0, (1 - xc - yc) / yc); + + /// XYZ to Rec.709 RGB colorspace conversion + matrix XYZ_to_RGB = matrix( 3.2406, -0.9689, 0.0557, + -1.5372, 1.8758, -0.2040, + -0.4986, 0.0415, 1.0570); + + color_value = transform(XYZ_to_RGB, XYZ); + color_value = max(color_value, vector(0.0)); +} diff --git a/libraries/pbrlib/genosl/pbrlib_genosl_impl.legacy b/libraries/pbrlib/genosl/pbrlib_genosl_impl.legacy index d7ccf80906..6ab7cc9e61 100644 --- a/libraries/pbrlib/genosl/pbrlib_genosl_impl.legacy +++ b/libraries/pbrlib/genosl/pbrlib_genosl_impl.legacy @@ -71,4 +71,7 @@ + + + diff --git a/libraries/pbrlib/genosl/pbrlib_genosl_impl.mtlx b/libraries/pbrlib/genosl/pbrlib_genosl_impl.mtlx index b37dc79fcd..7a38f0fb12 100644 --- a/libraries/pbrlib/genosl/pbrlib_genosl_impl.mtlx +++ b/libraries/pbrlib/genosl/pbrlib_genosl_impl.mtlx @@ -71,4 +71,7 @@ + + + diff --git a/resources/Materials/TestSuite/pbrlib/bsdf/blackbody.mtlx b/resources/Materials/TestSuite/pbrlib/bsdf/blackbody.mtlx new file mode 100644 index 0000000000..f2d9b193f3 --- /dev/null +++ b/resources/Materials/TestSuite/pbrlib/bsdf/blackbody.mtlx @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/source/MaterialXTest/MaterialXGenGlsl/GenGlsl.cpp b/source/MaterialXTest/MaterialXGenGlsl/GenGlsl.cpp index 54b6fbf420..339d3853cb 100644 --- a/source/MaterialXTest/MaterialXGenGlsl/GenGlsl.cpp +++ b/source/MaterialXTest/MaterialXGenGlsl/GenGlsl.cpp @@ -85,7 +85,7 @@ TEST_CASE("GenShader: GLSL Implementation Check", "[genglsl]") mx::StringSet generatorSkipNodeTypes; mx::StringSet generatorSkipNodeDefs; - GenShaderUtil::checkImplementations(context, generatorSkipNodeTypes, generatorSkipNodeDefs, 48); + GenShaderUtil::checkImplementations(context, generatorSkipNodeTypes, generatorSkipNodeDefs, 47); } TEST_CASE("GenShader: GLSL Unique Names", "[genglsl]") diff --git a/source/MaterialXTest/MaterialXGenMdl/GenMdl.cpp b/source/MaterialXTest/MaterialXGenMdl/GenMdl.cpp index e565071caa..1a3e127cde 100644 --- a/source/MaterialXTest/MaterialXGenMdl/GenMdl.cpp +++ b/source/MaterialXTest/MaterialXGenMdl/GenMdl.cpp @@ -93,7 +93,7 @@ TEST_CASE("GenShader: MDL Implementation Check", "[genmdl]") generatorSkipNodeTypes.insert("light"); mx::StringSet generatorSkipNodeDefs; - GenShaderUtil::checkImplementations(context, generatorSkipNodeTypes, generatorSkipNodeDefs, 49); + GenShaderUtil::checkImplementations(context, generatorSkipNodeTypes, generatorSkipNodeDefs, 48); } diff --git a/source/MaterialXTest/MaterialXGenMsl/GenMsl.cpp b/source/MaterialXTest/MaterialXGenMsl/GenMsl.cpp index e3bcc7cfa1..03dbcbde69 100644 --- a/source/MaterialXTest/MaterialXGenMsl/GenMsl.cpp +++ b/source/MaterialXTest/MaterialXGenMsl/GenMsl.cpp @@ -84,7 +84,7 @@ TEST_CASE("GenShader: MSL Implementation Check", "[genmsl]") mx::StringSet generatorSkipNodeTypes; mx::StringSet generatorSkipNodeDefs; - GenShaderUtil::checkImplementations(context, generatorSkipNodeTypes, generatorSkipNodeDefs, 48); + GenShaderUtil::checkImplementations(context, generatorSkipNodeTypes, generatorSkipNodeDefs, 47); } TEST_CASE("GenShader: MSL Unique Names", "[genmsl]") diff --git a/source/MaterialXTest/MaterialXGenOsl/GenOsl.cpp b/source/MaterialXTest/MaterialXGenOsl/GenOsl.cpp index 9d3fa78db4..13a8b5ffdf 100644 --- a/source/MaterialXTest/MaterialXGenOsl/GenOsl.cpp +++ b/source/MaterialXTest/MaterialXGenOsl/GenOsl.cpp @@ -89,7 +89,7 @@ TEST_CASE("GenShader: OSL Implementation Check", "[genosl]") generatorSkipNodeTypes.insert("light"); mx::StringSet generatorSkipNodeDefs; - GenShaderUtil::checkImplementations(context, generatorSkipNodeTypes, generatorSkipNodeDefs, 49); + GenShaderUtil::checkImplementations(context, generatorSkipNodeTypes, generatorSkipNodeDefs, 48); } TEST_CASE("GenShader: OSL Unique Names", "[genosl]") diff --git a/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp b/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp index 75b69ff93b..863cd1af05 100644 --- a/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp +++ b/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp @@ -94,7 +94,6 @@ void checkImplementations(mx::GenContext& context, "arrayappend", "displacement", "volume", - "blackbody", "curveadjust", "conical_edf", "measured_edf", diff --git a/source/MaterialXView/Editor.cpp b/source/MaterialXView/Editor.cpp index a4c6d3f675..ff91f0f129 100644 --- a/source/MaterialXView/Editor.cpp +++ b/source/MaterialXView/Editor.cpp @@ -701,7 +701,7 @@ ng::FloatBox* createFloatWidget(ng::Widget* parent, const std::string& la if (ui) { - std::pair range(0.0f, 0.0f); + std::pair range(0.0f, 1.0f); if (ui->uiMin) { box->set_min_value(ui->uiMin->asA()); From 4a55b91de352cd58c0d070434b4d4260d4388ae4 Mon Sep 17 00:00:00 2001 From: Brian Sharpe Date: Fri, 14 Jul 2023 05:15:42 +1200 Subject: [PATCH 4/7] Remove modulo from randomfloat graph (#1407) It did not achieve its intention of allowing for more consistent behavior over large ranges, giving no benefit over that of a simple scale. The scale value of 4096 has been chosen arbitrarily. Perhaps we could expose it as an input someday. --- libraries/stdlib/stdlib_ng.mtlx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/libraries/stdlib/stdlib_ng.mtlx b/libraries/stdlib/stdlib_ng.mtlx index f40001e14d..ab1332e79d 100644 --- a/libraries/stdlib/stdlib_ng.mtlx +++ b/libraries/stdlib/stdlib_ng.mtlx @@ -1246,13 +1246,9 @@ - - - - - - + + From 0e69033aa90e5c4212df9a07e7ac93e584cafd87 Mon Sep 17 00:00:00 2001 From: Karen Lucknavalai <34335343+klucknav@users.noreply.github.com> Date: Fri, 14 Jul 2023 16:06:42 -0700 Subject: [PATCH 5/7] Add missing cctype include for VS2017 (#1412) - std::isspace requires include of cctype in VS2017 --- source/MaterialXGenMsl/MslShaderGenerator.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/MaterialXGenMsl/MslShaderGenerator.cpp b/source/MaterialXGenMsl/MslShaderGenerator.cpp index 61a1c8f572..dcb0a3ed69 100644 --- a/source/MaterialXGenMsl/MslShaderGenerator.cpp +++ b/source/MaterialXGenMsl/MslShaderGenerator.cpp @@ -43,6 +43,8 @@ #include "MslResourceBindingContext.h" +#include + MATERIALX_NAMESPACE_BEGIN const string MslShaderGenerator::TARGET = "genmsl"; From 333ac964158c584ef80d2eb5cf6526230cdc9cea Mon Sep 17 00:00:00 2001 From: Jonathan Stone Date: Fri, 21 Jul 2023 15:08:10 -0700 Subject: [PATCH 6/7] Update three.js to r140 This changelist updates the version of three.js to r140 in the MaterialX Web Viewer, making a handful of adjustments to account for changes in environment texture conventions. --- javascript/MaterialXView/package-lock.json | 50 +++++++++++----------- javascript/MaterialXView/package.json | 2 +- javascript/MaterialXView/source/helper.js | 2 - javascript/MaterialXView/source/viewer.js | 2 +- 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/javascript/MaterialXView/package-lock.json b/javascript/MaterialXView/package-lock.json index 84d65f8589..f22bb7674c 100644 --- a/javascript/MaterialXView/package-lock.json +++ b/javascript/MaterialXView/package-lock.json @@ -10,7 +10,7 @@ "license": "ISC", "dependencies": { "dat.gui": "^0.7.9", - "three": "^0.135.0", + "three": "^0.140.2", "webpack": "^5.88.1" }, "devDependencies": { @@ -166,9 +166,9 @@ } }, "node_modules/@types/eslint": { - "version": "8.40.2", - "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.40.2.tgz", - "integrity": "sha512-PRVjQ4Eh9z9pmmtaq8nTjZjQwKFk7YIHIud3lRoKRBgUQjgjRmoGxxGEPXQkF+lH7QkHJRNr5F4aBgYCW0lqpQ==", + "version": "8.44.0", + "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.44.0.tgz", + "integrity": "sha512-gsF+c/0XOguWgaOgvFs+xnnRqt9GwgTvIks36WpE6ueeI4KCEHHd8K/CKHqhOqrJKsYH8m27kRzQEvWXAwXUTw==", "dependencies": { "@types/estree": "*", "@types/json-schema": "*" @@ -245,9 +245,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.3.3", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.3.3.tgz", - "integrity": "sha512-wheIYdr4NYML61AjC8MKj/2jrR/kDQri/CIpVoZwldwhnIrD/j9jIU5bJ8yBKuB2VhpFV7Ab6G2XkBjv9r9Zzw==" + "version": "20.4.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.2.tgz", + "integrity": "sha512-Dd0BYtWgnWJKwO1jkmTrzofjK2QXXcai0dmtzvIBhcA+RsG5h8R3xlyta0kGOZRNfL9GuRtb1knmPEhQrePCEw==" }, "node_modules/@types/qs": { "version": "6.9.7", @@ -506,9 +506,9 @@ } }, "node_modules/acorn": { - "version": "8.9.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.9.0.tgz", - "integrity": "sha512-jaVNAFBHNLXspO543WnNNPZFRtavh3skAkITqD0/2aeMkKZTN+254PyhwxFYrk3vQ1xfY+2wbesJMs/JC8/PwQ==", + "version": "8.10.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.10.0.tgz", + "integrity": "sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==", "bin": { "acorn": "bin/acorn" }, @@ -798,9 +798,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001512", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001512.tgz", - "integrity": "sha512-2S9nK0G/mE+jasCUsMPlARhRCts1ebcp2Ji8Y8PWi4NDE1iRdLCnEPHkEfeBrGC45L4isBx5ur3IQ6yTE2mRZw==", + "version": "1.0.30001515", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001515.tgz", + "integrity": "sha512-eEFDwUOZbE24sb+Ecsx3+OvNETqjWIdabMy52oOkIgcUtAsQifjUG9q4U9dgTHJM2mfk4uEPxc0+xuFdJ629QA==", "funding": [ { "type": "opencollective", @@ -1223,9 +1223,9 @@ "dev": true }, "node_modules/electron-to-chromium": { - "version": "1.4.449", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.449.tgz", - "integrity": "sha512-TxLRpRUj/107ATefeP8VIUWNOv90xJxZZbCW/eIbSZQiuiFANCx2b7u+GbVc9X4gU+xnbvypNMYVM/WArE1DNQ==" + "version": "1.4.460", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.460.tgz", + "integrity": "sha512-kKiHnbrHME7z8E6AYaw0ehyxY5+hdaRmeUbjBO22LZMdqTYCO29EvF0T1cQ3pJ1RN5fyMcHl1Lmcsdt9WWJpJQ==" }, "node_modules/encodeurl": { "version": "1.0.2", @@ -2397,9 +2397,9 @@ } }, "node_modules/node-releases": { - "version": "2.0.12", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.12.tgz", - "integrity": "sha512-QzsYKWhXTWx8h1kIvqfnC++o0pEmpRQA/aenALsL2F4pqNVr7YzcdMlDij5WBnwftRbJCNJL/O7zdKaxKPHqgQ==" + "version": "2.0.13", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.13.tgz", + "integrity": "sha512-uYr7J37ae/ORWdZeQ1xxMJe3NtdmqMC/JZK+geofDrkLUApKRHPd18/TxtBOJ4A0/+uUIliorNrfYV6s1b02eQ==" }, "node_modules/normalize-path": { "version": "3.0.0", @@ -3405,9 +3405,9 @@ } }, "node_modules/terser": { - "version": "5.18.2", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.18.2.tgz", - "integrity": "sha512-Ah19JS86ypbJzTzvUCX7KOsEIhDaRONungA4aYBjEP3JZRf4ocuDzTg4QWZnPn9DEMiMYGJPiSOy7aykoCc70w==", + "version": "5.19.0", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.19.0.tgz", + "integrity": "sha512-JpcpGOQLOXm2jsomozdMDpd5f8ZHh1rR48OFgWUH3QsyZcfPgv2qDCYbcDEAYNd4OZRj2bWYKpwdll/udZCk/Q==", "dependencies": { "@jridgewell/source-map": "^0.3.3", "acorn": "^8.8.2", @@ -3468,9 +3468,9 @@ "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" }, "node_modules/three": { - "version": "0.135.0", - "resolved": "https://registry.npmjs.org/three/-/three-0.135.0.tgz", - "integrity": "sha512-kuEpuuxRzLv0MDsXai9huCxOSQPZ4vje6y0gn80SRmQvgz6/+rI0NAvCRAw56zYaWKMGMfqKWsxF9Qa2Z9xymQ==" + "version": "0.140.2", + "resolved": "https://registry.npmjs.org/three/-/three-0.140.2.tgz", + "integrity": "sha512-DdT/AHm/TbZXEhQKQpGt5/iSgBrmXpjU26FNtj1KhllVPTKj1eG4X/ShyD5W2fngE+I1s1wa4ttC4C3oCJt7Ag==" }, "node_modules/thunky": { "version": "1.1.0", diff --git a/javascript/MaterialXView/package.json b/javascript/MaterialXView/package.json index 2113d145cf..7ee8611600 100644 --- a/javascript/MaterialXView/package.json +++ b/javascript/MaterialXView/package.json @@ -11,7 +11,7 @@ "license": "ISC", "dependencies": { "dat.gui": "^0.7.9", - "three": "^0.135.0", + "three": "^0.140.2", "webpack": "^5.88.1" }, "devDependencies": { diff --git a/javascript/MaterialXView/source/helper.js b/javascript/MaterialXView/source/helper.js index e8ffb9dcae..111dfd9b5d 100644 --- a/javascript/MaterialXView/source/helper.js +++ b/javascript/MaterialXView/source/helper.js @@ -20,8 +20,6 @@ const IMAGE_PATH_SEPARATOR = "/"; export function prepareEnvTexture(texture, capabilities) { const rgbaTexture = RGBToRGBA_Float(texture); - // RGBELoader sets flipY to true by default - rgbaTexture.flipY = false; rgbaTexture.wrapS = THREE.RepeatWrapping; rgbaTexture.anisotropy = capabilities.getMaxAnisotropy(); rgbaTexture.minFilter = THREE.LinearMipmapLinearFilter; diff --git a/javascript/MaterialXView/source/viewer.js b/javascript/MaterialXView/source/viewer.js index 0bc537faf0..126b5d5bca 100644 --- a/javascript/MaterialXView/source/viewer.js +++ b/javascript/MaterialXView/source/viewer.js @@ -777,7 +777,7 @@ export class Material Object.assign(uniforms, { u_numActiveLightSources: { value: lights.length }, u_lightData: { value: lightData }, - u_envMatrix: { value: getLightRotation() }, + u_envMatrix: { value: new THREE.Matrix4().multiplyMatrices(getLightRotation(), new THREE.Matrix4().makeScale(1, -1, 1)) }, u_envRadiance: { value: radianceTexture }, u_envRadianceMips: { value: Math.trunc(Math.log2(Math.max(radianceTexture.image.width, radianceTexture.image.height))) + 1 }, u_envRadianceSamples: { value: 16 }, From 42e8b765380efe157eaf9d072128db1835aff352 Mon Sep 17 00:00:00 2001 From: Benjamin Beilharz Date: Sun, 23 Jul 2023 20:34:46 +0200 Subject: [PATCH 7/7] Added option to install resource folder (#1419) Added an option in the CMake file which toggles the installation of resources if the renderer is built and the user wants to install the resources. --- CMakeLists.txt | 5 ++++- cmake/modules/MaterialXConfig.cmake.in | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 86872f26de..a5624f0a64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ option(MATERIALX_BUILD_TESTS "Build unit tests." ON) option(MATERIALX_BUILD_SHARED_LIBS "Build MaterialX libraries as shared rather than static." OFF) option(MATERIALX_PYTHON_LTO "Enable link-time optimizations for MaterialX Python." ON) option(MATERIALX_INSTALL_PYTHON "Install the MaterialX Python package as a third-party library when the install target is built." ON) +option(MATERIALX_INSTALL_RESOURCES "Install the resources folder when building render modules." ON) option(MATERIALX_TEST_RENDER "Run rendering tests for MaterialX Render module. GPU required for graphics validation." ON) option(MATERIALX_WARNINGS_AS_ERRORS "Interpret all compiler warnings as errors." OFF) option(MATERIALX_DYNAMIC_ANALYSIS "Build MaterialX libraries with dynamic analysis on supporting platforms." OFF) @@ -276,7 +277,9 @@ if(MATERIALX_BUILD_RENDER) if(MATERIALX_BUILD_GRAPH_EDITOR) add_subdirectory(source/MaterialXGraphEditor) endif() - add_subdirectory(resources) + if(MATERIALX_INSTALL_RESOURCES) + add_subdirectory(resources) + endif() endif() # Add test subdirectory diff --git a/cmake/modules/MaterialXConfig.cmake.in b/cmake/modules/MaterialXConfig.cmake.in index b4c8b7fad6..e1598087bf 100644 --- a/cmake/modules/MaterialXConfig.cmake.in +++ b/cmake/modules/MaterialXConfig.cmake.in @@ -22,6 +22,8 @@ set_and_check(MATERIALX_STDLIB_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/libraries") if(@MATERIALX_BUILD_PYTHON@ AND @MATERIALX_INSTALL_PYTHON@) set_and_check(MATERIALX_PYTHON_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/python") endif() -set_and_check(MATERIALX_RESOURCES_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/resources") +if(@MATERIALX_BUILD_RENDER@ AND @MATERIALX_INSTALL_RESOURCES@) + set_and_check(MATERIALX_RESOURCES_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/resources") +endif() check_required_components(@CMAKE_PROJECT_NAME@)