Skip to content

Commit

Permalink
Change to fit logic from Gooch paper.
Browse files Browse the repository at this point in the history
  • Loading branch information
kwokcb committed Jan 27, 2024
1 parent 6a94169 commit 94eb3ac
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 48 deletions.
13 changes: 8 additions & 5 deletions libraries/nprlib/nprlib_defs.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@
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.6, 0, 0" uiname="Warm Color" doc="Warm diffuse color"/>
<input name="cool_color" 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="specular_color" type="color3" value="0.6, 0.6, 0.6" uiname="Specular Color" doc="Specular color"/>
<input name="light_direction" type="vector3" value="1, -0.5, -0.5" uiname="Light Direction" doc="Light vector in world space"/>
<input name="diffuse_color" type="color3" value="0.8, 0.8, 0.8" doc="Diffuse Color" uiname="Diffuse Color" />
<input name="blue_tone" type="float" value="0.55" uimin="0" uimax="1" doc="Blue tone" uiname="Blue Tone" />
<input name="yellow_tone" type="float" value="0.3" uimin="0" uimax="1" doc="Yellow Tone" uiname="Yellow Tone" />
<input name="diffuse_strength" type="float" value="0.25" uimin="0" uimax="1" doc="Diffuse Strength" uiname="Diffuse Strength" />
<input name="luminance_shift" type="float" value="0.5" uimin="0" uimax="1" doc="Luminance Shift" uiname="Luminance Shift" />
<input name="shininess" type="float" value="32" uimin="1" uimax="64" uiname="Shininess" doc="Specular shininess" />
<input name="specular_color" type="color3" value="1, 1, 1" uiname="Specular Color" doc="Specular color" />
<input name="light_direction" type="vector3" value="1, -0.5, -0.5" uiname="Light Direction" doc="Light vector" />
<output name="out" type="color3" />
</nodedef>

Expand Down
78 changes: 67 additions & 11 deletions libraries/nprlib/nprlib_ng.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,12 @@
<input name="space" type="string" value="world" />
</normal>
<normalize name="normalized_light_dir" type="vector3">
<input name="in" type="vector3" nodename="invert_light_dir" />
<input name="in" type="vector3" interfacename="light_direction" />
</normalize>
<dotproduct name="NdotL" type="float">
<input name="in1" type="vector3" nodename="N" />
<input name="in2" type="vector3" nodename="normalized_light_dir" />
</dotproduct>
<mix name="diffuse" type="color3">
<input name="fg" type="color3" interfacename="warm_color" />
<input name="bg" type="color3" interfacename="cool_color" />
<input name="mix" type="float" nodename="max_float" />
</mix>
<power name="specular" type="float">
<input name="in1" type="float" nodename="max1" />
<input name="in2" type="float" interfacename="shininess" />
Expand All @@ -72,9 +67,6 @@
<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" />
<dotproduct name="NdotI" type="float">
<input name="in1" type="vector3" nodename="normalize_vector4" />
Expand All @@ -85,7 +77,7 @@
<input name="in2" type="float" value="2" />
</multiply>
<dotproduct name="VdotR" type="float">
<input name="in1" type="vector3" nodename="normalized_light_dir" />
<input name="in1" type="vector3" nodename="invert_light_dir" />
<input name="in2" type="vector3" nodename="I_NdotI_N_2" />
</dotproduct>
<multiply name="multiply_vector3FA" type="vector3">
Expand Down Expand Up @@ -115,9 +107,73 @@
<input name="in2" type="color3" nodename="multiply_color3FA" />
</add>
<multiply name="invert_light_dir" type="vector3">
<input name="in1" type="vector3" interfacename="light_direction" />
<input name="in1" type="vector3" nodename="normalized_light_dir" />
<input name="in2" type="vector3" value="-1, -1, -1" />
</multiply>
<swizzle name="swizzle_float_color3" type="color3">
<input name="in" type="float" interfacename="blue_tone" />
<input name="channels" type="string" value="00b" />
</swizzle>
<swizzle name="swizzle_float_color4" type="color3">
<input name="in" type="float" interfacename="yellow_tone" />
<input name="channels" type="string" value="rg0" />
</swizzle>
<add name="one_plus_NdotL" type="float">
<input name="in2" type="float" nodename="NdotL" />
<input name="in1" type="float" value="1" />
</add>
<divide name="one_plus_NdotL_div_2" type="float">
<input name="in1" type="float" nodename="one_plus_NdotL" />
<input name="in2" type="float" value="2" />
</divide>
<subtract name="one_minus_NdotL" type="float">
<input name="in2" type="float" nodename="NdotL" />
<input name="in1" type="float" value="1" />
</subtract>
<divide name="one_minus_NdotL_div_2" type="float">
<input name="in1" type="float" nodename="one_minus_NdotL" />
<input name="in2" type="float" value="2" />
</divide>
<convert name="convert_float_color3" type="color3">
<input name="in" type="float" interfacename="diffuse_strength" />
</convert>
<multiply name="multiply_color3" type="color3">
<input name="in1" type="color3" interfacename="diffuse_color" />
<input name="in2" type="color3" nodename="convert_float_color3" />
</multiply>
<add name="k_cool" type="color3">
<input name="in1" type="color3" nodename="multiply_color3" />
<input name="in2" type="color3" nodename="swizzle_float_color3" />
</add>
<add name="k_warm" type="color3">
<input name="in2" type="color3" nodename="swizzle_float_color4" />
<input name="in1" type="color3" nodename="multiply_color4" />
</add>
<convert name="convert_float_color4" type="color3">
<input name="in" type="float" interfacename="luminance_shift" />
</convert>
<multiply name="multiply_color4" type="color3">
<input name="in1" type="color3" interfacename="diffuse_color" />
<input name="in2" type="color3" nodename="convert_float_color4" />
</multiply>
<convert name="convert_float_color5" type="color3">
<input name="in" type="float" nodename="one_plus_NdotL_div_2" />
</convert>
<multiply name="cool" type="color3">
<input name="in2" type="color3" nodename="convert_float_color5" />
<input name="in1" type="color3" nodename="k_cool" />
</multiply>
<convert name="convert_float_color6" type="color3">
<input name="in" type="float" nodename="one_minus_NdotL_div_2" />
</convert>
<multiply name="warm" type="color3">
<input name="in1" type="color3" nodename="k_warm" />
<input name="in2" type="color3" nodename="convert_float_color6" />
</multiply>
<add name="diffuse" type="color3">
<input name="in1" type="color3" nodename="cool" />
<input name="in2" type="color3" nodename="warm" />
</add>
<output name="out" type="color3" nodename="final_color" />
</nodegraph>

