Skip to content

Commit

Permalink
Update with new Gooch implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
kwokcb committed Jan 24, 2024
1 parent 2c10440 commit d2c19a4
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 44 deletions.
36 changes: 31 additions & 5 deletions libraries/nprlib/nprlib_defs.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
Declarations of standard data types and nodes included in the MaterialX specification.
-->

<!-- ======================================================================== -->
<!-- View-dependent properties -->
<!-- ======================================================================== -->

<geompropdef name="Vworld" type="vector3" geomprop="viewdirection" space="world" />

<!-- ======================================================================== -->
<!-- View-dependent nodes -->
<!-- ======================================================================== -->
Expand All @@ -20,11 +26,31 @@
<output name="out" type="vector3" default="0.0, 0.0, 1.0" />
</nodedef>

<nodedef name="ND_gooch" node="gooch" version="1.0.0" isdefaultversion="true">
<input name="warm_color" type="color3" value="0.6, 0, 0" uiname="Warm Color"/>
<input name="cool_color" type="color3" value="0, 0, 0.6"/>
<!--
Node: <facingratio>
Return the geometric facing ratio, computed as the dot product between the
view direction and geometric normal.
-->
<nodedef name="ND_facingratio_float" node="facingratio" nodegroup="npr">
<input name="viewdirection" type="vector3" defaultgeomprop="Vworld" />
<input name="normal" type="vector3" defaultgeomprop="Nworld" />
<input name="light_dir" type="vector3" value="0, 1, 1"/>
<output name="out" type="surfaceshader" />
<input name="faceforward" type="boolean" default="true" />
<input name="invert" type="boolean" default="false" />
<output name="out" type="float" default="0.0" />
</nodedef>

<!--
Node: <gooch>
Compute Gooch shading.
-->
<nodedef name="ND_gooch" node="gooch" doc="Compute Gooch shading">
<input name="Warm" type="color3" value="0.6, 0, 0" uiname="Warm Color" doc="Warm diffuse color"/>
<input name="Cool" type="color3" value="0, 0, 0.6" uiname="Cool Color" doc="Cool diffuse color"/>
<input name="Shininess" type="float" value="8" uimin="1" uimax="64" doc="Specular shininess"/>
<input name="SpecularColor" type="color3" value="0.6, 0.6, 0.6" uiname="Specular Color" doc="Specular color"/>
<input name="LightDirection" type="vector3" value="1, 0.5, 0.5" uiname="Light Direction" doc="Light vector"/>
<output name="out" type="color3" />
</nodedef>


</materialx>
149 changes: 110 additions & 39 deletions libraries/nprlib/nprlib_ng.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,121 @@
Copyright Contributors to the MaterialX Project
SPDX-License-Identifier: Apache-2.0
Graph definitions of nprlib nodes included in the MaterialX specification.
Graph definitions of standard nodes included in the MaterialX specification.
-->

<nodegraph name="IMPL_gooch" nodedef="ND_gooch">
<add name="add" type="vector3" >
<input name="in1" type="vector3" nodename="light" />
<input name="in2" type="vector3" nodename="light" />
</add>
<add name="add1" type="color3" >
<input name="in1" type="color3" nodename="mix" />
<input name="in2" type="float" nodename="max1" />
</add>
<dotproduct name="dotproduct" type="float" >
<input name="in1" type="vector3" interfacename="normal" />
<input name="in2" type="vector3" nodename="normalize" />
<!-- ======================================================================== -->
<!-- View-dependent nodes -->
<!-- ======================================================================== -->

<!--
Node: <facingratio>
-->
<nodegraph name="NG_facingratio_float" nodedef="ND_facingratio_float">
<dotproduct name="N_dotproduct" type="float">
<input name="in1" type="vector3" interfacename="viewdirection" />
<input name="in2" type="vector3" interfacename="normal" />
</dotproduct>
<dotproduct name="dotproduct1" type="float" >
<input name="in1" type="vector3" interfacename="normal" />
<input name="in2" type="vector3" nodename="normalize1" />
<multiply name="N_scale" type="float">
<input name="in1" type="float" nodename="N_dotproduct" />
<input name="in2" type="float" value="-1" />
</multiply>
<absval name="N_absval" type="float">
<input name="in" type="float" nodename="N_dotproduct" />
</absval>
<ifequal name="N_facing" type="float">
<input name="value1" type="boolean" interfacename="faceforward" />
<input name="value2" type="boolean" value="true" />
<input name="in1" type="float" nodename="N_absval" />
<input name="in2" type="float" nodename="N_scale" />
</ifequal>
<subtract name="N_invert" type="float">
<input name="in1" type="float" value="1" />
<input name="in2" type="float" nodename="N_facing" />
</subtract>
<ifequal name="N_result" type="float">
<input name="value1" type="boolean" interfacename="invert" />
<input name="value2" type="boolean" value="true" />
<input name="in1" type="float" nodename="N_invert" />
<input name="in2" type="float" nodename="N_facing" />
</ifequal>
<output name="out" type="float" nodename="N_result" />
</nodegraph>

