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

Improved open_pbr_surface to standard_surface translation #1958

Merged
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
100 changes: 89 additions & 11 deletions libraries/bxdf/translation/open_pbr_to_standard_surface.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
<output name="coat_roughness_out" type="float" />
<output name="coat_anisotropy_out" type="float" />
<output name="coat_IOR_out" type="float" />
<output name="coat_affect_color_out" type="float" />
<output name="coat_affect_roughness_out" type="float" />

<output name="thin_film_thickness_out" type="float" />
Expand All @@ -96,19 +95,101 @@

<nodegraph name="NG_open_pbr_surface_to_standard_surface" nodedef="ND_open_pbr_surface_to_standard_surface">

<!-- Coat Darkening -->
<subtract name="coat_ior_minus_one" type="float">
<input name="in1" type="float" interfacename="coat_ior" />
<input name="in2" type="float" value="1.0" />
</subtract>
<add name="coat_ior_plus_one" type="float">
<input name="in1" type="float" value="1.0" />
<input name="in2" type="float" interfacename="coat_ior" />
</add>
<divide name="coat_ior_to_F0_sqrt" type="float">
<input name="in1" type="float" nodename="coat_ior_minus_one" />
<input name="in2" type="float" nodename="coat_ior_plus_one" />
</divide>
<multiply name="coat_ior_to_F0" type="float">
<input name="in1" type="float" nodename="coat_ior_to_F0_sqrt" />
<input name="in2" type="float" nodename="coat_ior_to_F0_sqrt" />
</multiply>
<!-- approximate Kcoat, "internal diffuse reflection coefficient" of coat -->
<subtract name="one_minus_coat_F0" type="float">
<input name="in1" type="float" value="1.0" />
<input name="in2" type="float" nodename="coat_ior_to_F0" />
</subtract>
<multiply name="coat_ior_sqr" type="float">
<input name="in1" type="float" interfacename="coat_ior" />
<input name="in2" type="float" interfacename="coat_ior" />
</multiply>
<divide name="one_minus_coat_F0_over_eta2" type="float">
<input name="in1" type="float" nodename="one_minus_coat_F0" />
<input name="in2" type="float" nodename="coat_ior_sqr" />
</divide>
<subtract name="Kcoat" type="float">
<input name="in1" type="float" value="1.0" />
<input name="in2" type="float" nodename="one_minus_coat_F0_over_eta2" />
</subtract>
<!-- approximate base metal albedo estimate, Emetal -->
<multiply name="Emetal" type="color3">
<input name="in1" type="color3" interfacename="base_color" />
<input name="in2" type="float" interfacename="specular_weight" />
</multiply>
<!-- approximate base dielectric albedo estimate, Edielectric -->
<mix name="Edielectric" type="color3">
<input name="fg" type="color3" interfacename="subsurface_color" />
<input name="bg" type="color3" interfacename="base_color" />
<input name="mix" type="float" interfacename="subsurface_weight" />
</mix>
<!-- thus calculate overall base albedo estimate approximation, Ebase -->
<mix name="Ebase" type="color3">
<input name="fg" type="color3" nodename="Emetal" />
<input name="bg" type="color3" nodename="Edielectric" />
<input name="mix" type="float" interfacename="base_metalness" />
</mix>
<!-- final base darkening factor due to coat: base_darkening = (1 - Kcoat) / (1 - Ebase*Kcoat) -->
<multiply name="Ebase_Kcoat" type="color3">
<input name="in1" type="color3" nodename="Ebase" />
<input name="in2" type="float" nodename="Kcoat" />
</multiply>
<subtract name="one_minus_Kcoat" type="float">
<input name="in1" type="float" value="1.0" />
<input name="in2" type="float" nodename="Kcoat" />
</subtract>
<subtract name="one_minus_Ebase_Kcoat" type="color3">
<input name="in1" type="color3" value="1.0, 1.0, 1.0" />
<input name="in2" type="color3" nodename="Ebase_Kcoat" />
</subtract>
<convert name="one_minus_Kcoat_color" type="color3">
<input name="in" type="float" nodename="one_minus_Kcoat" />
</convert>
<divide name="base_darkening" type="color3">
<input name="in1" type="color3" nodename="one_minus_Kcoat_color" />
<input name="in2" type="color3" nodename="one_minus_Ebase_Kcoat" />
</divide>
<multiply name="coat_weight_times_coat_darkening" type="float">
<input name="in1" type="float" interfacename="coat_weight" />
<input name="in2" type="float" interfacename="coat_darkening" />
</multiply>
<mix name="modulated_base_darkening" type="color3">
<input name="fg" type="color3" nodename="base_darkening" />
<input name="bg" type="color3" value="1.0, 1.0, 1.0" />
<input name="mix" type="float" nodename="coat_weight_times_coat_darkening" />
</mix>

<!--Base-->
<dot name="base" type="float">
<input name="in" type="float" interfacename="base_weight" />
</dot>
<dot name="baseColor" type="color3">
<input name="in" type="color3" interfacename="base_color" />
</dot>
<dot name="diffuseRoughness" type="float">
<input name="in" type="float" interfacename="base_diffuse_roughness" />
</dot>
<dot name="metalness" type="float">
<input name="in" type="float" interfacename="base_metalness" />
</dot>
<multiply name="baseColor" type="color3">
<input name="in1" type="color3" interfacename="base_color" />
<input name="in2" type="color3" nodename="modulated_base_darkening" />
</multiply>

<!--Specular-->
<dot name="spec" type="float">
Expand Down Expand Up @@ -154,9 +235,10 @@
<dot name="subsurface" type="float">
<input name="in" type="float" interfacename="subsurface_weight" />
</dot>
<dot name="subsurfaceColor" type="color3">
<input name="in" type="color3" interfacename="subsurface_color" />
</dot>
<multiply name="subsurfaceColor" type="color3">
<input name="in1" type="color3" interfacename="subsurface_color" />
<input name="in2" type="color3" nodename="modulated_base_darkening" />
</multiply>
<dot name="subsurfaceScale" type="float">
<input name="in" type="float" interfacename="subsurface_radius" />
</dot>
Expand Down Expand Up @@ -195,9 +277,6 @@
<dot name="coatIOR" type="float">
<input name="in" type="float" interfacename="coat_ior" />
</dot>
<dot name="coatAffectColor" type="float">
<input name="in" type="float" interfacename="coat_darkening" />
</dot>
<constant name="coatAffectRoughness" type="float">
<input name="value" type="float" value="1.0" />
</constant>
Expand Down Expand Up @@ -267,7 +346,6 @@
<output name="coat_roughness_out" type="float" nodename="coatRoughness" />
<output name="coat_anisotropy_out" type="float" nodename="coatAnisotropy" />
<output name="coat_IOR_out" type="float" nodename="coatIOR" />
<output name="coat_affect_color_out" type="float" nodename="coatAffectColor" />
<output name="coat_affect_roughness_out" type="float" nodename="coatAffectRoughness" />

<output name="thin_film_thickness_out" type="float" nodename="thinFilmThickness" />
Expand Down