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 refract node #1698

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
12 changes: 12 additions & 0 deletions libraries/stdlib/stdlib_defs.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -2761,6 +2761,18 @@
<output name="out" type="vector3" />
</nodedef>

<!--
Node: <refract>
Compute the refraction direction of an input vector against a normal vector.
The normal vector is assumed to be normalized.
-->
<nodedef name="ND_refract_vector3" node="refract" nodegroup="math" doc="Compute the refraction direction of an input vector.">
<input name="in" type="vector3" value="1.0,0.0,0.0" doc="Input vector to be reflected." />
jstone-lucasfilm marked this conversation as resolved.
Show resolved Hide resolved
<input name="normal" type="vector3" defaultgeomprop="Nworld" doc="Normal vector." />
<input name="eta" type="float" value="1.0" doc="Ratio of the indices of refraction."/>
jstone-lucasfilm marked this conversation as resolved.
Show resolved Hide resolved
<output name="out" type="vector3" />
</nodedef>

<!-- ======================================================================== -->
<!-- Adjustment nodes -->
<!-- ======================================================================== -->
Expand Down
62 changes: 62 additions & 0 deletions libraries/stdlib/stdlib_ng.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -2728,6 +2728,68 @@
<output name="out" type="vector3" nodename="reflection_vector" />
</nodegraph>

<!--
Node: <refract>
Compute the refraction direction of an input vector against a normal vector.
The normal vector is assumed to be normalized.
-->
<nodegraph name="NG_refract_vector3" nodedef="ND_refract_vector3">
<dotproduct name="IdotN" type="float">
<input name="in1" type="vector3" interfacename="in"/>
<input name="in2" type="vector3" interfacename="normal"/>
</dotproduct>
<multiply name="IdotNsq" type="float">
<input name="in1" type="float" nodename="IdotN"/>
<input name="in2" type="float" nodename="IdotN"/>
</multiply>
<multiply name="etasq" type="float">
<input name="in1" type="float" interfacename="eta"/>
<input name="in2" type="float" interfacename="eta"/>
</multiply>
<subtract name="one_IdotNsq" type="float">
<input name="in1" type="float" value="1.0"/>
<input name="in2" type="float" nodename="IdotNsq"/>
</subtract>
<multiply name="etasq_one_IdotNsq" type="float">
<input name="in1" type="float" nodename="etasq"/>
<input name="in2" type="float" nodename="one_IdotNsq"/>
</multiply>
<subtract name="k" type="float">
<input name="in1" type="float" value="1.0"/>
<input name="in2" type="float" nodename="etasq_one_IdotNsq"/>
</subtract>
<multiply name="I_scaled" type="vector3">
<input name="in1" type="vector3" interfacename="in"/>
<input name="in2" type="float" interfacename="eta"/>
</multiply>
<sqrt name="sqrt_k" type="float">
<input name="in" type="float" nodename="k"/>
</sqrt>
<multiply name="eta_NdotI" type="float">
<input name="in1" type="float" interfacename="eta"/>
<input name="in2" type="float" nodename="IdotN"/>
</multiply>
<add name="eta_NdotI_sqrt_k" type="float">
<input name="in1" type="float" nodename="eta_NdotI"/>
<input name="in2" type="float" nodename="sqrt_k"/>
</add>
<multiply name="N_scaled" type="vector3">
<input name="in1" type="vector3" interfacename="normal"/>
<input name="in2" type="float" nodename="eta_NdotI_sqrt_k"/>
</multiply>
<subtract name="refract_dir" type="vector3">
<input name="in1" type="vector3" nodename="I_scaled"/>
<input name="in2" type="vector3" nodename="N_scaled"/>
</subtract>
<ifgreater name="result" type="vector3">
<input name="value1" type="float" value="0.0"/>
<input name="value2" type="float" nodename="k"/>
<input name="in1" type="vector3" value="0.0, 0.0, 0.0"/>
<input name="in2" type="vector3" nodename="refract_dir"/>
</ifgreater>
<output name="out" type="vector3" nodename="result"/>
</nodegraph>

<!-- ======================================================================== -->
<!-- Adjustment nodes -->
<!-- ======================================================================== -->
Expand Down
Loading