-
Notifications
You must be signed in to change notification settings - Fork 360
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
Initial refraction approximation in GLSL #918
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ void mx_dielectric_bsdf_reflection(vec3 L, vec3 V, vec3 P, float occlusion, floa | |
} | ||
else | ||
{ | ||
fd = mx_init_fresnel_dielectric(ior); | ||
fd = mx_init_fresnel_dielectric(ior); | ||
} | ||
vec3 F = mx_compute_fresnel(VdotH, fd); | ||
float D = mx_ggx_NDF(Ht, safeAlpha); | ||
|
@@ -44,14 +44,7 @@ void mx_dielectric_bsdf_reflection(vec3 L, vec3 V, vec3 P, float occlusion, floa | |
|
||
void mx_dielectric_bsdf_transmission(vec3 V, float weight, vec3 tint, float ior, vec2 roughness, vec3 N, vec3 X, int distribution, int scatter_mode, inout BSDF bsdf) | ||
{ | ||
if (scatter_mode == 1) | ||
{ | ||
bsdf.response = tint * weight; | ||
bsdf.throughput = bsdf.response; | ||
return; | ||
} | ||
|
||
if (weight < M_FLOAT_EPS) | ||
if (weight < M_FLOAT_EPS || scatter_mode == 0) | ||
{ | ||
return; | ||
} | ||
|
@@ -61,20 +54,29 @@ void mx_dielectric_bsdf_transmission(vec3 V, float weight, vec3 tint, float ior, | |
|
||
FresnelData fd; | ||
if (bsdf.thickness > 0.0) | ||
{ | ||
fd = mx_init_fresnel_dielectric_airy(ior, bsdf.thickness, bsdf.ior); | ||
} | ||
else | ||
{ | ||
fd = mx_init_fresnel_dielectric(ior); | ||
|
||
} | ||
vec3 F = mx_compute_fresnel(NdotV, fd); | ||
|
||
vec2 safeAlpha = clamp(roughness, M_FLOAT_EPS, 1.0); | ||
float avgAlpha = mx_average_alpha(safeAlpha); | ||
|
||
float F0 = mx_ior_to_f0(ior); | ||
vec3 comp = mx_ggx_energy_compensation(NdotV, avgAlpha, F); | ||
vec3 dirAlbedo = mx_ggx_dir_albedo(NdotV, avgAlpha, F0, 1.0) * comp; | ||
bsdf.throughput = 1.0 - dirAlbedo * weight; | ||
|
||
bsdf.response = (scatter_mode == 2) ? tint * weight * bsdf.throughput : vec3(0.0); | ||
// For now, we approximate the appearance of dielectric transmission as | ||
// glossy environment map refraction, ignoring any scene geometry that | ||
// might be visible through the surface. | ||
fd.refraction = true; | ||
vec3 Li = $refractionEnv ? mx_environment_radiance(N, V, X, safeAlpha, distribution, fd) : $refractionColor; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity why is there an option to replace the refracted environment with a uniform color? We don't have a corresponding control for environment reflections. Or is this just for debugging for now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That option was primarily added for our GLSL/OSL reference renders, since OSL There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha! Maybe we should fix this so the environment is visible in both reflection and transmission, for both GLSL and OSL test suite rendering. Lets do that in a separate PR though. |
||
bsdf.response = Li * tint * weight; | ||
} | ||
|
||
void mx_dielectric_bsdf_indirect(vec3 V, float weight, vec3 tint, float ior, vec2 roughness, vec3 N, vec3 X, int distribution, int scatter_mode, inout BSDF bsdf) | ||
|
@@ -90,14 +92,18 @@ void mx_dielectric_bsdf_indirect(vec3 V, float weight, vec3 tint, float ior, vec | |
|
||
FresnelData fd; | ||
if (bsdf.thickness > 0.0) | ||
{ | ||
fd = mx_init_fresnel_dielectric_airy(ior, bsdf.thickness, bsdf.ior); | ||
} | ||
else | ||
{ | ||
fd = mx_init_fresnel_dielectric(ior); | ||
|
||
} | ||
vec3 F = mx_compute_fresnel(NdotV, fd); | ||
|
||
vec2 safeAlpha = clamp(roughness, M_FLOAT_EPS, 1.0); | ||
float avgAlpha = mx_average_alpha(safeAlpha); | ||
|
||
float F0 = mx_ior_to_f0(ior); | ||
vec3 comp = mx_ggx_energy_compensation(NdotV, avgAlpha, F); | ||
vec3 dirAlbedo = mx_ggx_dir_albedo(NdotV, avgAlpha, F0, 1.0) * comp; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0"?> | ||
<materialx version="1.38" colorspace="lin_rec709"> | ||
<standard_surface name="SR_glass_tinted" type="surfaceshader"> | ||
<input name="base" type="float" value="0" /> | ||
<input name="specular" type="float" value="1" /> | ||
<input name="specular_color" type="color3" value="1, 1, 1" /> | ||
<input name="specular_roughness" type="float" value="0.15" /> | ||
<input name="specular_IOR" type="float" value="1.54" /> | ||
<input name="transmission" type="float" value="1" /> | ||
<input name="transmission_color" type="color3" value="0.2, 0.1, 1" /> | ||
</standard_surface> | ||
<surfacematerial name="GlassTinted" type="material"> | ||
<input name="surfaceshader" type="surfaceshader" nodename="SR_glass_tinted" /> | ||
</surfacematerial> | ||
</materialx> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,122 +1,43 @@ | ||
<?xml version="1.0"?> | ||
<materialx version="1.38"> | ||
<!-- Test dielectric_bsdf in various scatter modes --> | ||
<nodegraph name="dielectric_bsdf_R"> | ||
<dielectric_bsdf name="bsdf1" type="BSDF"> | ||
<nodegraph name="dielectric_bsdf"> | ||
<dielectric_bsdf name="dielectric_R" type="BSDF"> | ||
<input name="weight" type="float" value="1.0" /> | ||
<input name="tint" type="color3" value="0.7, 0.7, 0.7" /> | ||
<input name="ior" type="float" value="1.7" /> | ||
<input name="scatter_mode" type="string" value="R" /> | ||
</dielectric_bsdf> | ||
<surface name="surface1" type="surfaceshader"> | ||
<input name="bsdf" type="BSDF" nodename="bsdf1" /> | ||
<surface name="surface_R" type="surfaceshader"> | ||
<input name="bsdf" type="BSDF" nodename="dielectric_R" /> | ||
</surface> | ||
<output name="out" type="surfaceshader" nodename="surface1" /> | ||
</nodegraph> | ||
<nodegraph name="dielectric_bsdf_T"> | ||
<dielectric_bsdf name="bsdf1" type="BSDF"> | ||
<output name="R_out" type="surfaceshader" nodename="surface_R" /> | ||
|
||
<dielectric_bsdf name="dielectric_T" type="BSDF"> | ||
<input name="weight" type="float" value="1.0" /> | ||
<input name="tint" type="color3" value="0.7, 0.7, 0.7" /> | ||
<input name="ior" type="float" value="1.7" /> | ||
<input name="scatter_mode" type="string" value="T" /> | ||
</dielectric_bsdf> | ||
<surface name="surface1" type="surfaceshader"> | ||
<input name="bsdf" type="BSDF" nodename="bsdf1" /> | ||
<surface name="surface_T" type="surfaceshader"> | ||
<input name="bsdf" type="BSDF" nodename="dielectric_T" /> | ||
</surface> | ||
<output name="out" type="surfaceshader" nodename="surface1" /> | ||
</nodegraph> | ||
<nodegraph name="dielectric_bsdf_RT"> | ||
<dielectric_bsdf name="bsdf1" type="BSDF"> | ||
<output name="T_out" type="surfaceshader" nodename="surface_T" /> | ||
|
||
<dielectric_bsdf name="dielectric_RT" type="BSDF"> | ||
<input name="weight" type="float" value="1.0" /> | ||
<input name="tint" type="color3" value="0.7, 0.7, 0.7" /> | ||
<input name="ior" type="float" value="1.7" /> | ||
<input name="scatter_mode" type="string" value="RT" /> | ||
</dielectric_bsdf> | ||
<surface name="surface1" type="surfaceshader"> | ||
<input name="bsdf" type="BSDF" nodename="bsdf1" /> | ||
</surface> | ||
<output name="out" type="surfaceshader" nodename="surface1" /> | ||
</nodegraph> | ||
<nodegraph name="dielectric_bsdf_layeredRT"> | ||
<dielectric_bsdf name="bsdf1" type="BSDF"> | ||
<input name="weight" type="float" value="1.0" /> | ||
<input name="tint" type="color3" value="0.7, 0.7, 0.7" /> | ||
<input name="ior" type="float" value="1.7" /> | ||
<input name="scatter_mode" type="string" value="R" /> | ||
</dielectric_bsdf> | ||
<dielectric_bsdf name="bsdf2" type="BSDF"> | ||
<input name="weight" type="float" value="1.0" /> | ||
<input name="tint" type="color3" value="0.7, 0.7, 0.7" /> | ||
<input name="ior" type="float" value="1.7" /> | ||
<input name="scatter_mode" type="string" value="T" /> | ||
</dielectric_bsdf> | ||
<layer name="layer1" type="BSDF"> | ||
<input name="top" type="BSDF" nodename="bsdf1" /> | ||
<input name="base" type="BSDF" nodename="bsdf2" /> | ||
</layer> | ||
<surface name="surface1" type="surfaceshader"> | ||
<input name="bsdf" type="BSDF" nodename="layer1" /> | ||
<surface name="surface_RT" type="surfaceshader"> | ||
<input name="bsdf" type="BSDF" nodename="dielectric_RT" /> | ||
</surface> | ||
<output name="out" type="surfaceshader" nodename="surface1" /> | ||
</nodegraph> | ||
<output name="RT_out" type="surfaceshader" nodename="surface_RT" /> | ||
|
||
<!-- Test generalized_schlick_bsdf in various scatter modes --> | ||
<nodegraph name="generalized_schlick_bsdf_R"> | ||
<generalized_schlick_bsdf name="bsdf1" type="BSDF"> | ||
<input name="weight" type="float" value="1.0" /> | ||
<input name="color0" type="color3" value="0.7, 0.7, 0.7" /> | ||
<input name="color90" type="color3" value="1.0, 1.0, 1.0" /> | ||
<input name="scatter_mode" type="string" value="R" /> | ||
</generalized_schlick_bsdf> | ||
<surface name="surface1" type="surfaceshader"> | ||
<input name="bsdf" type="BSDF" nodename="bsdf1" /> | ||
</surface> | ||
<output name="out" type="surfaceshader" nodename="surface1" /> | ||
</nodegraph> | ||
<nodegraph name="generalized_schlick_bsdf_T"> | ||
<generalized_schlick_bsdf name="bsdf1" type="BSDF"> | ||
<input name="weight" type="float" value="1.0" /> | ||
<input name="color0" type="color3" value="0.7, 0.7, 0.7" /> | ||
<input name="color90" type="color3" value="1.0, 1.0, 1.0" /> | ||
<input name="scatter_mode" type="string" value="T" /> | ||
</generalized_schlick_bsdf> | ||
<surface name="surface1" type="surfaceshader"> | ||
<input name="bsdf" type="BSDF" nodename="bsdf1" /> | ||
</surface> | ||
<output name="out" type="surfaceshader" nodename="surface1" /> | ||
</nodegraph> | ||
<nodegraph name="generalized_schlick_bsdf_RT"> | ||
<generalized_schlick_bsdf name="bsdf1" type="BSDF"> | ||
<input name="weight" type="float" value="1.0" /> | ||
<input name="color0" type="color3" value="0.7, 0.7, 0.7" /> | ||
<input name="color90" type="color3" value="1.0, 1.0, 1.0" /> | ||
<input name="scatter_mode" type="string" value="RT" /> | ||
</generalized_schlick_bsdf> | ||
<surface name="surface1" type="surfaceshader"> | ||
<input name="bsdf" type="BSDF" nodename="bsdf1" /> | ||
</surface> | ||
<output name="out" type="surfaceshader" nodename="surface1" /> | ||
</nodegraph> | ||
<nodegraph name="generalized_schlick_bsdf_layeredRT"> | ||
<generalized_schlick_bsdf name="bsdf1" type="BSDF"> | ||
<input name="weight" type="float" value="1.0" /> | ||
<input name="color0" type="color3" value="0.7, 0.7, 0.7" /> | ||
<input name="color90" type="color3" value="1.0, 1.0, 1.0" /> | ||
<input name="scatter_mode" type="string" value="R" /> | ||
</generalized_schlick_bsdf> | ||
<generalized_schlick_bsdf name="bsdf2" type="BSDF"> | ||
<input name="weight" type="float" value="1.0" /> | ||
<input name="color0" type="color3" value="1.0, 1.0, 1.0" /> | ||
<input name="color90" type="color3" value="1.0, 1.0, 1.0" /> | ||
<input name="scatter_mode" type="string" value="T" /> | ||
</generalized_schlick_bsdf> | ||
<layer name="layer1" type="BSDF"> | ||
<input name="top" type="BSDF" nodename="bsdf1" /> | ||
<input name="base" type="BSDF" nodename="bsdf2" /> | ||
<layer name="layer_RT" type="BSDF"> | ||
<input name="top" type="BSDF" nodename="dielectric_R" /> | ||
<input name="base" type="BSDF" nodename="dielectric_T" /> | ||
</layer> | ||
<surface name="surface1" type="surfaceshader"> | ||
<input name="bsdf" type="BSDF" nodename="layer1" /> | ||
<surface name="surface_layer_RT" type="surfaceshader"> | ||
<input name="bsdf" type="BSDF" nodename="layer_RT" /> | ||
</surface> | ||
<output name="out" type="surfaceshader" nodename="surface1" /> | ||
<output name="layer_RT_out" type="surfaceshader" nodename="surface_layer_RT" /> | ||
</nodegraph> | ||
</materialx> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note for the future that we need to split this switch in two later to support thin-walled materials. We then need to have separate control of transmission and refraction on/off, since we can have transmission without refraction in that case, but still transmission with a roughness.