From 5def239b82c20a7bf4875686e03743bc421a68f6 Mon Sep 17 00:00:00 2001 From: Frieder Erdmann <55715326+friedererdmann@users.noreply.github.com> Date: Thu, 4 Jan 2024 04:03:03 +0100 Subject: [PATCH] Add creatematrix nodes to build matrices from vectors (#1553) I'm opening this PR to add creatematrix, a constructor for Matrix33 from 3 Vector3s, Matrix44 from 4 Vector3s and Matrix44 from 4 Vector4s from the specification document (https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/documents/Specification/MaterialX.Specification.md#math-nodes). --- .../mx_creatematrix_vector3_matrix33.glsl | 6 +++ .../mx_creatematrix_vector3_matrix44.glsl | 7 ++++ .../mx_creatematrix_vector4_matrix44.glsl | 7 ++++ .../stdlib/genglsl/stdlib_genglsl_impl.mtlx | 5 +++ .../stdlib/genmdl/stdlib_genmdl_impl.mtlx | 5 +++ .../stdlib/genmsl/stdlib_genmsl_impl.mtlx | 5 +++ libraries/stdlib/genosl/mx_creatematrix.osl | 23 +++++++++++ .../stdlib/genosl/stdlib_genosl_impl.mtlx | 5 +++ libraries/stdlib/stdlib_defs.mtlx | 27 +++++++++++++ .../TestSuite/stdlib/math/matrix.mtlx | 29 ++++++++++++++ .../MaterialXGenMdl/mdl/materialx/stdlib.mdl | 40 +++++++++++++++++++ 11 files changed, 159 insertions(+) create mode 100644 libraries/stdlib/genglsl/mx_creatematrix_vector3_matrix33.glsl create mode 100644 libraries/stdlib/genglsl/mx_creatematrix_vector3_matrix44.glsl create mode 100644 libraries/stdlib/genglsl/mx_creatematrix_vector4_matrix44.glsl create mode 100644 libraries/stdlib/genosl/mx_creatematrix.osl create mode 100644 resources/Materials/TestSuite/stdlib/math/matrix.mtlx diff --git a/libraries/stdlib/genglsl/mx_creatematrix_vector3_matrix33.glsl b/libraries/stdlib/genglsl/mx_creatematrix_vector3_matrix33.glsl new file mode 100644 index 0000000000..aa10ef5b98 --- /dev/null +++ b/libraries/stdlib/genglsl/mx_creatematrix_vector3_matrix33.glsl @@ -0,0 +1,6 @@ +void mx_creatematrix_vector3_matrix33(vec3 in1, vec3 in2, vec3 in3, out mat3 result) +{ + result = mat3(in1.x, in1.y, in1.z, + in2.x, in2.y, in2.z, + in3.x, in3.y, in3.z); +} diff --git a/libraries/stdlib/genglsl/mx_creatematrix_vector3_matrix44.glsl b/libraries/stdlib/genglsl/mx_creatematrix_vector3_matrix44.glsl new file mode 100644 index 0000000000..194fad421a --- /dev/null +++ b/libraries/stdlib/genglsl/mx_creatematrix_vector3_matrix44.glsl @@ -0,0 +1,7 @@ +void mx_creatematrix_vector3_matrix44(vec3 in1, vec3 in2, vec3 in3, vec3 in4, out mat4 result) +{ + result = mat4(in1.x, in1.y, in1.z, 0.0, + in2.x, in2.y, in2.z, 0.0, + in3.x, in3.y, in3.z, 0.0, + in4.x, in4.y, in4.z, 1.0); +} diff --git a/libraries/stdlib/genglsl/mx_creatematrix_vector4_matrix44.glsl b/libraries/stdlib/genglsl/mx_creatematrix_vector4_matrix44.glsl new file mode 100644 index 0000000000..665a22212b --- /dev/null +++ b/libraries/stdlib/genglsl/mx_creatematrix_vector4_matrix44.glsl @@ -0,0 +1,7 @@ +void mx_creatematrix_vector4_matrix44(vec4 in1, vec4 in2, vec4 in3, vec4 in4, out mat4 result) +{ + result = mat4(in1.x, in1.y, in1.z, in1.w, + in2.x, in2.y, in2.z, in2.w, + in3.x, in3.y, in3.z, in3.w, + in4.x, in4.y, in4.z, in4.w); +} diff --git a/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx b/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx index 07aae6ce66..6f67b21d33 100644 --- a/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx +++ b/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx @@ -748,6 +748,11 @@ + + + + + diff --git a/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx b/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx index 022f0896f1..6c550c92db 100644 --- a/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx +++ b/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx @@ -754,6 +754,11 @@ + + + + + diff --git a/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx b/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx index dea1c49636..40be6f8c46 100644 --- a/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx +++ b/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx @@ -748,6 +748,11 @@ + + + + + diff --git a/libraries/stdlib/genosl/mx_creatematrix.osl b/libraries/stdlib/genosl/mx_creatematrix.osl new file mode 100644 index 0000000000..933dce00ba --- /dev/null +++ b/libraries/stdlib/genosl/mx_creatematrix.osl @@ -0,0 +1,23 @@ +void mx_creatematrix_vector3_matrix33(vector in1, vector in2, vector in3, out matrix result) +{ + result = matrix(in1.x, in1.y, in1.z, 0.0, + in2.x, in2.y, in2.z, 0.0, + in3.x, in3.y, in3.z, 0.0, + 0.0, 0.0, 0.0, 1.0); +} + +void mx_creatematrix_vector3_matrix44(vector3 in1, vector3 in2, vector3 in3, vector3 in4, out matrix result) +{ + result = matrix(in1.x, in1.y, in1.z, 0.0, + in2.x, in2.y, in2.z, 0.0, + in3.x, in3.y, in3.z, 0.0, + in4.x, in4.y, in4.z, 1.0); +} + +void mx_creatematrix_vector4_matrix44(vector4 in1, vector4 in2, vector4 in3, vector4 in4, out matrix result) +{ + result = matrix(in1.x, in1.y, in1.z, in1.w, + in2.x, in2.y, in2.z, in2.w, + in3.x, in3.y, in3.z, in3.w, + in4.x, in4.y, in4.z, in4.w); +} diff --git a/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx b/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx index 42828ce641..a984d912b8 100644 --- a/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx +++ b/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx @@ -751,6 +751,11 @@ + + + + + diff --git a/libraries/stdlib/stdlib_defs.mtlx b/libraries/stdlib/stdlib_defs.mtlx index 3f187e2be1..90ccb57a98 100644 --- a/libraries/stdlib/stdlib_defs.mtlx +++ b/libraries/stdlib/stdlib_defs.mtlx @@ -4359,6 +4359,33 @@ + + + + + + + + + + + + + + + + + + + + + + + +