From c0cd1a61eed6d6de46ead0c28e927facd5457776 Mon Sep 17 00:00:00 2001
From: friedererdmann <55715326+friedererdmann@users.noreply.github.com>
Date: Wed, 14 Sep 2022 20:34:49 +0200
Subject: [PATCH 1/3] Initial pass to expose mix datatypes
---
goal.md | 16 +++++++++
.../stdlib/genglsl/stdlib_genglsl_impl.mtlx | 5 +++
.../stdlib/genmdl/stdlib_genmdl_impl.mtlx | 5 +++
libraries/stdlib/genosl/include/color4.h | 6 ++++
libraries/stdlib/genosl/include/vector2.h | 5 +++
libraries/stdlib/genosl/include/vector4.h | 8 +++++
.../stdlib/genosl/stdlib_genosl_impl.mtlx | 5 +++
libraries/stdlib/stdlib_defs.mtlx | 30 ++++++++++++++++
.../stdlib/compositing/compositing.mtlx | 36 +++++++++++++++++--
.../MaterialXGenMdl/mdl/materialx/stdlib.mdl | 12 +++++++
10 files changed, 126 insertions(+), 2 deletions(-)
create mode 100644 goal.md
diff --git a/goal.md b/goal.md
new file mode 100644
index 0000000000..335d79dbf1
--- /dev/null
+++ b/goal.md
@@ -0,0 +1,16 @@
+# Extending `mix` node to allow per channel mixing
+
+The mix node's mix input should allow for all data formats as input and do a per element linear interpolation, not just float.
+
+```
+in1 = Vector2(1,1)
+in2 = Vector2(0,0)
+mix = Vector2(1,0)
+out = Vector2(1,0)
+```
+
+Backwards compatibility means float needs to remain supported.
+
+Adding node definitions with the extra suffix of the mix data type like `ND_mix_color3_color3`.
+
+
diff --git a/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx b/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx
index 39262ae95a..47b95c1990 100644
--- a/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx
+++ b/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx
@@ -597,10 +597,15 @@
+
+
+
+
+
diff --git a/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx b/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
index 24b5099ad2..0ea537a310 100644
--- a/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
+++ b/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
@@ -605,10 +605,15 @@
+
+
+
+
+
diff --git a/libraries/stdlib/genosl/include/color4.h b/libraries/stdlib/genosl/include/color4.h
index bd05d639a2..78b06b24ec 100644
--- a/libraries/stdlib/genosl/include/color4.h
+++ b/libraries/stdlib/genosl/include/color4.h
@@ -182,6 +182,12 @@ color4 mix(color4 a, color4 b, float x )
mix(a.a, b.a, x));
}
+color4 mix(color4 a, color4 b, color4 x )
+{
+ return color4(mix(a.rgb, b.rgb, x.rgb),
+ mix(a.a, b.a, x.a));
+}
+
float dot(color4 a, color b)
{
return dot(a.rgb, b);
diff --git a/libraries/stdlib/genosl/include/vector2.h b/libraries/stdlib/genosl/include/vector2.h
index 1307ab40ab..f819dd142f 100644
--- a/libraries/stdlib/genosl/include/vector2.h
+++ b/libraries/stdlib/genosl/include/vector2.h
@@ -181,6 +181,11 @@ vector2 mix(vector2 a, vector2 b, float x )
return vector2 (mix(a.x, b.x, x), mix(a.y, b.y, x));
}
+vector2 mix(vector2 a, vector2 b, vector2 x )
+{
+ return vector2 (mix(a.x, b.x, x.x), mix(a.y, b.y, x.y));
+}
+
float dot(vector2 a, vector2 b)
{
return (a.x * b.x + a.y * b.y);
diff --git a/libraries/stdlib/genosl/include/vector4.h b/libraries/stdlib/genosl/include/vector4.h
index 667b001120..56b64b0c6a 100644
--- a/libraries/stdlib/genosl/include/vector4.h
+++ b/libraries/stdlib/genosl/include/vector4.h
@@ -208,6 +208,14 @@ vector4 mix(vector4 value1, vector4 value2, float x )
mix( value1.w, value2.w, x));
}
+vector4 mix(vector4 value1, vector4 value2, vector4 x )
+{
+ return vector4 (mix( value1.x, value2.x, x.x),
+ mix( value1.y, value2.y, x.y),
+ mix( value1.z, value2.z, x.z),
+ mix( value1.w, value2.w, x.w));
+}
+
vector vec4ToVec3(vector4 v)
{
return vector(v.x, v.y, v.z) / v.w;
diff --git a/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx b/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx
index 1677aecc1c..b7a1b0363c 100644
--- a/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx
+++ b/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx
@@ -602,10 +602,15 @@
+
+
+
+
+
diff --git a/libraries/stdlib/stdlib_defs.mtlx b/libraries/stdlib/stdlib_defs.mtlx
index 000344868c..d1f8c29468 100644
--- a/libraries/stdlib/stdlib_defs.mtlx
+++ b/libraries/stdlib/stdlib_defs.mtlx
@@ -3222,30 +3222,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/resources/Materials/TestSuite/stdlib/compositing/compositing.mtlx b/resources/Materials/TestSuite/stdlib/compositing/compositing.mtlx
index a2bd7d9a24..e7a742c581 100644
--- a/resources/Materials/TestSuite/stdlib/compositing/compositing.mtlx
+++ b/resources/Materials/TestSuite/stdlib/compositing/compositing.mtlx
@@ -282,11 +282,19 @@
-
+
+
+
+
+
+
+
+
+
-
+
@@ -298,6 +306,14 @@
+
+
+
+
+
+
+
+
@@ -306,6 +322,14 @@
+
+
+
+
+
+
+
+
@@ -314,6 +338,14 @@
+
+
+
+
+
+
+
+
diff --git a/source/MaterialXGenMdl/mdl/materialx/stdlib.mdl b/source/MaterialXGenMdl/mdl/materialx/stdlib.mdl
index 1e4db85eed..c7572f854b 100644
--- a/source/MaterialXGenMdl/mdl/materialx/stdlib.mdl
+++ b/source/MaterialXGenMdl/mdl/materialx/stdlib.mdl
@@ -3049,6 +3049,18 @@ export color4 mx_mix_color4(
return mk_color4(::math::lerp(mk_float4(mxp_bg), mk_float4(mxp_fg), float4(mxp_mix)));
}
+export color4 mx_mix_color4_color4(
+ color4 mxp_fg = mk_color4(0.0, 0.0, 0.0, 0.0),
+ color4 mxp_bg = mk_color4(0.0, 0.0, 0.0, 0.0),
+ color4 mxp_mix = mk_color4(0.0, 0.0, 0.0, 0.0)
+)
+ [[
+ anno::description("Node Group: compositing")
+ ]]
+{
+ return mk_color4(::math::lerp(mk_float4(mxp_bg), mk_float4(mxp_fg), mk_float4(mxp_mix)));
+}
+
export material mx_mix_surfaceshader(
material mxp_fg [[ anno::unused() ]],
material mxp_bg,
From 3a2ec1f709558bb70a144839e3998869470d5385 Mon Sep 17 00:00:00 2001
From: friedererdmann <55715326+friedererdmann@users.noreply.github.com>
Date: Wed, 14 Sep 2022 22:15:37 +0200
Subject: [PATCH 2/3] Removing goal document in favor of draft PR
---
goal.md | 16 ----------------
1 file changed, 16 deletions(-)
delete mode 100644 goal.md
diff --git a/goal.md b/goal.md
deleted file mode 100644
index 335d79dbf1..0000000000
--- a/goal.md
+++ /dev/null
@@ -1,16 +0,0 @@
-# Extending `mix` node to allow per channel mixing
-
-The mix node's mix input should allow for all data formats as input and do a per element linear interpolation, not just float.
-
-```
-in1 = Vector2(1,1)
-in2 = Vector2(0,0)
-mix = Vector2(1,0)
-out = Vector2(1,0)
-```
-
-Backwards compatibility means float needs to remain supported.
-
-Adding node definitions with the extra suffix of the mix data type like `ND_mix_color3_color3`.
-
-
From 31a4f206fbe399b6bb1282b9187bed174036732f Mon Sep 17 00:00:00 2001
From: friedererdmann <55715326+friedererdmann@users.noreply.github.com>
Date: Mon, 26 Sep 2022 20:41:37 +0200
Subject: [PATCH 3/3] changed mdl output to use c4_c4 function
---
libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx b/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
index 0ea537a310..0f89e7bdcc 100644
--- a/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
+++ b/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
@@ -607,7 +607,7 @@
-
+