@@ -159,11 +159,16 @@ export material mx_dielectric_bsdf(
159159]]
160160= let {
161161 float coatIor = mxp_thinfilm_ior <= 0.0 ? 1.0 : mxp_thinfilm_ior;
162+ float grazing_refl = math::max((1.0 - math::average(mxp_roughness)), 0.0);
163+ float root_r = (mxp_ior-1)/(mxp_ior+1);
162164 bsdf bsdf_R = df::thin_film(
163165 thickness: mxp_thinfilm_thickness,
164166 ior: color(coatIor),
165- base: df::fresnel_layer(
166- ior: mxp_ior,
167+ // fresnel layer has issues if base is a diffuse transmission, use custom curve for now
168+ // this will break thin_film but improves standard_surface with diffuse transmission
169+ base: df::custom_curve_layer(
170+ normal_reflectivity: root_r*root_r,
171+ grazing_reflectivity: grazing_refl,
167172 weight: mxp_weight,
168173 layer: df::microfacet_ggx_smith_bsdf(
169174 roughness_u: mxp_roughness.x,
@@ -172,16 +177,16 @@ export material mx_dielectric_bsdf(
172177 tangent_u: mxp_tangent,
173178 mode: df::scatter_reflect),
174179 base: mxp_base.surface.scattering,
175- normal: mxp_normal));
180+ normal: mxp_normal));
176181
177182 bsdf bsdf_T = df::weighted_layer(
178183 weight: mxp_weight,
179184 layer: df::microfacet_ggx_smith_bsdf(
180- roughness_u: mxp_roughness.x,
181- roughness_v: mxp_roughness.y,
182- tint: mxp_tint,
183- tangent_u: mxp_tangent,
184- mode: df::scatter_transmit),
185+ roughness_u: mxp_roughness.x,
186+ roughness_v: mxp_roughness.y,
187+ tint: mxp_tint,
188+ tangent_u: mxp_tangent,
189+ mode: df::scatter_transmit),
185190 normal: mxp_normal);
186191
187192 bsdf bsdf_RT = df::weighted_layer(
@@ -255,7 +260,7 @@ export material mx_generalized_schlick_bsdf(
255260 color mxp_color0 = color(1.0),
256261 color mxp_color90 = color(1.0),
257262 float mxp_exponent = 5.0,
258- float2 mxp_roughness = float2(0.0 ),
263+ float2 mxp_roughness = float2(0.05 ),
259264 float3 mxp_normal = state::normal(),
260265 float3 mxp_tangent = state::texture_tangent_u(0),
261266 uniform mx_distribution_type mxp_distribution = mx_distribution_type_ggx [[ anno::unused() ]],
@@ -268,31 +273,51 @@ export material mx_generalized_schlick_bsdf(
268273]]
269274= let {
270275 float coatIor = mxp_thinfilm_ior <= 0.0 ? 1.0 : mxp_thinfilm_ior;
271- df::scatter_mode mode = ::mx_map_scatter_mode(mxp_scatter_mode);
272- bsdf ggx_model = df::microfacet_ggx_smith_bsdf(
273- roughness_u: mxp_roughness.x * mxp_roughness.x,
274- roughness_v: mxp_roughness.y * mxp_roughness.y,
276+ float avgF0 = math::average(float3(mxp_color0));
277+ bsdf ggx_model_R = df::microfacet_ggx_smith_bsdf(
278+ roughness_u: mxp_roughness.x,
279+ roughness_v: mxp_roughness.y,
280+ tint: color(1.0),
281+ tangent_u: mxp_tangent,
282+ mode: df::scatter_reflect);
283+
284+ bsdf ggx_model_T = df::microfacet_ggx_smith_bsdf(
285+ roughness_u: mxp_roughness.x,
286+ roughness_v: mxp_roughness.y,
275287 tint: color(1.0),
276288 tangent_u: mxp_tangent,
277- mode: mode );
289+ mode: df::scatter_transmit );
278290} in material(
279291 surface: material_surface(
280- scattering: df::thin_film(
281- thickness: mxp_thinfilm_thickness,
282- ior: color(coatIor),
283- base: df::color_custom_curve_layer(
284- normal_reflectivity: mxp_color0,
285- grazing_reflectivity: mxp_color90,
286- exponent: mxp_exponent,
287- weight: color(mxp_weight),
288- layer: ggx_model,
289- base: mxp_base.surface.scattering,
290- normal: mxp_normal
291- )
292+ scattering: df::weighted_layer(
293+ weight: mxp_weight,
294+ layer: mxp_scatter_mode == mx_scatter_mode_T
295+ ? df::color_custom_curve_layer(
296+ normal_reflectivity: mxp_color0,
297+ grazing_reflectivity: mxp_color90,
298+ exponent: mxp_exponent,
299+ layer: bsdf(),
300+ base: ggx_model_T)
301+ : df::thin_film(
302+ thickness: mxp_thinfilm_thickness,
303+ ior: color(coatIor),
304+ base: df::color_custom_curve_layer(
305+ normal_reflectivity: mxp_color0,
306+ grazing_reflectivity: mxp_color90,
307+ exponent: mxp_exponent,
308+ layer: ggx_model_R,
309+ base: mxp_scatter_mode == mx_scatter_mode_R
310+ ? mxp_base.surface.scattering
311+ : ggx_model_T)),
312+ base: mxp_base.surface.scattering,
313+ normal: mxp_normal
292314 )
293315 ),
316+ // we can't use the computed ior here because it's varying
317+ // assuming that we have something glass like when transmission is used
318+ ior: color(1.5), // color(mx_f0_to_ior(avgF0))
319+
294320 // we need to carry volume properties along for SSS
295- ior: mxp_base.ior,
296321 volume: mxp_base.volume
297322);
298323
@@ -513,7 +538,7 @@ export material mx_surface(
513538 material mxp_bsdf = material() [[ anno::usage( "materialx:bsdf") ]],
514539 material mxp_edf = material() [[ anno::usage( "materialx:edf") ]],
515540 float mxp_opacity = 1.0,
516- uniform float mxp_transmission_ior = 1 .0 // extra parameter for setting transmission IOR
541+ uniform float mxp_transmission_ior = 0 .0 // extra parameter for setting transmission IOR
517542) [[
518543 anno::usage( "materialx:surfaceshader")
519544]]
@@ -528,7 +553,7 @@ export material mx_surface(
528553 scattering: bsdf_node,
529554 emission: edf_node
530555 ),
531- ior: color(mxp_transmission_ior),
556+ ior: mxp_transmission_ior > 0.0 ? color(mxp_transmission_ior) : mxp_bsdf.ior ,
532557 volume: bsdf_volume,
533558 geometry: material_geometry(
534559 cutout_opacity: mxp_opacity
0 commit comments