<!--
Node: <gooch>
-->
<nodegraph name="NG_gooch" type="color3" nodedef="ND_gooch">
<normal name="N" type="vector3">
<input name="space" type="string" value="world" />
</normal>
<normalize name="normalize" type="vector3">
<input name="in" type="vector3" interfacename="LightDirection" />
</normalize>
<dotproduct name="NdotL" type="float">
<input name="in1" type="vector3" nodename="N" />
<input name="in2" type="vector3" nodename="normalize" />
</dotproduct>
<constant name="light" type="vector3" >
<input name="value" type="vector3" interfacename="light_dir" />
</constant>
<max name="max1" type="float" >
<input name="in1" type="float" nodename="power" />
</max>
<mix name="mix" type="color3" >
<input name="fg" type="color3" interfacename="cool_color" />
<input name="bg" type="color3" interfacename="warm_color" />
<input name="mix" type="float" nodename="dotproduct" />
<mix name="diffuse" type="color3">
<input name="fg" type="color3" interfacename="Cool" />
<input name="bg" type="color3" interfacename="Warm" />
<input name="mix" type="float" nodename="max_float" />
</mix>
<normalize name="normalize" type="vector3" >
<input name="in" type="vector3" nodename="light" />
<power name="specular" type="float">
<input name="in1" type="float" nodename="max1" />
<input name="in2" type="float" interfacename="Shininess" />
</power>
<max name="max1" type="float">
<input name="in1" type="float" nodename="VdotR" />
<input name="in2" type="float" value="0" />
</max>
<max name="max_float" type="float">
<input name="in1" type="float" nodename="NdotL" />
</max>
<viewdirection name="view" type="vector3" />
<multiply name="viewDirection" type="vector3">
<input name="in1" type="vector3" nodename="view" />
<input name="in2" type="float" value="-1" />
</multiply>
<dotproduct name="NdotI" type="float">
<input name="in1" type="vector3" nodename="normalize_vector4" />
<input name="in2" type="vector3" nodename="multiply_vector3FA" />
</dotproduct>
<multiply name="NdotI_2" type="float">
<input name="in1" type="float" nodename="NdotI" />
<input name="in2" type="float" value="2" />
</multiply>
<dotproduct name="VdotR" type="float">
<input name="in1" type="vector3" nodename="viewDirection" />
<input name="in2" type="vector3" nodename="I_NdotI_N_2" />
</dotproduct>
<multiply name="multiply_vector3FA" type="vector3">
<input name="in1" type="vector3" nodename="normalize_vector3" />
<input name="in2" type="float" value="1" />
</multiply>
<normalize name="normalize_vector3" type="vector3">
<input name="in" type="vector3" nodename="view" />
</normalize>
<normalize name="normalize1" type="vector3" >
<input name="in" type="vector3" nodename="add" />
<normalize name="normalize_vector4" type="vector3">
<input name="in" type="vector3" nodename="N" />
</normalize>
<power name="power" type="float" >
<input name="in1" type="float" nodename="dotproduct1" />
<input name="in2" type="float" value="32" />
</power>
<surface_unlit name="gooch_shader" type="surfaceshader" >
<input name="emission_color" type="color3" nodename="add1" />
</surface_unlit>
<output name="out" type="surfaceshader" nodename="gooch_shader" />
</nodegraph>
<multiply name="NdotI_N_2" type="vector3">
<input name="in1" type="vector3" nodename="normalize_vector4" />
<input name="in2" type="float" nodename="NdotI_2" />
</multiply>
<subtract name="I_NdotI_N_2" type="vector3">
<input name="in1" type="vector3" nodename="normalize_vector3" />
<input name="in2" type="vector3" nodename="NdotI_N_2" />
</subtract>
<multiply name="multiply_color3FA" type="color3">
<input name="in2" type="float" nodename="specular" />
<input name="in1" type="color3" interfacename="SpecularColor" />
</multiply>
<add name="final_color" type="color3">
<input name="in1" type="color3" nodename="diffuse" />
<input name="in2" type="color3" nodename="multiply_color3FA" />
</add>
<output name="out" type="color3" nodename="final_color" />
</nodegraph>

</materialx>
30 changes: 30 additions & 0 deletions resources/Materials/TestSuite/nprlib/gooch.mtlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<materialx version="1.38">
<!--
Copyright Contributors to the MaterialX Project
SPDX-License-Identifier: Apache-2.0

Graph definitions of standard nodes included in the MaterialX specification.
-->

<!-- ======================================================================== -->
<!-- Gooch Shading Example -->
<!-- ======================================================================== -->

<!--
Node: <gooch>
-->
<gooch name="gooch1" type="color3">
<input name="Warm" type="color3" value="0.701712, 0.37992, 0.111519" />
<input name="Cool" type="color3" value="0.073756, 0, 0.486553" />
<input name="Shininess" type="float" value="10" />
<input name="SpecularColor" type="color3" value="0.929095, 0.603842, 0.0817786" />
</gooch>
<surface_unlit name="unlit_surface" type="surfaceshader">
<input name="emission_color" type="color3" nodename="gooch1" />
<input name="opacity" type="float" value="1.0" />
</surface_unlit>
<surfacematerial name="surfacematerial" type="material">
<input name="surfaceshader" type="surfaceshader" nodename="unlit_surface" />
<input name="displacementshader" type="displacementshader" value="" />
</surfacematerial>
</materialx>

0 comments on commit d2c19a4

Please sign in to comment.