171 const uint32_t path_flag,
183 if (mix_weight == 0.0f) {
218 kg, sd, stack, data,
N, ray_visibility, path_flag, mix_weight);
222 const Spectrum clamped_base_color =
min(base_color, white);
228 const ClosureType distribution = data.distribution;
236 float alpha_x =
sqr(roughness);
237 float alpha_y =
sqr(roughness);
239 if (anisotropic > 0.0f &&
stack_valid(data.tangent_offset)) {
241 const float aspect =
sqrtf(1.0f - anisotropic * 0.9f);
244 const float anisotropic_rotation =
stack_load(stack, data.anisotropic_rotation);
245 if (anisotropic_rotation != 0.0f) {
250#ifdef __CAUSTICS_TRICKS__
251 const bool reflective_caustics = (
kernel_data.integrator.caustics_reflective ||
253 const bool refractive_caustics = (
kernel_data.integrator.caustics_refractive ||
256 const bool reflective_caustics =
true;
257 const bool refractive_caustics =
true;
263 if (reflective_caustics) {
271 if (bsdf && fresnel) {
272 bsdf->N = valid_reflection_N;
275 bsdf->alpha_x = alpha_x;
276 bsdf->alpha_y = alpha_y;
278 fresnel->f0 = clamped_base_color;
282 fresnel->thin_film.ior = thinfilm_ior;
291 weight *= (1.0f - metallic);
294 const bool thin_wall =
stack_load(stack, data.thin_wall);
299 if (reflective_caustics || refractive_caustics) {
306 {specular_tint, clamped_base_color},
307 transmission_weight * weight,
323 if (bsdf && fresnel) {
325 bsdf->N = valid_reflection_N;
327 bsdf->alpha_x = alpha_x;
328 bsdf->alpha_y = alpha_y;
330 const float dispersion_scale =
saturatef(
331 stack_load(stack, data.transmission_dispersion_scale));
332 const float abbe_number =
fmaxf(
333 stack_load(stack, data.transmission_dispersion_abbe_number), 0.0f);
334 const float inv_abbe =
safe_divide(dispersion_scale, abbe_number);
335 bsdf->ior = backfacing ? 1.0f / ior : ior;
346 sqrt(clamped_base_color),
351 const bool is_multiggx = (distribution ==
354 kg, bsdf, sd->wi, fresnel, is_multiggx);
359 weight *= (1.0f - transmission_weight);
363 const float specular_ior_level =
max(
stack_load(stack, data.specular_ior_level), 0.0f);
366 if (specular_ior_level != 0.5f) {
367 f0 *= 2.0f * specular_ior_level;
383 if (bsdf && fresnel) {
384 bsdf->N = valid_reflection_N;
387 bsdf->alpha_x = alpha_x;
388 bsdf->alpha_y = alpha_y;
390 fresnel->f0 = f0 * specular_tint;
391 fresnel->f90 = white;
392 fresnel->exponent = -eta;
393 fresnel->tint = {white, black};
400 kg, bsdf, sd->wi, fresnel, is_multiggx);
412 const float anisotropy =
stack_load(stack, data.subsurface_anisotropy);
413 const Spectrum closure_weight = clamped_base_color * subsurface_weight * weight;
417 sd,
N, closure_weight, anisotropy, diffuse_roughness, clamped_base_color);
420 const ClosureType subsurface_method = data.subsurface_method;
424 const float subsurface_scale =
stack_load(stack, data.subsurface_scale);
428 bssrdf->albedo = clamped_base_color;
434 bssrdf->anisotropy = anisotropy;
445 const float subsurface_weight = 0.0f;
449 const Spectrum diffuse_weight = base_color * (1.0f - subsurface_weight) * weight;
465 const Spectrum weight = closure_weight * mix_weight;
466 const float roughness =
stack_load(stack, bsdf_data.roughness);
482 const Spectrum weight = closure_weight * mix_weight;
490 const Spectrum weight = closure_weight * mix_weight;
499#ifdef __CAUSTICS_TRICKS__
509 if (bsdf !=
nullptr) {
515 bsdf->alpha_x =
sqr(roughness);
516 bsdf->alpha_y =
sqr(roughness);
517 if (anisotropy > 0.0f &&
stack_valid(cdata.tangent_offset)) {
519 const float aspect =
sqrtf(1.0f - anisotropy * 0.9f);
520 bsdf->alpha_x /= aspect;
521 bsdf->alpha_y *= aspect;
522 const float anisotropic_rotation =
stack_load(stack, cdata.rotation);
523 if (anisotropic_rotation != 0.0f) {
531 bsdf->N = valid_reflection_N;
534 const float thin_film_thickness =
fmaxf(
stack_load(stack, cdata.thin_film_thickness),
536 const float thin_film_ior =
fmaxf(
stack_load(stack, cdata.thin_film_ior), 1e-5f);
538 const ClosureType distribution = cdata.distribution;
557 fresnel->thin_film.thickness = thin_film_thickness;
558 fresnel->thin_film.ior = thin_film_ior;
574 fresnel->thin_film.thickness = thin_film_thickness;
575 fresnel->thin_film.ior = thin_film_ior;
590 const Spectrum weight = closure_weight * mix_weight;
603#ifdef __CAUSTICS_TRICKS__
613 const Spectrum weight = closure_weight * mix_weight;
627 const float anisotropy =
clamp(
stack_load(stack, bsdf_data.anisotropy), -0.99f, 0.99f);
631 bsdf->alpha_x = roughness;
632 bsdf->alpha_y = roughness;
638 const float rotation =
stack_load(stack, bsdf_data.rotation);
639 if (rotation != 0.0f) {
643 if (anisotropy < 0.0f) {
644 bsdf->alpha_x = roughness / (1.0f + anisotropy);
645 bsdf->alpha_y = roughness * (1.0f + anisotropy);
648 bsdf->alpha_x = roughness * (1.0f - anisotropy);
649 bsdf->alpha_y = roughness / (1.0f - anisotropy);
675#ifdef __CAUSTICS_TRICKS__
685 const Spectrum weight = closure_weight * mix_weight;
697 const float roughness =
sqr(
stack_load(stack, bsdf_data.roughness));
698 bsdf->alpha_x = roughness;
699 bsdf->alpha_y = roughness;
718#ifdef __CAUSTICS_TRICKS__
719 const bool reflective_caustics = (
kernel_data.integrator.caustics_reflective ||
721 const bool refractive_caustics = (
kernel_data.integrator.caustics_refractive ||
723 if (!(reflective_caustics || refractive_caustics)) {
727 const bool reflective_caustics =
true;
728 const bool refractive_caustics =
true;
735 const float thinfilm_ior =
fmaxf(
stack_load(stack, bsdf_data.thin_film_ior), 1e-5f);
744 if (bsdf && fresnel) {
746 const float anisotropy =
clamp(
stack_load(stack, bsdf_data.anisotropy), -0.99f, 0.99f);
751 bsdf->alpha_x = bsdf->alpha_y = roughness;
757 const float rotation =
stack_load(stack, bsdf_data.rotation);
758 if (rotation != 0.0f) {
762 if (anisotropy < 0.0f) {
763 bsdf->alpha_x = roughness / (1.0f + anisotropy);
764 bsdf->alpha_y = roughness * (1.0f + anisotropy);
767 bsdf->alpha_x = roughness * (1.0f - anisotropy);
768 bsdf->alpha_y = roughness / (1.0f - anisotropy);
773 bsdf->ior = (sd->runtime_flag &
SR_BACKFACING) ? 1.0f / ior : ior;
776 fresnel->f90 = white;
777 fresnel->exponent = -ior;
779 fresnel->tint = {
float(reflective_caustics) * color,
float(refractive_caustics) * color};
781 fresnel->thin_film.ior = (sd->runtime_flag &
SR_BACKFACING) ? thinfilm_ior / ior :
801 const Spectrum weight = closure_weight * mix_weight;
819 const Spectrum weight = closure_weight * mix_weight;
829#ifdef __CAUSTICS_TRICKS__
839 const Spectrum weight = closure_weight * mix_weight;
845 bsdf->size =
stack_load(stack, bsdf_data.size);
846 bsdf->smooth =
stack_load(stack, bsdf_data.smooth);
862#if defined(__HAIR__) && defined(__PRINCIPLED_HAIR__)
863 const Spectrum weight = closure_weight * mix_weight;
865 const float alpha =
stack_load(stack, hdata.offset);
866 const float ior =
stack_load(stack, hdata.ior);
878 const float random_roughness =
stack_load(stack, hdata.random_roughness);
879 const float factor_random_roughness = 1.0f + 2.0f * (
random - 0.5f) * random_roughness;
880 const float roughness =
stack_load(stack, hdata.roughness) * factor_random_roughness;
883 factor_random_roughness :
887 switch (hdata.parametrization) {
889 const float3 absorption_coefficient =
stack_load(stack, hdata.absorption_coefficient);
894 float melanin =
stack_load(stack, hdata.melanin);
895 const float melanin_redness =
stack_load(stack, hdata.melanin_redness);
898 float random_color =
stack_load(stack, hdata.random_color);
899 random_color =
clamp(random_color, 0.0f, 1.0f);
900 const float factor_random_color = 1.0f + 2.0f * (
random - 0.5f) * random_color;
901 melanin *= factor_random_color;
904 melanin = -
logf(
fmaxf(1.0f - melanin, 0.0001f));
907 const float eumelanin = melanin * (1.0f - melanin_redness);
908 const float pheomelanin = melanin * melanin_redness;
910 eumelanin, pheomelanin);
917 sigma = melanin_sigma + tint_sigma;
939 const float coat =
stack_load(stack, hdata.coat);
940 const float m0_roughness = 1.0f -
clamp(coat, 0.0f, 1.0f);
943 bsdf->s = radial_roughness;
944 bsdf->m0_roughness = m0_roughness;
949 sd->runtime_flag |= bsdf_hair_chiang_setup(sd, bsdf);
956 const float TRT =
stack_load(stack, hdata.TRT);
957 if (
R <= 0.0f && TT <= 0.0f && TRT <= 0.0f) {
972 bsdf->extra->R =
fmaxf(0.0f,
R);
973 bsdf->extra->TT =
fmaxf(0.0f, TT);
974 bsdf->extra->TRT =
fmaxf(0.0f, TRT);
976 bsdf->extra->pixel_coverage = 1.0f;
984 const int k1 = k0 + 1;
985 const int position_offset =
kernel_data_fetch(objects, sd->object).position_offset;
990 bsdf->extra->pixel_coverage = 0.5f * sd->dP / radius;
993 bsdf->aspect_ratio =
stack_load(stack, hdata.aspect_ratio);
994 if (bsdf->aspect_ratio != 1.0f) {
997 kg, sd, hdata.attr_normal);
998 bsdf->N = curve_attribute<float3>(kg, sd, attr_descr_normal);
1001 bsdf->roughness = roughness;
1004 bsdf->sigma = sigma;
1006 sd->runtime_flag |= bsdf_hair_huang_setup(sd, bsdf, path_flag);
1020 const Spectrum weight = closure_weight * mix_weight;
1027 bsdf->roughness1 =
stack_load(stack, bsdf_data.roughness1);
1028 bsdf->roughness2 =
stack_load(stack, bsdf_data.roughness2);
1029 bsdf->offset = -
stack_load(stack, bsdf_data.offset);
1036 bsdf->offset = 0.0f;
1061#ifdef __SUBSURFACE__
1065 const Spectrum weight = closure_weight * mix_weight;
1071 bssrdf->albedo = closure_weight;