Skip to content

Commit

Permalink
Add Gooch Shading node to NPR library (#1674)
Browse files Browse the repository at this point in the history
Initial implementation of a gooch_shade node to the NPR data library that represents Gooch Shading used for technical illustration.
  • Loading branch information
ashwinbhat authored Jan 31, 2024
1 parent 2edc358 commit 7bec19f
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
13 changes: 13 additions & 0 deletions libraries/nprlib/nprlib_defs.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,17 @@
<output name="out" type="float" default="0.0" />
</nodedef>

<!--
Node: <gooch_shade>
Compute Gooch Shading.
-->
<nodedef name="ND_gooch_shade" node="gooch_shade" nodegroup="npr" doc="Compute Gooch shading">
<input name="warm_color" type="color3" value="0.8, 0.8, 0.7" uiname="Warm Color" doc="Warm color" />
<input name="cool_color" type="color3" value="0.3, 0.3, 0.8" uiname="Cool Color" doc="Cool color" />
<input name="specular_intensity" type="float" value="1" uimin="0" uimax="1" uiname="Specular Intensity" doc="Specular Intensity" />
<input name="shininess" type="float" value="64" uimin="1" uisoftmax="256" uiname="Shininess" doc="Specular Power" />
<input name="light_direction" type="vector3" value="1, -0.5, -0.5" uiname="Light Direction" doc="Light vector in world space" />
<output name="out" type="color3"/>
</nodedef>

</materialx>
75 changes: 75 additions & 0 deletions libraries/nprlib/nprlib_ng.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,79 @@
<output name="out" type="float" nodename="N_result" />
</nodegraph>

<!--
Node: <gooch_shade>
-->
<nodegraph name="NG_gooch_shade" type="color3" nodedef="ND_gooch_shade">
<normal name="normal" type="vector3" />
<viewdirection name="viewdir" type="vector3" />
<normalize name="unit_normal" type="vector3">
<input name="in" type="vector3" nodename="normal" />
</normalize>
<normalize name="unit_viewdir" type="vector3">
<input name="in" type="vector3" nodename="viewdir" />
</normalize>
<normalize name="unit_lightdir" type="vector3">
<input name="in" type="vector3" interfacename="light_direction" />
</normalize>
<dotproduct name="NdotL" type="float">
<input name="in1" type="vector3" nodename="unit_normal" />
<input name="in2" type="vector3" nodename="unit_lightdir" />
</dotproduct>
<add name="one_plus_NdotL" type="float">
<input name="in2" type="float" nodename="NdotL" />
<input name="in1" type="float" value="1" />
</add>
<divide name="cool_intensity" type="float">
<input name="in1" type="float" nodename="one_plus_NdotL" />
<input name="in2" type="float" value="2" />
</divide>
<mix name="diffuse" type="color3">
<input name="bg" type="color3" interfacename="warm_color" />
<input name="fg" type="color3" interfacename="cool_color" />
<input name="mix" type="float" nodename="cool_intensity" />
</mix>
<dotproduct name="NdotV" type="float">
<input name="in1" type="vector3" nodename="unit_normal" />
<input name="in2" type="vector3" nodename="unit_viewdir" />
</dotproduct>
<multiply name="NdotV_2" type="float">
<input name="in1" type="float" nodename="NdotV" />
<input name="in2" type="float" value="2" />
</multiply>
<multiply name="NdotV_N_2" type="vector3">
<input name="in1" type="vector3" nodename="unit_normal" />
<input name="in2" type="float" nodename="NdotV_2" />
</multiply>
<subtract name="view_reflect" type="vector3">
<input name="in1" type="vector3" nodename="unit_viewdir" />
<input name="in2" type="vector3" nodename="NdotV_N_2" />
</subtract>
<multiply name="invert_lightdir" type="vector3">
<input name="in1" type="vector3" nodename="unit_lightdir" />
<input name="in2" type="float" value="-1" />
</multiply>
<dotproduct name="VdotR" type="float">
<input name="in1" type="vector3" nodename="invert_lightdir" />
<input name="in2" type="vector3" nodename="view_reflect" />
</dotproduct>
<max name="VdotR_nonnegative" type="float">
<input name="in1" type="float" nodename="VdotR" />
<input name="in2" type="float" value="0" />
</max>
<power name="specular_highlight" type="float">
<input name="in1" type="float" nodename="VdotR_nonnegative" />
<input name="in2" type="float" interfacename="shininess" />
</power>
<multiply name="specular" type="float">
<input name="in1" type="float" nodename="specular_highlight" />
<input name="in2" type="float" interfacename="specular_intensity" />
</multiply>
<add name="final_color" type="color3">
<input name="in1" type="color3" nodename="diffuse" />
<input name="in2" type="float" nodename="specular" />
</add>
<output name="out" type="color3" nodename="final_color" />
</nodegraph>

</materialx>
30 changes: 30 additions & 0 deletions resources/Materials/TestSuite/nprlib/gooch_shade.mtlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<materialx version="1.38">

<gooch_shade name="default_gooch" type="color3">
<input name="warm_color" type="color3" value="0.8, 0.8, 0.7" />
<input name="cool_color" type="color3" value="0.3, 0.3, 0.8" />
<input name="specular_intensity" type="float" value="1" />
<input name="shininess" type="float" value="64" />
</gooch_shade>
<surface_unlit name="unlit_surface" type="surfaceshader">
<input name="emission_color" type="color3" nodename="default_gooch" />
</surface_unlit>
<surfacematerial name="default_gooch_material" type="material">
<input name="surfaceshader" type="surfaceshader" nodename="unlit_surface" />
</surfacematerial>

<gooch_shade name="red_blue_gooch" type="color3">
<input name="warm_color" type="color3" value="0.9, 0.1, 0.1" />
<input name="cool_color" type="color3" value="0.1, 0.1, 0.9" />
<input name="specular_intensity" type="float" value="1" />
<input name="shininess" type="float" value="64" />
</gooch_shade>
<surface_unlit name="redblue_gooch_surface" type="surfaceshader">
<input name="emission_color" type="color3" nodename="red_blue_gooch" />
</surface_unlit>
<surfacematerial name="redblue_gooch_material" type="material">
<input name="surfaceshader" type="surfaceshader" nodename="redblue_gooch_surface" />
</surfacematerial>

</materialx>

0 comments on commit 7bec19f

Please sign in to comment.