Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add creatematrix nodes to build matrices from vectors #1553

Merged
merged 25 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
11599c0
Added constructor for Matrix33 from 3 Vector3s
friedererdmann Oct 5, 2023
08a6d57
fixed typo in genosl_impl
friedererdmann Oct 5, 2023
e55cd26
fixed missing xml end tag in genmsl
friedererdmann Oct 5, 2023
a5119c7
renamed node to creatematrix
friedererdmann Oct 5, 2023
fb071c4
Implemented missing interface, various bug fixes
friedererdmann Oct 10, 2023
eab31db
Added matrix44 nodes to test material
friedererdmann Oct 10, 2023
28cce2d
fixed glsl and msl duplicate file import
friedererdmann Oct 11, 2023
71b8efa
formal test cases for creatematrix implementations
friedererdmann Oct 11, 2023
a20052b
fixed nodedef name, fixed test output
friedererdmann Oct 11, 2023
1ebc4d9
fixed mdl call
friedererdmann Oct 11, 2023
43ca8cf
fixed include statement in osl code
friedererdmann Oct 11, 2023
c871d4f
removed include of matrix33 in osl
friedererdmann Oct 11, 2023
d7b0264
fixed typo in signature of osl
friedererdmann Oct 11, 2023
cc7df02
Merge branch 'main' into main
jstone-lucasfilm Oct 15, 2023
8f6c0c8
Remove extra newlines
jstone-lucasfilm Oct 15, 2023
ace738c
Merge branch 'main' into main
jstone-lucasfilm Oct 17, 2023
307755f
Merge branch 'main' into main
jstone-lucasfilm Nov 1, 2023
76f6eb4
Remove UI properties
jstone-lucasfilm Nov 1, 2023
cf770c5
Fix typo
jstone-lucasfilm Nov 1, 2023
6d98ae3
Add newline
jstone-lucasfilm Nov 1, 2023
d68ce31
Remove extra newline
jstone-lucasfilm Nov 1, 2023
50f5188
Use non-zero test inputs
jstone-lucasfilm Nov 1, 2023
dc6438f
Merge branch 'main' into main
jstone-lucasfilm Nov 29, 2023
a1be340
Merge branch 'main' into main
jstone-lucasfilm Jan 4, 2024
c7e788d
Use standard output names
jstone-lucasfilm Jan 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}
5 changes: 5 additions & 0 deletions libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,11 @@
<implementation name="IM_combine4_color4_genglsl" nodedef="ND_combine4_color4" target="genglsl" />
<implementation name="IM_combine4_vector4_genglsl" nodedef="ND_combine4_vector4" target="genglsl" />

<!-- <creatematrix> -->
<implementation name="IM_creatematrix_vector3_matrix33_genglsl" nodedef="ND_creatematrix_vector3_matrix33" file="mx_creatematrix_vector3_matrix33.glsl" function="mx_creatematrix_vector3_matrix33" target="genglsl" />
<implementation name="IM_creatematrix_vector3_matrix44_genglsl" nodedef="ND_creatematrix_vector3_matrix44" file="mx_creatematrix_vector3_matrix44.glsl" function="mx_creatematrix_vector3_matrix44" target="genglsl" />
<implementation name="IM_creatematrix_vector4_matrix44_genglsl" nodedef="ND_creatematrix_vector4_matrix44" file="mx_creatematrix_vector4_matrix44.glsl" function="mx_creatematrix_vector4_matrix44" target="genglsl" />

<!-- ======================================================================== -->
<!-- Convolution nodes -->
<!-- ======================================================================== -->
Expand Down
5 changes: 5 additions & 0 deletions libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,11 @@
<implementation name="IM_combine4_color4_genmdl" nodedef="ND_combine4_color4" target="genmdl" />
<implementation name="IM_combine4_vector4_genmdl" nodedef="ND_combine4_vector4" target="genmdl" />

<!-- <creatematrix> -->
<implementation name="IM_creatematrix_vector3_matrix33_genmdl" nodedef="ND_creatematrix_vector3_matrix33" sourcecode="mx::stdlib::mx_creatematrix_vector3_matrix33({{in1}}, {{in2}}, {{in3}})" target="genmdl" />
<implementation name="IM_creatematrix_vector3_matrix44_genmdl" nodedef="ND_creatematrix_vector3_matrix44" sourcecode="mx::stdlib::mx_creatematrix_vector3_matrix44({{in1}}, {{in2}}, {{in3}}, {{in4}})" target="genmdl" />
<implementation name="IM_creatematrix_vector4_matrix44_genmdl" nodedef="ND_creatematrix_vector4_matrix44" sourcecode="mx::stdlib::mx_creatematrix_vector4_matrix44({{in1}}, {{in2}}, {{in3}}, {{in4}})" target="genmdl" />

