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 all commits
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
11 changes: 11 additions & 0 deletions libraries/stdlib/stdlib_defs.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -2761,6 +2761,17 @@
<output name="out" type="vector3" />
</nodedef>

<!--
Node: <refract>
Compute the refraction vector given an incident vector, unit surface normal, and index of refraction.
-->
<nodedef name="ND_refract_vector3" node="refract" nodegroup="math" doc="Compute the refraction vector">
<input name="in" type="vector3" value="1.0, 0.0, 0.0" doc="Incident vector" />
<input name="normal" type="vector3" defaultgeomprop="Nworld" doc="Surface normal" />
<input name="ior" type="float" value="1.0" doc="Index of refraction" />
<output name="out" type="vector3" />
</nodedef>

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

<!--
Node: <refract>
Compute the refraction vector given an incident vector, unit surface normal, and index of refraction.
-->
<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="iorsq" type="float">
<input name="in1" type="float" interfacename="ior"/>
<input name="in2" type="float" interfacename="ior"/>
</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="iorsq_one_IdotNsq" type="float">
<input name="in1" type="float" nodename="iorsq"/>
<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="iorsq_one_IdotNsq"/>
</subtract>
<multiply name="I_scaled" type="vector3">
<input name="in1" type="vector3" interfacename="in"/>
<input name="in2" type="float" interfacename="ior"/>
</multiply>
<sqrt name="sqrt_k" type="float">
<input name="in" type="float" nodename="k"/>
</sqrt>
<multiply name="ior_NdotI" type="float">
<input name="in1" type="float" interfacename="ior"/>
<input name="in2" type="float" nodename="IdotN"/>
</multiply>
<add name="ior_NdotI_sqrt_k" type="float">
<input name="in1" type="float" nodename="ior_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="ior_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