From f900c67ce06b44340f06e7a8b183174773ca6f9a Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Wed, 6 Sep 2023 18:02:01 +0300 Subject: [PATCH 1/7] MaterialX: added Blackbody node --- source/blender/nodes/shader/CMakeLists.txt | 1 + .../nodes/shader/materialx/nodes/blackbody.cc | 22 +++++++++++++++++++ .../shader/materialx/nodes/node_parser.cc | 1 + .../shader/materialx/nodes/node_parser.h | 1 + 4 files changed, 25 insertions(+) create mode 100644 source/blender/nodes/shader/materialx/nodes/blackbody.cc diff --git a/source/blender/nodes/shader/CMakeLists.txt b/source/blender/nodes/shader/CMakeLists.txt index 9a3b77502fbf..7238a845e239 100644 --- a/source/blender/nodes/shader/CMakeLists.txt +++ b/source/blender/nodes/shader/CMakeLists.txt @@ -147,6 +147,7 @@ set(LIB if(WITH_MATERIALX) list(APPEND SRC materialx/material.cc + materialx/nodes/blackbody.cc materialx/nodes/brightness.cc materialx/nodes/bsdf_principled.cc materialx/nodes/huesatval.cc diff --git a/source/blender/nodes/shader/materialx/nodes/blackbody.cc b/source/blender/nodes/shader/materialx/nodes/blackbody.cc new file mode 100644 index 000000000000..443cd598143d --- /dev/null +++ b/source/blender/nodes/shader/materialx/nodes/blackbody.cc @@ -0,0 +1,22 @@ +/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "node_parser.h" + +namespace blender::nodes::materialx { + +NodeItem BlackbodyNodeParser::compute() +{ + /* This node doesn't have an implementation in MaterialX 1.38.6. + * It's added in MaterialX 1.38.8. Uncomment this code after switching to 1.38.8. + * + * NodeItem temperature = get_input_value("Temperature", NodeItem::Type::Float); + + * NodeItem res = create_node("blackbody", "color3"); + * res.set_input("temperature", temperature); + * return res; */ + return empty(); +} + +} // namespace blender::nodes::materialx diff --git a/source/blender/nodes/shader/materialx/nodes/node_parser.cc b/source/blender/nodes/shader/materialx/nodes/node_parser.cc index ec3462efb801..d1e6954122c8 100644 --- a/source/blender/nodes/shader/materialx/nodes/node_parser.cc +++ b/source/blender/nodes/shader/materialx/nodes/node_parser.cc @@ -132,6 +132,7 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket) break; switch (from_node->typeinfo->type) { + CASE_NODE_TYPE(SH_NODE_BLACKBODY, BlackbodyNodeParser) CASE_NODE_TYPE(SH_NODE_BRIGHTCONTRAST, BrightContrastNodeParser) CASE_NODE_TYPE(SH_NODE_BSDF_PRINCIPLED, BSDFPrincipledNodeParser) CASE_NODE_TYPE(SH_NODE_COMBINE_COLOR, CombineColorNodeParser) diff --git a/source/blender/nodes/shader/materialx/nodes/node_parser.h b/source/blender/nodes/shader/materialx/nodes/node_parser.h index 15243b74f992..b4102b471998 100644 --- a/source/blender/nodes/shader/materialx/nodes/node_parser.h +++ b/source/blender/nodes/shader/materialx/nodes/node_parser.h @@ -63,6 +63,7 @@ template NodeItem NodeParser::value(const T &data) const NodeItem compute() override; \ }; +DECLARE_PARSER(BlackbodyNodeParser) DECLARE_PARSER(BrightContrastNodeParser) DECLARE_PARSER(BSDFPrincipledNodeParser) DECLARE_PARSER(CombineColorNodeParser) -- 2.30.2 From 5a5dd1201ff3a8e137fb63345b2515cf566ced91 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Wed, 6 Sep 2023 19:00:57 +0300 Subject: [PATCH 2/7] MaterialX: added Clamp node --- source/blender/nodes/shader/CMakeLists.txt | 1 + .../nodes/shader/materialx/nodes/clamp.cc | 23 +++++++++++++++++++ .../shader/materialx/nodes/node_parser.cc | 1 + .../shader/materialx/nodes/node_parser.h | 1 + 4 files changed, 26 insertions(+) create mode 100644 source/blender/nodes/shader/materialx/nodes/clamp.cc diff --git a/source/blender/nodes/shader/CMakeLists.txt b/source/blender/nodes/shader/CMakeLists.txt index 7238a845e239..9d4f32f5d9f2 100644 --- a/source/blender/nodes/shader/CMakeLists.txt +++ b/source/blender/nodes/shader/CMakeLists.txt @@ -150,6 +150,7 @@ if(WITH_MATERIALX) materialx/nodes/blackbody.cc materialx/nodes/brightness.cc materialx/nodes/bsdf_principled.cc + materialx/nodes/clamp.cc materialx/nodes/huesatval.cc materialx/nodes/invert.cc materialx/nodes/math.cc diff --git a/source/blender/nodes/shader/materialx/nodes/clamp.cc b/source/blender/nodes/shader/materialx/nodes/clamp.cc new file mode 100644 index 000000000000..f598e961833a --- /dev/null +++ b/source/blender/nodes/shader/materialx/nodes/clamp.cc @@ -0,0 +1,23 @@ +/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "node_parser.h" + +namespace blender::nodes::materialx { + +NodeItem ClampNodeParser::compute() +{ + auto type = node_->custom1; + NodeItem value = get_input_value("Value", NodeItem::Type::Float); + NodeItem min = get_input_value("Min", NodeItem::Type::Float); + NodeItem max = get_input_value("Max", NodeItem::Type::Float); + + if (type == NODE_CLAMP_MINMAX) { + min = min.if_else(NodeItem::CompareOp::Greater, max, max, min); + } + + return value.clamp(min, max); +} + +} // namespace blender::nodes::materialx diff --git a/source/blender/nodes/shader/materialx/nodes/node_parser.cc b/source/blender/nodes/shader/materialx/nodes/node_parser.cc index d1e6954122c8..1b8da2d4b3fb 100644 --- a/source/blender/nodes/shader/materialx/nodes/node_parser.cc +++ b/source/blender/nodes/shader/materialx/nodes/node_parser.cc @@ -135,6 +135,7 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket) CASE_NODE_TYPE(SH_NODE_BLACKBODY, BlackbodyNodeParser) CASE_NODE_TYPE(SH_NODE_BRIGHTCONTRAST, BrightContrastNodeParser) CASE_NODE_TYPE(SH_NODE_BSDF_PRINCIPLED, BSDFPrincipledNodeParser) + CASE_NODE_TYPE(SH_NODE_CLAMP, ClampNodeParser) CASE_NODE_TYPE(SH_NODE_COMBINE_COLOR, CombineColorNodeParser) CASE_NODE_TYPE(SH_NODE_COMBXYZ, CombineXYZNodeParser) CASE_NODE_TYPE(SH_NODE_HUE_SAT, HueSatValNodeParser) diff --git a/source/blender/nodes/shader/materialx/nodes/node_parser.h b/source/blender/nodes/shader/materialx/nodes/node_parser.h index b4102b471998..8e2d739e0bf9 100644 --- a/source/blender/nodes/shader/materialx/nodes/node_parser.h +++ b/source/blender/nodes/shader/materialx/nodes/node_parser.h @@ -66,6 +66,7 @@ template NodeItem NodeParser::value(const T &data) const DECLARE_PARSER(BlackbodyNodeParser) DECLARE_PARSER(BrightContrastNodeParser) DECLARE_PARSER(BSDFPrincipledNodeParser) +DECLARE_PARSER(ClampNodeParser) DECLARE_PARSER(CombineColorNodeParser) DECLARE_PARSER(CombineXYZNodeParser) DECLARE_PARSER(HueSatValNodeParser) -- 2.30.2 From 7ebca40cfc546b8e798e1d83beffc17b5a507fff Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Wed, 6 Sep 2023 21:02:50 +0300 Subject: [PATCH 3/7] MaterialX: added MapRange node --- source/blender/nodes/shader/CMakeLists.txt | 1 + .../nodes/shader/materialx/nodes/map_range.cc | 51 +++++++++++++++++++ .../nodes/shader/materialx/nodes/node_item.cc | 9 ++++ .../nodes/shader/materialx/nodes/node_item.h | 6 ++- .../shader/materialx/nodes/node_parser.cc | 1 + .../shader/materialx/nodes/node_parser.h | 1 + 6 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 source/blender/nodes/shader/materialx/nodes/map_range.cc diff --git a/source/blender/nodes/shader/CMakeLists.txt b/source/blender/nodes/shader/CMakeLists.txt index 9d4f32f5d9f2..7dcf7f0380d2 100644 --- a/source/blender/nodes/shader/CMakeLists.txt +++ b/source/blender/nodes/shader/CMakeLists.txt @@ -153,6 +153,7 @@ if(WITH_MATERIALX) materialx/nodes/clamp.cc materialx/nodes/huesatval.cc materialx/nodes/invert.cc + materialx/nodes/map_range.cc materialx/nodes/math.cc materialx/nodes/mix_rgb.cc materialx/nodes/node_item.cc diff --git a/source/blender/nodes/shader/materialx/nodes/map_range.cc b/source/blender/nodes/shader/materialx/nodes/map_range.cc new file mode 100644 index 000000000000..74cdf7f93250 --- /dev/null +++ b/source/blender/nodes/shader/materialx/nodes/map_range.cc @@ -0,0 +1,51 @@ +/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "node_parser.h" + +namespace blender::nodes::materialx { + +NodeItem MapRangeNodeParser::compute() +{ + /* Interpolation isn't supported by MaterialX. */ + const NodeMapRange *map_range = static_cast(node_->storage); + + NodeItem::Type type; + NodeItem val = empty(); + NodeItem from_min = empty(); + NodeItem from_max = empty(); + NodeItem to_min = empty(); + NodeItem to_max = empty(); + switch (map_range->data_type) { + case CD_PROP_FLOAT: + type = NodeItem::Type::Float; + val = get_input_value("Value", type); + from_min = get_input_value(1, type); + from_max = get_input_value(2, type); + to_min = get_input_value(3, type); + to_max = get_input_value(4, type); + break; + case CD_PROP_FLOAT3: + type = NodeItem::Type::Vector3; + val = get_input_value("Vector", type); + from_min = get_input_value(7, type); + from_max = get_input_value(8, type); + to_min = get_input_value(9, type); + to_max = get_input_value(10, type); + break; + default: + BLI_assert_unreachable(); + } + + NodeItem res = create_node("range", NodeItem::type(type)); + res.set_input("in", val); + res.set_input("inlow", from_min); + res.set_input("inhigh", from_max); + res.set_input("outlow", to_min); + res.set_input("outhigh", to_max); + res.set_input("doclamp", value(bool(map_range->clamp))); + return res; +} + +} // namespace blender::nodes::materialx diff --git a/source/blender/nodes/shader/materialx/nodes/node_item.cc b/source/blender/nodes/shader/materialx/nodes/node_item.cc index 7801d5409135..bd49e6c10235 100644 --- a/source/blender/nodes/shader/materialx/nodes/node_item.cc +++ b/source/blender/nodes/shader/materialx/nodes/node_item.cc @@ -513,6 +513,9 @@ void NodeItem::set_input(const std::string &name, case Type::String: set_input(name, item.value->asA(), mx_type); break; + case Type::Bool: + set_input(name, item.value->asA(), mx_type); + break; case Type::Integer: set_input(name, item.value->asA(), mx_type); break; @@ -559,6 +562,9 @@ NodeItem::Type NodeItem::type(const std::string &type_str) if (type_str == "string") { return Type::String; } + if (type_str == "boolean") { + return Type::Bool; + } if (type_str == "integer") { return Type::Integer; } @@ -588,6 +594,8 @@ std::string NodeItem::type(Type type) switch (type) { case Type::String: return "string"; + case Type::Bool: + return "boolean"; case Type::Integer: return "integer"; case Type::Float: @@ -603,6 +611,7 @@ std::string NodeItem::type(Type type) case Type::Color4: return "color4"; default: + BLI_assert_unreachable(); break; } return ""; diff --git a/source/blender/nodes/shader/materialx/nodes/node_item.h b/source/blender/nodes/shader/materialx/nodes/node_item.h index 19e29ef1854f..8ca3c8f50e51 100644 --- a/source/blender/nodes/shader/materialx/nodes/node_item.h +++ b/source/blender/nodes/shader/materialx/nodes/node_item.h @@ -14,6 +14,7 @@ class NodeItem { Empty = 0, Other, /* For MaterialX types like: surfaceshader, bsdf, edf, ...*/ String, + Bool, Integer, Float, Vector2, @@ -47,6 +48,9 @@ class NodeItem { bool operator==(const NodeItem &other) const; bool operator!=(const NodeItem &other) const; + static Type type(const std::string &type_str); + static std::string type(Type type); + /* Math functions */ NodeItem abs() const; NodeItem floor() const; @@ -92,8 +96,6 @@ class NodeItem { void add_output(const std::string &in_name, Type out_type); private: - static Type type(const std::string &type_str); - static std::string type(Type type); static bool is_arithmetic(Type type); static Type adjust_types(NodeItem &item1, NodeItem &item2); diff --git a/source/blender/nodes/shader/materialx/nodes/node_parser.cc b/source/blender/nodes/shader/materialx/nodes/node_parser.cc index 1b8da2d4b3fb..004be77b0c59 100644 --- a/source/blender/nodes/shader/materialx/nodes/node_parser.cc +++ b/source/blender/nodes/shader/materialx/nodes/node_parser.cc @@ -140,6 +140,7 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket) CASE_NODE_TYPE(SH_NODE_COMBXYZ, CombineXYZNodeParser) CASE_NODE_TYPE(SH_NODE_HUE_SAT, HueSatValNodeParser) CASE_NODE_TYPE(SH_NODE_INVERT, InvertNodeParser) + CASE_NODE_TYPE(SH_NODE_MAP_RANGE, MapRangeNodeParser) CASE_NODE_TYPE(SH_NODE_MATH, MathNodeParser) CASE_NODE_TYPE(SH_NODE_MIX_RGB_LEGACY, MixRGBNodeParser) CASE_NODE_TYPE(SH_NODE_NORMAL_MAP, NormalMapNodeParser) diff --git a/source/blender/nodes/shader/materialx/nodes/node_parser.h b/source/blender/nodes/shader/materialx/nodes/node_parser.h index 8e2d739e0bf9..905aa34ebd3d 100644 --- a/source/blender/nodes/shader/materialx/nodes/node_parser.h +++ b/source/blender/nodes/shader/materialx/nodes/node_parser.h @@ -71,6 +71,7 @@ DECLARE_PARSER(CombineColorNodeParser) DECLARE_PARSER(CombineXYZNodeParser) DECLARE_PARSER(HueSatValNodeParser) DECLARE_PARSER(InvertNodeParser) +DECLARE_PARSER(MapRangeNodeParser) DECLARE_PARSER(MathNodeParser) DECLARE_PARSER(MixRGBNodeParser) DECLARE_PARSER(NormalMapNodeParser) -- 2.30.2 From c3cede664da2197f95e7b3b62a85a32dc1ba0deb Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 7 Sep 2023 17:16:28 +0300 Subject: [PATCH 4/7] MaterialX: added RGBToBW node --- .../nodes/shader/materialx/nodes/blackbody.cc | 2 +- .../shader/materialx/nodes/node_parser.cc | 1 + .../nodes/shader/materialx/nodes/node_parser.h | 1 + .../nodes/shader/materialx/nodes/rgb_to_bw.cc | 18 ++++++++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 source/blender/nodes/shader/materialx/nodes/rgb_to_bw.cc diff --git a/source/blender/nodes/shader/materialx/nodes/blackbody.cc b/source/blender/nodes/shader/materialx/nodes/blackbody.cc index 443cd598143d..956e540d80b0 100644 --- a/source/blender/nodes/shader/materialx/nodes/blackbody.cc +++ b/source/blender/nodes/shader/materialx/nodes/blackbody.cc @@ -13,7 +13,7 @@ NodeItem BlackbodyNodeParser::compute() * * NodeItem temperature = get_input_value("Temperature", NodeItem::Type::Float); - * NodeItem res = create_node("blackbody", "color3"); + * NodeItem res = create_node("blackbody", NodeItem::Type::Color3); * res.set_input("temperature", temperature); * return res; */ return empty(); diff --git a/source/blender/nodes/shader/materialx/nodes/node_parser.cc b/source/blender/nodes/shader/materialx/nodes/node_parser.cc index 53eed07adfc0..ec017a5319a5 100644 --- a/source/blender/nodes/shader/materialx/nodes/node_parser.cc +++ b/source/blender/nodes/shader/materialx/nodes/node_parser.cc @@ -147,6 +147,7 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket, NodeItem::Type to CASE_NODE_TYPE(SH_NODE_MATH, MathNodeParser) CASE_NODE_TYPE(SH_NODE_MIX_RGB_LEGACY, MixRGBNodeParser) CASE_NODE_TYPE(SH_NODE_NORMAL_MAP, NormalMapNodeParser) + CASE_NODE_TYPE(SH_NODE_RGBTOBW, RGBToBWNodeParser) CASE_NODE_TYPE(SH_NODE_SEPARATE_COLOR, SeparateColorNodeParser) CASE_NODE_TYPE(SH_NODE_SEPXYZ, SeparateXYZNodeParser) CASE_NODE_TYPE(SH_NODE_TEX_CHECKER, TexCheckerNodeParser) diff --git a/source/blender/nodes/shader/materialx/nodes/node_parser.h b/source/blender/nodes/shader/materialx/nodes/node_parser.h index 2b719fed1012..9cfc729439c3 100644 --- a/source/blender/nodes/shader/materialx/nodes/node_parser.h +++ b/source/blender/nodes/shader/materialx/nodes/node_parser.h @@ -101,6 +101,7 @@ DECLARE_NODE_PARSER(MapRangeNodeParser) DECLARE_NODE_PARSER(MathNodeParser) DECLARE_NODE_PARSER(MixRGBNodeParser) DECLARE_NODE_PARSER(NormalMapNodeParser) +DECLARE_NODE_PARSER(RGBToBWNodeParser) DECLARE_NODE_PARSER(SeparateColorNodeParser) DECLARE_NODE_PARSER(SeparateXYZNodeParser) DECLARE_NODE_PARSER(TexCheckerNodeParser) diff --git a/source/blender/nodes/shader/materialx/nodes/rgb_to_bw.cc b/source/blender/nodes/shader/materialx/nodes/rgb_to_bw.cc new file mode 100644 index 000000000000..cf0e825cff7c --- /dev/null +++ b/source/blender/nodes/shader/materialx/nodes/rgb_to_bw.cc @@ -0,0 +1,18 @@ +/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "node_parser.h" + +namespace blender::nodes::materialx { + +NodeItem RGBToBWNodeParser::compute() +{ + NodeItem color = get_input_value("Color", NodeItem::Type::Color3); + + NodeItem res = create_node("luminance", NodeItem::Type::Color3); + res.set_input("in", color); + return res; +} + +} // namespace blender::nodes::materialx -- 2.30.2 From ffce802015c049156db7f3959643507e4a9631f2 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 7 Sep 2023 17:18:48 +0300 Subject: [PATCH 5/7] MaterialX: added file to CMakeLists.txt --- source/blender/nodes/shader/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/source/blender/nodes/shader/CMakeLists.txt b/source/blender/nodes/shader/CMakeLists.txt index cee14296cd21..d1e953629e80 100644 --- a/source/blender/nodes/shader/CMakeLists.txt +++ b/source/blender/nodes/shader/CMakeLists.txt @@ -171,6 +171,7 @@ if(WITH_MATERIALX) materialx/nodes/node_parser.cc materialx/nodes/normal_map.cc materialx/nodes/output_material.cc + materialx/nodes/rgb_to_bw.cc materialx/nodes/sepcomb_color.cc materialx/nodes/sepcomb_xyz.cc materialx/nodes/subsurface_scattering.cc -- 2.30.2 From 51c2e94a6c2c170139c67313c644cc724de590df Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 8 Sep 2023 11:24:32 +0300 Subject: [PATCH 6/7] MaterialX: fix review comments --- .../nodes/shader/materialx/nodes/blackbody.cc | 12 ++++-------- .../nodes/shader/materialx/nodes/node_item.cc | 6 +++--- .../blender/nodes/shader/materialx/nodes/node_item.h | 2 +- .../nodes/shader/materialx/nodes/rgb_to_bw.cc | 4 ++-- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/source/blender/nodes/shader/materialx/nodes/blackbody.cc b/source/blender/nodes/shader/materialx/nodes/blackbody.cc index 956e540d80b0..4d251c869bee 100644 --- a/source/blender/nodes/shader/materialx/nodes/blackbody.cc +++ b/source/blender/nodes/shader/materialx/nodes/blackbody.cc @@ -8,15 +8,11 @@ namespace blender::nodes::materialx { NodeItem BlackbodyNodeParser::compute() { - /* This node doesn't have an implementation in MaterialX 1.38.6. - * It's added in MaterialX 1.38.8. Uncomment this code after switching to 1.38.8. - * - * NodeItem temperature = get_input_value("Temperature", NodeItem::Type::Float); + NodeItem temperature = get_input_value("Temperature", NodeItem::Type::Float); - * NodeItem res = create_node("blackbody", NodeItem::Type::Color3); - * res.set_input("temperature", temperature); - * return res; */ - return empty(); + NodeItem res = create_node("blackbody", NodeItem::Type::Color3); + res.set_input("temperature", temperature); + return res; } } // namespace blender::nodes::materialx diff --git a/source/blender/nodes/shader/materialx/nodes/node_item.cc b/source/blender/nodes/shader/materialx/nodes/node_item.cc index 859706e892d9..efef38cec1ed 100644 --- a/source/blender/nodes/shader/materialx/nodes/node_item.cc +++ b/source/blender/nodes/shader/materialx/nodes/node_item.cc @@ -21,7 +21,7 @@ NodeItem::Type NodeItem::type(const std::string &type_str) return Type::Filename; } if (type_str == "boolean") { - return Type::Bool; + return Type::Boolean; } if (type_str == "integer") { return Type::Integer; @@ -67,7 +67,7 @@ std::string NodeItem::type(Type type) return "string"; case Type::Filename: return "filename"; - case Type::Bool: + case Type::Boolean: return "boolean"; case Type::Integer: return "integer"; @@ -638,7 +638,7 @@ void NodeItem::set_input(const std::string &in_name, const NodeItem &item) case Type::String: set_input(in_name, item.value->asA(), item_type); break; - case Type::Bool: + case Type::Boolean: set_input(in_name, item.value->asA(), item_type); break; case Type::Integer: diff --git a/source/blender/nodes/shader/materialx/nodes/node_item.h b/source/blender/nodes/shader/materialx/nodes/node_item.h index 1115be225e38..f67adcd11133 100644 --- a/source/blender/nodes/shader/materialx/nodes/node_item.h +++ b/source/blender/nodes/shader/materialx/nodes/node_item.h @@ -17,7 +17,7 @@ class NodeItem { /* Value types */ String, Filename, - Bool, + Boolean, Integer, /* Block of arithmetic types. Ordered by type cast */ Float, diff --git a/source/blender/nodes/shader/materialx/nodes/rgb_to_bw.cc b/source/blender/nodes/shader/materialx/nodes/rgb_to_bw.cc index cf0e825cff7c..b52b7a6e9cab 100644 --- a/source/blender/nodes/shader/materialx/nodes/rgb_to_bw.cc +++ b/source/blender/nodes/shader/materialx/nodes/rgb_to_bw.cc @@ -8,9 +8,9 @@ namespace blender::nodes::materialx { NodeItem RGBToBWNodeParser::compute() { - NodeItem color = get_input_value("Color", NodeItem::Type::Color3); + NodeItem color = get_input_value("Color", NodeItem::Type::Color4); - NodeItem res = create_node("luminance", NodeItem::Type::Color3); + NodeItem res = create_node("luminance", NodeItem::Type::Color4); res.set_input("in", color); return res; } -- 2.30.2 From 33d2cfc8b021dd94e3bfcf3e6bd6b7ba89f65821 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 8 Sep 2023 16:04:52 +0300 Subject: [PATCH 7/7] MaterialX: fix clamp node, revert blackbody node changes --- .../nodes/shader/materialx/nodes/blackbody.cc | 12 ++++++++---- source/blender/nodes/shader/materialx/nodes/clamp.cc | 12 ++++++++---- .../nodes/shader/materialx/nodes/rgb_to_bw.cc | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/source/blender/nodes/shader/materialx/nodes/blackbody.cc b/source/blender/nodes/shader/materialx/nodes/blackbody.cc index 4d251c869bee..e3293ffe4fe0 100644 --- a/source/blender/nodes/shader/materialx/nodes/blackbody.cc +++ b/source/blender/nodes/shader/materialx/nodes/blackbody.cc @@ -8,11 +8,15 @@ namespace blender::nodes::materialx { NodeItem BlackbodyNodeParser::compute() { - NodeItem temperature = get_input_value("Temperature", NodeItem::Type::Float); + /* This node doesn't have an implementation in MaterialX 1.38.6. + * It's added in MaterialX 1.38.8. Uncomment this code after switching to 1.38.8. + * + * NodeItem temperature = get_input_value("Temperature", NodeItem::Type::Float); - NodeItem res = create_node("blackbody", NodeItem::Type::Color3); - res.set_input("temperature", temperature); - return res; + * NodeItem res = create_node("blackbody", NodeItem::Type::Color3); + * res.set_input("temperature", temperature); + * return res; */ + return empty(); } } // namespace blender::nodes::materialx diff --git a/source/blender/nodes/shader/materialx/nodes/clamp.cc b/source/blender/nodes/shader/materialx/nodes/clamp.cc index f598e961833a..035a6dd98349 100644 --- a/source/blender/nodes/shader/materialx/nodes/clamp.cc +++ b/source/blender/nodes/shader/materialx/nodes/clamp.cc @@ -13,11 +13,15 @@ NodeItem ClampNodeParser::compute() NodeItem min = get_input_value("Min", NodeItem::Type::Float); NodeItem max = get_input_value("Max", NodeItem::Type::Float); - if (type == NODE_CLAMP_MINMAX) { - min = min.if_else(NodeItem::CompareOp::Greater, max, max, min); + NodeItem res = empty(); + if (type == NODE_CLAMP_RANGE) { + res = min.if_else( + NodeItem::CompareOp::Less, max, value.clamp(min, max), value.clamp(max, min)); } - - return value.clamp(min, max); + else { + res = value.clamp(min, max); + } + return res; } } // namespace blender::nodes::materialx diff --git a/source/blender/nodes/shader/materialx/nodes/rgb_to_bw.cc b/source/blender/nodes/shader/materialx/nodes/rgb_to_bw.cc index b52b7a6e9cab..26ed24694327 100644 --- a/source/blender/nodes/shader/materialx/nodes/rgb_to_bw.cc +++ b/source/blender/nodes/shader/materialx/nodes/rgb_to_bw.cc @@ -12,7 +12,7 @@ NodeItem RGBToBWNodeParser::compute() NodeItem res = create_node("luminance", NodeItem::Type::Color4); res.set_input("in", color); - return res; + return res; } } // namespace blender::nodes::materialx -- 2.30.2