<!-- ======================================================================== -->
<!-- Convolution nodes -->
<!-- ======================================================================== -->
Expand Down
5 changes: 5 additions & 0 deletions libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,11 @@
<implementation name="IM_combine4_color4_genmsl" nodedef="ND_combine4_color4" target="genmsl" />
<implementation name="IM_combine4_vector4_genmsl" nodedef="ND_combine4_vector4" target="genmsl" />

<!-- <creatematrix> -->
<implementation name="IM_creatematrix_vector3_matrix33_genmsl" nodedef="ND_creatematrix_vector3_matrix33" file="../genglsl/mx_creatematrix_vector3_matrix33.glsl" function="mx_creatematrix_vector3_matrix33" nodegroup="genmsl" />
<implementation name="IM_creatematrix_vector3_matrix44_genmsl" nodedef="ND_creatematrix_vector3_matrix44" file="../genglsl/mx_creatematrix_vector3_matrix44.glsl" function="mx_creatematrix_vector3_matrix44" nodegroup="genmsl" />
<implementation name="IM_creatematrix_vector4_matrix44_genmsl" nodedef="ND_creatematrix_vector4_matrix44" file="../genglsl/mx_creatematrix_vector4_matrix44.glsl" function="mx_creatematrix_vector4_matrix44" nodegroup="genmsl" />

<!-- ======================================================================== -->
<!-- Convolution nodes -->
<!-- ======================================================================== -->
Expand Down
23 changes: 23 additions & 0 deletions libraries/stdlib/genosl/mx_creatematrix.osl
Original file line number Diff line number Diff line change
@@ -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);
}
5 changes: 5 additions & 0 deletions libraries/stdlib/genosl/stdlib_genosl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,11 @@
<implementation name="IM_combine4_color4_genosl" nodedef="ND_combine4_color4" target="genosl" />
<implementation name="IM_combine4_vector4_genosl" nodedef="ND_combine4_vector4" target="genosl" />

<!-- <creatematrix> -->
<implementation name="IM_creatematrix_vector3_matrix33_genosl" nodedef="ND_creatematrix_vector3_matrix33" file="mx_creatematrix.osl" function="mx_creatematrix_vector3_matrix33" nodegroup="genosl" />
<implementation name="IM_creatematrix_vector3_matrix44_genosl" nodedef="ND_creatematrix_vector3_matrix44" file="mx_creatematrix.osl" function="mx_creatematrix_vector3_matrix44" nodegroup="genosl" />
<implementation name="IM_creatematrix_vector4_matrix44_genosl" nodedef="ND_creatematrix_vector4_matrix44" file="mx_creatematrix.osl" function="mx_creatematrix_vector4_matrix44" nodegroup="genosl" />

<!-- ======================================================================== -->
<!-- Convolution nodes -->
<!-- ======================================================================== -->
Expand Down
27 changes: 27 additions & 0 deletions libraries/stdlib/stdlib_defs.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -4359,6 +4359,33 @@
<output name="out" type="vector4" default="0.0, 0.0, 0.0, 0.0" />
</nodedef>

<!--
Node <creatematrix>
Combine the the three vectors3 from stream into a matrix 33.
-->
<nodedef name="ND_creatematrix_vector3_matrix33" node="creatematrix" nodegroup="math">
<input name="in1" type="vector3" value="1.0, 0.0, 0.0" />
<input name="in2" type="vector3" value="0.0, 1.0, 0.0" />
<input name="in3" type="vector3" value="0.0, 0.0, 1.0" />
<output name="out" type="matrix33" default="1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0" />
</nodedef>

<nodedef name="ND_creatematrix_vector3_matrix44" node="creatematrix" nodegroup="math">
<input name="in1" type="vector3" value="1.0, 0.0, 0.0" />
<input name="in2" type="vector3" value="0.0, 1.0, 0.0" />
<input name="in3" type="vector3" value="0.0, 0.0, 1.0" />
<input name="in4" type="vector3" value="0.0, 0.0, 0.0" />
<output name="out" type="matrix44" default="1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0" />
</nodedef>

<nodedef name="ND_creatematrix_vector4_matrix44" node="creatematrix" nodegroup="math">
<input name="in1" type="vector4" value="1.0, 0.0, 0.0, 0.0" />
<input name="in2" type="vector4" value="0.0, 1.0, 0.0, 0.0" />
<input name="in3" type="vector4" value="0.0, 0.0, 1.0, 0.0" />
<input name="in4" type="vector4" value="0.0, 0.0, 0.0, 1.0" />
<output name="out" type="matrix44" default="1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0" />
</nodedef>

