Skip to content

Commit

Permalink
Provide a frame transform for UV texture coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
vernalchen committed Jul 11, 2022
1 parent 5ca38d7 commit 6d672c6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
15 changes: 15 additions & 0 deletions libraries/stdlib/stdlib_defs.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -2333,6 +2333,7 @@
<!--
Node: <place2d> Supplemental Node
Transform incoming UV texture coordinates for 2D texture placement.
Sequence of transformation (in the order of application): -pivot, scale, rotate, translate, pivot.
-->
<nodedef name="ND_place2d_vector2" node="place2d" nodegroup="math">
<input name="texcoord" type="vector2" value="0.0, 0.0" />
Expand All @@ -2343,6 +2344,20 @@
<output name="out" type="vector2" defaultinput="texcoord" />
</nodedef>

<!--
Node: <place2dframe> Supplemental Node
Transform incoming UV texture coordinates for 2D texture placement.
Sequence of transformation (in the order of application): -pivot, translate, rotate, scale, pivot.
-->
<nodedef name="ND_place2dframe_vector2" node="place2dframe" nodegroup="math">
<input name="texcoord" type="vector2" value="0.0, 0.0" />
<input name="pivot" type="vector2" value="0.0,0.0" />
<input name="scale" type="vector2" value="1.0,1.0" />
<input name="rotate" type="float" value="0.0" unittype="angle" unit="degree" />
<input name="offset" type="vector2" value="0.0,0.0" />
<output name="out" type="vector2" defaultinput="texcoord" />
</nodedef>

<!--
Node: <arrayappend>
Creates a two-element array from two base types, or appends a base-type value to an array of
Expand Down
30 changes: 30 additions & 0 deletions libraries/stdlib/stdlib_ng.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,7 @@
<!--
Node: <place2d>
Transform incoming UV texture coordinates for 2D texture placement.
Sequence of transformation (in the order of application): -pivot, scale, rotate, translate, pivot.
-->
<nodegraph name="NG_place2d_vector2" nodedef="ND_place2d_vector2">
<subtract name="N_subpivot" type="vector2">
Expand All @@ -1071,6 +1072,35 @@
<output name="out" type="vector2" nodename="N_addpivot" />
</nodegraph>

<!--
Node: <place2dframe>
Transform incoming UV texture coordinates for 2D texture placement.
Sequence of transformation (in the order of application): -pivot, translate, rotate, scale, pivot.
-->
<nodegraph name="NG_place2dframe_vector2" nodedef="ND_place2dframe_vector2">
<subtract name="N_subpivot" type="vector2">
<input name="in1" type="vector2" interfacename="texcoord" />
<input name="in2" type="vector2" interfacename="pivot" />
</subtract>
<subtract name="N_applyoffset" type="vector2">
<input name="in1" type="vector2" nodename="N_subpivot" />
<input name="in2" type="vector2" interfacename="offset" />
</subtract>
<rotate2d name="N_applyrot" type="vector2">
<input name="in" type="vector2" nodename="N_applyoffset" />
<input name="amount" type="float" interfacename="rotate" />
</rotate2d>
<divide name="N_applyscale" type="vector2">
<input name="in1" type="vector2" nodename="N_applyrot" />
<input name="in2" type="vector2" interfacename="scale" />
</divide>
<add name="N_addpivot" type="vector2">
<input name="in1" type="vector2" nodename="N_applyscale" />
<input name="in2" type="vector2" interfacename="pivot" />
</add>
<output name="out" type="vector2" nodename="N_addpivot" />
</nodegraph>

<!-- ======================================================================== -->
<!-- Adjustment nodes -->
<!-- ======================================================================== -->
Expand Down
14 changes: 14 additions & 0 deletions resources/Materials/TestSuite/stdlib/math/transform.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,18 @@
</place2d>
<output name="out" type="vector2" nodename="place2d1_1" />
</nodegraph>
<!-- place2dframe -->
<nodegraph name="place2dframe_vector2">
<texcoord name="texcoord1" type="vector2">
<input name="index" type="integer" value="0" />
</texcoord>
<place2dframe name="place2d1_1" type="vector2">
<input name="texcoord" type="vector2" nodename="texcoord1" />
<input name="pivot" type="vector2" value="0.5,0.5" />
<input name="scale" type="vector2" value="2.0,1.0" />
<input name="rotate" type="float" value="1.0" unittype="angle" unit="radian" />
<input name="offset" type="vector2" value="0.2,0.2" />
</place2dframe>
<output name="out" type="vector2" nodename="place2d1_1" />
</nodegraph>
</materialx>

0 comments on commit 6d672c6

Please sign in to comment.