forked from AcademySoftwareFoundation/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backported OSL, MSL, and MDL. Added testing.
- Loading branch information
1 parent
6b1000d
commit 4ad6db4
Showing
31 changed files
with
372 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0"?> | ||
<materialx version="1.38"> | ||
|
||
<!-- <compensating_oren_nayar_diffuse_bsdf> --> | ||
<implementation name="IM_compensating_oren_nayar_diffuse_bsdf_genmdl" nodedef="ND_compensating_oren_nayar_diffuse_bsdf" sourcecode="materialx::pbrlib_{{MDL_VERSION_SUFFIX}}::mx_oren_nayar_diffuse_bsdf(mxp_weight:{{weight}}, mxp_color:{{color}}, mxp_roughness:{{roughness}}, mxp_normal:{{normal}})" target="genmdl" /> | ||
|
||
<!-- <dielectric_tf_bsdf> --> | ||
<implementation name="IM_dielectric_tf_bsdf_genmdl" nodedef="ND_dielectric_tf_bsdf" sourcecode="materialx::pbrlib_{{MDL_VERSION_SUFFIX}}::mx_dielectric_bsdf(mxp_weight:{{weight}}, mxp_tint:{{tint}}, mxp_ior:{{ior}}, mxp_roughness:{{roughness}}, mxp_thinfilm_thickness:{{thinfilm_thickness}}, mxp_thinfilm_ior:{{thinfilm_ior}}, mxp_normal:{{normal}}, mxp_tangent:{{tangent}}, mxp_distribution:{{distribution}}, mxp_scatter_mode:{{scatter_mode}}, mxp_base:{{base}})" target="genmdl" /> | ||
|
||
<!-- <generalized_schlick_tf_82_bsdf> --> | ||
<implementation name="IM_generalized_schlick_tf_82_bsdf_genmdl" nodedef="ND_generalized_schlick_tf_82_bsdf" sourcecode="materialx::pbrlib_{{MDL_VERSION_SUFFIX}}::mx_generalized_schlick_bsdf(mxp_weight:{{weight}}, mxp_color0:{{color0}}, mxp_color90:{{color90}}, mxp_exponent:{{exponent}},mxp_roughness:{{roughness}}, mxp_thinfilm_thickness:{{thinfilm_thickness}}, mxp_thinfilm_ior:{{thinfilm_ior}}, mxp_normal:{{normal}}, mxp_tangent:{{tangent}}, mxp_distribution:{{distribution}}, mxp_scatter_mode:{{scatter_mode}}, mxp_base:{{base}})" target="genmdl" /> | ||
|
||
<!-- <sheen_zeltner_bsdf> --> | ||
<implementation name="IM_sheen_zeltner_bsdf_genmdl" nodedef="ND_sheen_zeltner_bsdf" sourcecode="materialx::pbrlib_{{MDL_VERSION_SUFFIX}}::mx_sheen_bsdf(mxp_weight:{{weight}}, mxp_color:{{color}}, mxp_roughness:{{roughness}}, mxp_normal:{{normal}}, mxp_base:{{weight}})" target="genmdl" /> | ||
|
||
</materialx> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0"?> | ||
<materialx version="1.38"> | ||
|
||
<!-- <compensating_oren_nayar_diffuse_bsdf> --> | ||
<implementation name="IM_compensating_oren_nayar_diffuse_bsdf_genglsl" nodedef="ND_compensating_oren_nayar_diffuse_bsdf" file="../genglsl/mx39_compensating_oren_nayar_diffuse_bsdf.glsl" function="mx39_compensating_oren_nayar_diffuse_bsdf" target="genmsl" /> | ||
|
||
<!-- <dielectric_tf_bsdf> --> | ||
<implementation name="IM_dielectric_tf_bsdf_genglsl" nodedef="ND_dielectric_tf_bsdf" file="mx39_dielectric_tf_bsdf.glsl" function="../genglsl/mx39_dielectric_tf_bsdf" target="genmsl" /> | ||
|
||
<!-- <generalized_schlick_tf_82_bsdf> --> | ||
<implementation name="IM_generalized_schlick_tf_82_bsdf_genglsl" nodedef="ND_generalized_schlick_tf_82_bsdf" file="../genglsl/mx39_generalized_schlick_tf_82_bsdf.glsl" function="mx39_generalized_schlick_tf_82_bsdf" target="genmsl" /> | ||
|
||
<!-- <sheen_zeltner_bsdf> --> | ||
<implementation name="IM_sheen_zeltner_bsdf_genglsl" nodedef="ND_sheen_zeltner_bsdf" file="../genglsl/mx39_sheen_zeltner_bsdf.glsl" function="mx39_sheen_zeltner_bsdf" target="genmsl" /> | ||
|
||
</materialx> |
5 changes: 5 additions & 0 deletions
5
libraries/pbrlib/genosl/legacy/mx39_compensating_oren_nayar_diffuse_bsdf.osl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
void mx39_compensating_oren_nayar_diffuse_bsdf(float weight, color _color, float roughness, normal N, int energy_compensation, output BSDF bsdf) | ||
{ | ||
bsdf.response = _color * weight * oren_nayar(N, roughness); | ||
bsdf.throughput = color(0.0); | ||
} |
36 changes: 36 additions & 0 deletions
36
libraries/pbrlib/genosl/legacy/mx39_dielectric_tf_bsdf.osl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "../lib/mx_microfacet_specular.osl" | ||
|
||
void mx39_dielectric_tf_bsdf(float weight, color tint, float ior, vector2 roughness, float thinfilm_thickness, float thinfilm_ior, normal N, vector U, string distribution, string scatter_mode, output BSDF bsdf) | ||
{ | ||
if (scatter_mode == "T") | ||
{ | ||
bsdf.response = tint * weight * microfacet(distribution, N, U, roughness.x, roughness.y, ior, 1); | ||
bsdf.throughput = tint * weight; | ||
return; | ||
} | ||
|
||
float NdotV = clamp(dot(N,-I), M_FLOAT_EPS, 1.0); | ||
float F0 = mx_ior_to_f0(ior); | ||
float F = mx_fresnel_schlick(NdotV, F0); | ||
|
||
// Calculate compensation for multiple scattering. | ||
// This should normally be done inside the closure | ||
// but since vanilla OSL doesen't support this we | ||
// add it here in shader code instead. | ||
vector2 safeAlpha = clamp(roughness, M_FLOAT_EPS, 1.0); | ||
float avgAlpha = mx_average_alpha(safeAlpha); | ||
float comp = mx_ggx_energy_compensation(NdotV, avgAlpha, F); | ||
|
||
// Calculate throughput from directional albedo. | ||
float dirAlbedo = mx_ggx_dir_albedo(NdotV, avgAlpha, ior) * comp; | ||
bsdf.throughput = 1.0 - dirAlbedo * weight; | ||
|
||
if (scatter_mode == "R") | ||
{ | ||
bsdf.response = tint * weight * comp * microfacet(distribution, N, U, safeAlpha.x, safeAlpha.y, ior, 0); | ||
} | ||
else | ||
{ | ||
bsdf.response = tint * weight * comp * microfacet(distribution, N, U, safeAlpha.x, safeAlpha.y, ior, 2); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
libraries/pbrlib/genosl/legacy/mx39_generalized_schlick_tf_82_bsdf.osl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "../lib/mx_microfacet_specular.osl" | ||
|
||
void mx39_generalized_schlick_tf_82_bsdf(float weight, color color0, color color82, color color90, float exponent, vector2 roughness, float thinfilm_thickness, float thinfilm_ior, normal N, vector U, string distribution, string scatter_mode, output BSDF bsdf) | ||
{ | ||
float avgF0 = dot(color0, color(1.0 / 3.0)); | ||
float ior = mx_f0_to_ior(avgF0); | ||
|
||
if (scatter_mode == "T") | ||
{ | ||
bsdf.response = weight * microfacet(distribution, N, U, roughness.x, roughness.y, ior, 1); | ||
bsdf.throughput = weight; | ||
return; | ||
} | ||
|
||
float NdotV = fabs(dot(N,-I)); | ||
color F = mx_fresnel_schlick(NdotV, color0, color90, exponent); | ||
|
||
// Calculate compensation for multiple scattering. | ||
// This should normally be done inside the closure | ||
// but since vanilla OSL doesen't support this we | ||
// add it here in shader code instead. | ||
vector2 safeAlpha = clamp(roughness, M_FLOAT_EPS, 1.0); | ||
float avgAlpha = mx_average_alpha(safeAlpha); | ||
color comp = mx_ggx_energy_compensation(NdotV, avgAlpha, F); | ||
|
||
// Calculate throughput from directional albedo. | ||
color dirAlbedo = mx_ggx_dir_albedo(NdotV, avgAlpha, color0, color90) * comp; | ||
float avgDirAlbedo = dot(dirAlbedo, color(1.0 / 3.0)); | ||
bsdf.throughput = 1.0 - avgDirAlbedo * weight; | ||
|
||
// Calculate the reflection response, setting IOR to zero to disable internal Fresnel. | ||
bsdf.response = F * comp * weight * microfacet(distribution, N, U, safeAlpha.x, safeAlpha.y, 0.0, 0); | ||
|
||
if (scatter_mode == "RT") | ||
{ | ||
bsdf.response += bsdf.throughput * microfacet(distribution, N, U, safeAlpha.x, safeAlpha.y, ior, 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
void mx39_dielectric_tf_bsdf(float weight, color tint, float ior, vector2 roughness, float thinfilm_thickness, float thinfilm_ior, normal N, vector U, string distribution, string scatter_mode, output BSDF bsdf) | ||
{ | ||
if (scatter_mode == "R") | ||
{ | ||
bsdf = weight * dielectric_bsdf(N, U, tint, color(0.0), roughness.x, roughness.y, ior, distribution, "thinfilm_thickness", thinfilm_thickness, "thinfilm_ior", thinfilm_ior); | ||
} | ||
else if (scatter_mode == "T") | ||
{ | ||
bsdf = weight * dielectric_bsdf(N, U, color(0.0), tint, roughness.x, roughness.y, ior, distribution, "thinfilm_thickness", thinfilm_thickness, "thinfilm_ior", thinfilm_ior); | ||
} | ||
else | ||
{ | ||
bsdf = weight * dielectric_bsdf(N, U, tint, tint, roughness.x, roughness.y, ior, distribution, "thinfilm_thickness", thinfilm_thickness, "thinfilm_ior", thinfilm_ior); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
libraries/pbrlib/genosl/mx39_generalized_schlick_tf_82_bsdf.osl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
void mx39_generalized_schlick_tf_82_bsdf(float weight, color color0, color color82, color color90, float exponent, vector2 roughness, float thinfilm_thickness, float thinfilm_ior, normal N, vector U, string distribution, string scatter_mode, output BSDF bsdf) | ||
{ | ||
if (scatter_mode == "R") | ||
{ | ||
bsdf = weight * generalized_schlick_bsdf(N, U, color(1.0), color(0.0), roughness.x, roughness.y, color0, color90, exponent, distribution, "thinfilm_thickness", thinfilm_thickness, "thinfilm_ior", thinfilm_ior); | ||
} | ||
else if (scatter_mode == "T") | ||
{ | ||
bsdf = weight * generalized_schlick_bsdf(N, U, color(0.0), color(1.0), roughness.x, roughness.y, color0, color90, exponent, distribution, "thinfilm_thickness", thinfilm_thickness, "thinfilm_ior", thinfilm_ior); | ||
} | ||
else | ||
{ | ||
bsdf = weight * generalized_schlick_bsdf(N, U, color(1.0), color(1.0), roughness.x, roughness.y, color0, color90, exponent, distribution, "thinfilm_thickness", thinfilm_thickness, "thinfilm_ior", thinfilm_ior); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0"?> | ||
<materialx version="1.38"> | ||
|
||
<!-- <compensating_oren_nayar_diffuse_bsdf> --> | ||
<implementation name="IM_compensating_oren_nayar_diffuse_bsdf_genosl" nodedef="ND_compensating_oren_nayar_diffuse_bsdf" file="legacy/mx39_compensating_oren_nayar_diffuse_bsdf.osl" function="mx39_compensating_oren_nayar_diffuse_bsdf" target="genosl" /> | ||
|
||
<!-- <dielectric_tf_bsdf> --> | ||
<implementation name="IM_dielectric_tf_bsdf_genosl" nodedef="ND_dielectric_tf_bsdf" file="legacy/mx39_dielectric_tf_bsdf.osl" function="mx39_dielectric_tf_bsdf" target="genosl" /> | ||
|
||
<!-- <generalized_schlick_tf_82_bsdf> --> | ||
<implementation name="IM_generalized_schlick_tf_82_bsdf_genosl" nodedef="ND_generalized_schlick_tf_82_bsdf" file="legacy/mx39_generalized_schlick_tf_82_bsdf.osl" function="mx39_generalized_schlick_tf_82_bsdf" target="genosl" /> | ||
|
||
<!-- <sheen_zeltner_bsdf> --> | ||
<implementation name="IM_sheen_zeltner_bsdf_genosl" nodedef="ND_sheen_zeltner_bsdf" file="legacy/mx_sheen_bsdf.osl" function="mx_sheen_bsdf" target="genosl" /> | ||
|
||
</materialx> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0"?> | ||
<materialx version="1.38"> | ||
|
||
<!-- <compensating_oren_nayar_diffuse_bsdf> --> | ||
<implementation name="IM_compensating_oren_nayar_diffuse_bsdf_genosl" nodedef="ND_compensating_oren_nayar_diffuse_bsdf" sourcecode="{{weight}} * oren_nayar_diffuse_bsdf({{normal}}, {{color}}, {{roughness}})" target="genosl" /> | ||
|
||
<!-- <dielectric_tf_bsdf> --> | ||
<implementation name="IM_dielectric_tf_bsdf_genosl" nodedef="ND_dielectric_tf_bsdf" file="mx39_dielectric_tf_bsdf.osl" function="mx39_dielectric_tf_bsdf" target="genosl" /> | ||
|
||
<!-- <generalized_schlick_tf_82_bsdf> --> | ||
<implementation name="IM_generalized_schlick_tf_82_bsdf_genosl" nodedef="ND_generalized_schlick_tf_82_bsdf" file="mx39_generalized_schlick_tf_82_bsdf.osl" function="mx39_generalized_schlick_tf_82_bsdf" target="genosl" /> | ||
|
||
<!-- <sheen_zeltner_bsdf> --> | ||
<implementation name="IM_sheen_zeltner_bsdf_genosl" nodedef="ND_sheen_zeltner_bsdf" sourcecode="{{weight}} * sheen_bsdf({{normal}}, {{color}}, {{roughness}})" target="genosl" /> | ||
|
||
</materialx> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
resources/Materials/Examples/OpenPbr/open_pbr_aluminum_brushed.mtlx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0"?> | ||
<materialx version="1.38" colorspace="lin_rec709"> | ||
<surfacematerial name="Aluminum_Brushed" type="material"> | ||
<input name="surfaceshader" type="surfaceshader" nodename="open_pbr_surface_surfaceshader" /> | ||
</surfacematerial> | ||
<open_pbr_surface name="open_pbr_surface_surfaceshader" type="surfaceshader"> | ||
<input name="base_color" type="color3" value="0.912, 0.914, 0.920" /> | ||
<input name="base_metalness" type="float" value="1.0" /> | ||
<input name="specular_color" type="color3" value="0.970, 0.979, 0.988" /> | ||
<input name="specular_roughness" type="float" value="0.2" /> | ||
<input name="specular_roughness_anisotropy" type="float" value="0.9" /> | ||
</open_pbr_surface> | ||
</materialx> |
14 changes: 14 additions & 0 deletions
14
resources/Materials/Examples/OpenPbr/open_pbr_carpaint.mtlx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0"?> | ||
<materialx version="1.38" colorspace="lin_rec709"> | ||
<surfacematerial name="Car_Paint" type="material"> | ||
<input name="surfaceshader" type="surfaceshader" nodename="open_pbr_surface_surfaceshader" /> | ||
</surfacematerial> | ||
<open_pbr_surface name="open_pbr_surface_surfaceshader" type="surfaceshader"> | ||
<input name="base_color" type="color3" value="0.1, 0.6, 0.9" /> | ||
<input name="specular_ior" type="float" value="1.6" /> | ||
<input name="specular_roughness" type="float" value="0.3" /> | ||
<input name="coat_weight" type="float" value="1" /> | ||
<input name="coat_roughness" type="float" value="0.02" /> | ||
<input name="coat_ior" type="float" value="1.6" /> | ||
</open_pbr_surface> | ||
</materialx> |
Oops, something went wrong.