Skip to content

Commit

Permalink
Optimize hexagon computation
Browse files Browse the repository at this point in the history
  • Loading branch information
jstone-lucasfilm committed Jul 24, 2023
1 parent bd5ecd6 commit 3f2ca3e
Showing 1 changed file with 41 additions and 58 deletions.
99 changes: 41 additions & 58 deletions libraries/stdlib/stdlib_ng.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -1519,63 +1519,43 @@
Uses formulas from Inigo Quilez SDF samples (iquilezles.org)
-->
<nodegraph name="NG_hexagon_float" nodedef="ND_hexagon_float">
<subtract name="dist" type="vector2">
<subtract name="delta" type="vector2">
<input name="in1" type="vector2" interfacename="sample" />
<input name="in2" type="vector2" interfacename="center" />
</subtract>
<absval name="absval_p" type="vector2">
<input name="in" type="vector2" nodename="dist" />
<absval name="delta_abs" type="vector2">
<input name="in" type="vector2" nodename="delta" />
</absval>
<separate2 name="separate_p" type="multioutput">
<input name="in" type="vector2" nodename="absval_p" />
</separate2>
<combine2 name="combine_p" type="vector2">
<input name="in1" type="float" nodename="separate_p" output="outy" />
<input name="in2" type="float" nodename="separate_p" output="outx" />
<combine2 name="p" type="vector2">
<input name="in1" type="float" nodename="delta_abs" channels="y" />
<input name="in2" type="float" nodename="delta_abs" channels="x" />
</combine2>
<constant name="k_x" type="float">
<input name="value" type="float" value="-0.866025" />
</constant>
<constant name="k_y" type="float">
<input name="value" type="float" value="0.5" />
<constant name="k" type="vector3">
<input name="value" type="vector3" value="-0.866025, 0.5, 0.57735" />
</constant>
<constant name="k_z" type="float">
<input name="value" type="float" value="0.57735" />
</constant>
<combine2 name="combine_kxy" type="vector2">
<input name="in1" type="float" nodename="k_x" />
<input name="in2" type="float" nodename="k_y" />
</combine2>
<subtract name="minus_kx" type="float">
<input name="in2" type="float" nodename="k_x" />
</subtract>
<subtract name="minus_kz" type="float">
<input name="in2" type="float" nodename="k_z" />
</subtract>
<multiply name="minus_kz_r" type="float">
<input name="in1" type="float" nodename="minus_kz" />
<multiply name="kz_r1" type="float">
<input name="in1" type="float" nodename="k" channels="z" />
<input name="in2" type="float" interfacename="radius" />
</multiply>
<multiply name="kz_r1" type="float">
<input name="in1" type="float" nodename="k_z" />
<multiply name="minus_k" type="vector3">
<input name="in1" type="vector3" nodename="k" />
<input name="in2" type="float" value="-1.0" />
</multiply>
<multiply name="minus_kz_r" type="float">
<input name="in1" type="float" nodename="minus_k" channels="z" />
<input name="in2" type="float" interfacename="radius" />
</multiply>
<clamp name="clamp" type="float">
<input name="in" type="float" nodename="separate_p2" output="outx" />
<input name="low" type="float" nodename="minus_kz_r" />
<input name="high" type="float" nodename="kz_r1" />
</clamp>
<combine2 name="combine_mkx_ky" type="vector2">
<input name="in1" type="float" nodename="minus_kx" />
<input name="in2" type="float" nodename="k_y" />
<input name="in1" type="float" nodename="minus_k" channels="x" />
<input name="in2" type="float" nodename="k" channels="y" />
</combine2>
<combine2 name="combine_clamp_rad" type="vector2">
<input name="in1" type="float" nodename="clamp" />
<input name="in2" type="float" interfacename="radius" />
<combine2 name="kxy" type="vector2">
<input name="in1" type="float" nodename="k" channels="x" />
<input name="in2" type="float" nodename="k" channels="y" />
</combine2>
<dotproduct name="dot_kxy_p" type="float">
<input name="in1" type="vector2" nodename="combine_kxy" />
<input name="in2" type="vector2" nodename="combine_p" />
<input name="in1" type="vector2" nodename="kxy" />
<input name="in2" type="vector2" nodename="p" />
</dotproduct>
<dotproduct name="dot_kxy_p1" type="float">
<input name="in1" type="vector2" nodename="combine_mkx_ky" />
Expand All @@ -1588,7 +1568,7 @@
<input name="in1" type="float" nodename="dot_kxy_p1" />
</min>
<multiply name="multiply_kxy_min" type="vector2">
<input name="in1" type="vector2" nodename="combine_kxy" />
<input name="in1" type="vector2" nodename="kxy" />
<input name="in2" type="float" nodename="min_dotkxyp_p" />
</multiply>
<multiply name="multiply2_1" type="vector2">
Expand All @@ -1603,8 +1583,17 @@
<input name="in1" type="vector2" nodename="multiply_min_comb" />
<input name="in2" type="float" value="2" />
</multiply>
<clamp name="clamp" type="float">
<input name="in" type="float" nodename="new_p2" channels="x" />
<input name="low" type="float" nodename="minus_kz_r" />
<input name="high" type="float" nodename="kz_r1" />
</clamp>
<combine2 name="combine_clamp_rad" type="vector2">
<input name="in1" type="float" nodename="clamp" />
<input name="in2" type="float" interfacename="radius" />
</combine2>
<subtract name="new_p1" type="vector2">
<input name="in1" type="vector2" nodename="combine_p" />
<input name="in1" type="vector2" nodename="p" />
<input name="in2" type="vector2" nodename="multiply2_1" />
</subtract>
<subtract name="new_p2" type="vector2">
Expand All @@ -1615,21 +1604,15 @@
<input name="in1" type="vector2" nodename="new_p2" />
<input name="in2" type="vector2" nodename="combine_clamp_rad" />
</subtract>
<separate2 name="separate_p2" type="multioutput">
<input name="in" type="vector2" nodename="new_p2" />
</separate2>
<separate2 name="separate_p3" type="multioutput">
<input name="in" type="vector2" nodename="new_p3" />
</separate2>
<add name="add_p3" type="float">
<input name="in1" type="float" nodename="separate_p3" output="outx" />
<input name="in2" type="float" nodename="separate_p3" output="outy" />
</add>
<sqrt name="sqrt_p3" type="float">
<input name="in" type="float" nodename="add_p3" />
<dotproduct name="p3_sum" type="float">
<input name="in1" type="vector2" nodename="new_p3" />
<input name="in2" type="vector2" value="1, 1" />
</dotproduct>
<sqrt name="p3_sqrt" type="float">
<input name="in" type="float" nodename="p3_sum" />
</sqrt>
<ifgreater name="ifgreater_p3" type="float">
<input name="value1" type="float" nodename="sqrt_p3" />
<input name="value1" type="float" nodename="p3_sqrt" />
<input name="value2" type="float" value="0" />
<input name="in1" type="float" value="0" />
<input name="in2" type="float" value="1" />
Expand Down

0 comments on commit 3f2ca3e

Please sign in to comment.