Expand Down
24 changes: 11 additions & 13 deletions resources/Materials/Examples/npr/gooch_material.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@
<input name="file" type="filename" value="brass_roughness.jpg" />
<input name="uvtiling" type="vector2" value="1.0, 1.0" />
</tiledimage>

<gooch_shade name="gooch1" type="color3">
<input name="warm_color" type="color3" value="0.6, 0, 0"/>
<input name="cool_color" type="color3" value="0, 0, 0.6"/>
<input name="light_direction" type="vector3" value="0, 1, 1"/>
<input name="specular_color" type="color3" value="0.8, 0.8, 0.8"/>
</gooch_shade>

<input name="warm_color" type="color3" value="0.6, 0, 0" />
<input name="cool_color" type="color3" value="0, 0, 0.6" />
<input name="light_direction" type="vector3" value="0, 1, 1" />
<input name="specular_color" type="color3" value="0.8, 0.8, 0.8" />
</gooch_shade>
<output name="out_basecolor" type="color3" nodename="gooch1" />
<output name="out_color" type="color3" nodename="image_color" />
<output name="out_roughness" type="float" nodename="image_roughness" />
</nodegraph>

<standard_surface name="SR_brass1" type="surfaceshader">
<input name="base" type="float" value="1" />
<input name="base_color" type="color3" nodegraph="NG_brass1" output="out_basecolor" />
Expand All @@ -35,12 +32,13 @@
<surfacematerial name="Tiled_Brass" type="material">
<input name="surfaceshader" type="surfaceshader" nodename="SR_brass1" />
</surfacematerial>

<gooch_shade name="gooch_color" type="color3">
<input name="warm_color" type="color3" value="0.6, 0, 0" />
<input name="cool_color" type="color3" value="0, 0, 0.6" />
<input name="light_direction" type="vector3" value="0, 1, 1"/>
<input name="specular_color" type="color3" value="0.8, 0.8, 0.8"/>
<input name="diffuse_color" type="color3" value="1, 0, 0" />
<input name="yellow_tone" type="float" value="0" />
<input name="blue_tone" type="float" value="1" />
<input name="diffuse_strength" type="float" value="0" />
<input name="luminance_shift" type="float" value="0.522" />
<input name="shininess" type="float" value="16" />
</gooch_shade>
<surface_unlit name="unlit_surface" type="surfaceshader">
<input name="emission_color" type="color3" nodename="gooch_color" />
Expand Down
28 changes: 9 additions & 19 deletions resources/Materials/TestSuite/nprlib/gooch.mtlx
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
<?xml version="1.0"?>
<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_shade>
-->
<gooch_shade name="gooch1" type="color3">
<input name="warm_color" type="color3" value="0.701712, 0.37992, 0.111519" />
<input name="cool_color" type="color3" value="0.073756, 0, 0.486553" />
<input name="shininess" type="float" value="10" />
<input name="specular_color" type="color3" value="0.929095, 0.603842, 0.0817786" />
<input name="diffuse_strength" type="float" value="0.269" />
<input name="diffuse_color" type="color3" value="0, 0.535452, 0.068077" />
<input name="luminance_shift" type="float" value="0.374" />
<input name="yellow_tone" type="float" value="0.325" />
<input name="blue_tone" type="float" value="0.491" />
<input name="light_direction" type="vector3" value="-1, -0.5, -0.5" />
<input name="shininess" type="float" value="5" />
</gooch_shade>
<surface_unlit name="unlit_surface" type="surfaceshader">
<input name="emission_color" type="color3" nodename="gooch1" />
Expand All @@ -27,4 +17,4 @@
<input name="surfaceshader" type="surfaceshader" nodename="unlit_surface" />
<input name="displacementshader" type="displacementshader" value="" />
</surfacematerial>
</materialx>
</materialx>

0 comments on commit 94eb3ac

Please sign in to comment.