<!--
Node: <extract> Supplemental Node
Extract a single channel from a colorN or vectorN stream, outputting a float.
Expand Down
29 changes: 29 additions & 0 deletions resources/Materials/TestSuite/stdlib/math/matrix.mtlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<materialx version="1.38">
<nodegraph name="creatematrix_vector3_matrix33">
<creatematrix name="creatematrix_vector3_matrix33" type="matrix33">
<input name="in1" type="vector3" value="1, 0, 0" />
<input name="in2" type="vector3" value="0, 1, 0" />
<input name="in3" type="vector3" value="0, 0, 1" />
</creatematrix>
<output name="out" type="matrix33" nodename="creatematrix_vector3_matrix33" />
</nodegraph>
<nodegraph name="creatematrix_vector3_matrix44">
<creatematrix name="creatematrix_vector3_matrix44" type="matrix44">
<input name="in1" type="vector3" value="1, 0, 0" />
<input name="in2" type="vector3" value="0, 1, 0" />
<input name="in3" type="vector3" value="0, 0, 1" />
<input name="in4" type="vector3" value="0, 0, 0" />
</creatematrix>
<output name="out" type="matrix44" nodename="creatematrix_vector3_matrix44" />
</nodegraph>
<nodegraph name="creatematrix_vector4_matrix44">
<creatematrix name="creatematrix_vector4_matrix44" type="matrix44">
<input name="in1" type="vector4" value="1, 0, 0, 0" />
<input name="in2" type="vector4" value="0, 1, 0, 0" />
<input name="in3" type="vector4" value="0, 0, 1, 0" />
<input name="in4" type="vector4" value="0, 0, 0, 1" />
</creatematrix>
<output name="out" type="matrix44" nodename="creatematrix_vector4_matrix44" />
</nodegraph>
</materialx>
40 changes: 40 additions & 0 deletions source/MaterialXGenMdl/mdl/materialx/stdlib.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -4147,6 +4147,46 @@ export float4 mx_combine4_vector4(
return float4(mxp_in1, mxp_in2, mxp_in3, mxp_in4);
}

export float3x3 mx_creatematrix_vector3_matrix33(
float3 mxp_in1 = float3(1.0, 0.0, 0.0),
float3 mxp_in2 = float3(0.0, 1.0, 0.0),
float3 mxp_in3 = float3(0.0, 0.0, 1.0)
)
[[
anno::description("Node Group: math")
]]
{
return float3x3(mxp_in1[0],mxp_in1[1],mxp_in1[2],mxp_in2[0],mxp_in2[1],mxp_in2[2],mxp_in3[0],mxp_in3[1],mxp_in3[2]);
}


export float4x4 mx_creatematrix_vector3_matrix44(
float3 mxp_in1 = float3(1.0, 0.0, 0.0),
float3 mxp_in2 = float3(0.0, 1.0, 0.0),
float3 mxp_in3 = float3(0.0, 0.0, 1.0)
float3 mxp_in4 = float3(0.0, 0.0, 0.0)
)
[[
anno::description("Node Group: math")
]]
{
return float4x4(mxp_in1[0],mxp_in1[1],mxp_in1[2],0.0, mxp_in2[0],mxp_in2[1],mxp_in2[2],0.0, mxp_in3[0],mxp_in3[1],mxp_in3[2]0.0, mxp_in4[0],mxp_in4[1],mxp_in4[2],1.0);
}


export float4x4 mx_creatematrix_vector4_matrix44(
float4 mxp_in1 = float4(1.0, 0.0, 0.0, 0.0),
float4 mxp_in2 = float4(0.0, 1.0, 0.0, 0.0),
float4 mxp_in3 = float4(0.0, 0.0, 1.0, 0.0)
float4 mxp_in4 = float4(0.0, 0.0, 0.0, 1.0)
)
[[
anno::description("Node Group: math")
]]
{
return float4x4(mxp_in1[0],mxp_in1[1],mxp_in1[2],mxp_in1[3],mxp_in2[0],mxp_in2[1],mxp_in2[2],mxp_in2[3],mxp_in3[0],mxp_in3[1],mxp_in3[2],mxp_in3[3],mxp_in4[0],mxp_in4[1],mxp_in4[2],mxp_in4[3]);
}

// Nodedef: ND_extract_color3 is represented by a nodegraph: NG_extract_color3
// Nodedef: ND_extract_color4 is represented by a nodegraph: NG_extract_color4
// Nodedef: ND_extract_vector2 is represented by a nodegraph: NG_extract_vector2
Expand Down