46 uint type, param1_offset, param2_offset;
48 uint mix_weight_offset;
83 uint specular_ior_level_offset, roughness_offset, specular_tint_offset, anisotropic_offset,
84 sheen_weight_offset, sheen_tint_offset, sheen_roughness_offset, coat_weight_offset,
85 coat_roughness_offset, coat_ior_offset, eta_offset, transmission_weight_offset,
86 anisotropic_rotation_offset, coat_tint_offset, coat_normal_offset, alpha_offset,
87 emission_strength_offset, emission_offset, thinfilm_thickness_offset,
88 diffuse_roughness_offset;
93 &specular_ior_level_offset,
95 &specular_tint_offset,
100 &sheen_roughness_offset,
101 &diffuse_roughness_offset);
104 &transmission_weight_offset,
105 &anisotropic_rotation_offset,
106 &coat_normal_offset);
109 &coat_roughness_offset,
115 float subsurface_weight =
saturatef(param2);
129 float anisotropic_rotation =
stack_load_float(stack, anisotropic_rotation_offset);
159 &emission_strength_offset,
161 &thinfilm_thickness_offset);
166 float emission_strength =
stack_valid(emission_strength_offset) ?
176 float alpha_x =
sqr(roughness), alpha_y =
sqr(roughness);
177 if (anisotropic > 0.0f) {
178 float aspect =
sqrtf(1.0f - anisotropic * 0.9f);
181 if (anisotropic_rotation != 0.0f)
185#ifdef __CAUSTICS_TRICKS__
186 const bool reflective_caustics = (
kernel_data.integrator.caustics_reflective ||
188 const bool refractive_caustics = (
kernel_data.integrator.caustics_refractive ||
191 const bool reflective_caustics =
true;
192 const bool refractive_caustics =
true;
208 bsdf->roughness = sheen_roughness;
214 sd->flag |= sheen_flag;
226 if (reflective_caustics) {
231 bsdf->N = coat_normal;
233 bsdf->ior = coat_ior;
235 bsdf->alpha_x = bsdf->alpha_y =
sqr(coat_roughness);
266 float cosNI =
dot(sd->wi, coat_normal);
269 float cosNT =
sqrtf(1.0f -
sqr(1.0f / coat_ior) * (1 -
sqr(cosNI)));
270 float optical_depth = 1.0f / cosNT;
283 if (reflective_caustics) {
291 if (bsdf && fresnel) {
292 bsdf->N = valid_reflection_N;
295 bsdf->alpha_x = alpha_x;
296 bsdf->alpha_y = alpha_y;
313 if (reflective_caustics || refractive_caustics) {
321 if (bsdf && fresnel) {
322 bsdf->N = valid_reflection_N;
325 bsdf->alpha_x = bsdf->alpha_y =
sqr(roughness);
330 fresnel->exponent = -ior;
332 fresnel->transmission_tint = refractive_caustics ?
335 fresnel->thin_film.thickness = thinfilm_thickness;
336 fresnel->thin_film.ior = (sd->flag &
SD_BACKFACING) ? thinfilm_ior / ior :
346 weight *= (1.0f - transmission_weight);
352 if (specular_ior_level != 0.5f) {
353 f0 *= 2.0f * specular_ior_level;
361 if (reflective_caustics && (eta != 1.0f || thinfilm_thickness > 0.1f)) {
369 if (bsdf && fresnel) {
370 bsdf->N = valid_reflection_N;
373 bsdf->alpha_x = alpha_x;
374 bsdf->alpha_y = alpha_y;
376 fresnel->f0 = f0 * specular_tint;
378 fresnel->exponent = -eta;
381 fresnel->thin_film.thickness = thinfilm_thickness;
382 fresnel->thin_film.ior = thinfilm_ior;
419 subsurface_weight = 0.0f;
430 const float diffuse_roughness =
saturatef(
437 bsdf->roughness = diffuse_roughness;
452 float roughness = param1;
454 if (roughness == 0.0f) {
458 bsdf->roughness = roughness;
483#ifdef __CAUSTICS_TRICKS__
491 uint base_ior_offset, edge_tint_k_offset, rotation_offset, tangent_offset;
493 node.z, &base_ior_offset, &edge_tint_k_offset, &rotation_offset, &tangent_offset);
497 const float anisotropy =
saturatef(param2);
498 const float roughness =
saturatef(param1);
499 float alpha_x =
sqr(roughness), alpha_y =
sqr(roughness);
500 if (anisotropy > 0.0f) {
501 float aspect =
sqrtf(1.0f - anisotropy * 0.9f);
505 if (anisotropic_rotation != 0.0f) {
510 bsdf->N = valid_reflection_N;
513 bsdf->alpha_x = alpha_x;
514 bsdf->alpha_y = alpha_y;
563#ifdef __CAUSTICS_TRICKS__
581 float anisotropy =
clamp(param2, -0.99f, 0.99f);
585 bsdf->alpha_x = roughness;
586 bsdf->alpha_y = roughness;
593 if (rotation != 0.0f) {
597 if (anisotropy < 0.0f) {
598 bsdf->alpha_x = roughness / (1.0f + anisotropy);
599 bsdf->alpha_y = roughness * (1.0f + anisotropy);
602 bsdf->alpha_x = roughness * (1.0f - anisotropy);
603 bsdf->alpha_y = roughness / (1.0f - anisotropy);
628#ifdef __CAUSTICS_TRICKS__
640 float eta =
fmaxf(param2, 1e-5f);
644 float roughness =
sqr(param1);
645 bsdf->alpha_x = roughness;
646 bsdf->alpha_y = roughness;
662#ifdef __CAUSTICS_TRICKS__
663 const bool reflective_caustics = (
kernel_data.integrator.caustics_reflective ||
665 const bool refractive_caustics = (
kernel_data.integrator.caustics_refractive ||
667 if (!(reflective_caustics || refractive_caustics))
670 const bool reflective_caustics =
true;
671 const bool refractive_caustics =
true;
680 if (bsdf && fresnel) {
684 float ior =
fmaxf(param2, 1e-5f);
690 fresnel->exponent = -ior;
693 fresnel->transmission_tint = refractive_caustics ?
rgb_to_spectrum(color) :
695 fresnel->thin_film.thickness = 0.0f;
696 fresnel->thin_film.ior = 0.0f;
737#ifdef __CAUSTICS_TRICKS__
750 bsdf->smooth = param2;
762# ifdef __PRINCIPLED_HAIR__
771 uint offset_ofs, ior_ofs, color_ofs, parametrization;
776 uint tint_ofs, melanin_ofs, melanin_redness_ofs, absorption_coefficient_ofs;
780 &melanin_redness_ofs,
781 &absorption_coefficient_ofs);
783 uint shared_ofs1, random_ofs, random_color_ofs, shared_ofs2;
785 data_node3.
x, &shared_ofs1, &random_ofs, &random_color_ofs, &shared_ofs2);
797 float random_roughness = param2;
798 float factor_random_roughness = 1.0f + 2.0f * (random - 0.5f) * random_roughness;
799 float roughness = param1 * factor_random_roughness;
802 factor_random_roughness :
806 switch (parametrization) {
815 stack, melanin_redness_ofs, data_node2.
w);
819 random_color =
clamp(random_color, 0.0f, 1.0f);
820 float factor_random_color = 1.0f + 2.0f * (random - 0.5f) * random_color;
821 melanin *= factor_random_color;
824 melanin = -
logf(
fmaxf(1.0f - melanin, 0.0001f));
827 float eumelanin = melanin * (1.0f - melanin_redness);
828 float pheomelanin = melanin * melanin_redness;
837 sigma = melanin_sigma + tint_sigma;
860 float m0_roughness = 1.0f -
clamp(coat, 0.0f, 1.0f);
863 bsdf->s = radial_roughness;
864 bsdf->m0_roughness = m0_roughness;
869 sd->flag |= bsdf_hair_chiang_setup(sd, bsdf);
874 uint R_ofs, TT_ofs, TRT_ofs, unused;
879 if (
R <= 0.0f && TT <= 0.0f && TRT <= 0.0f) {
894 bsdf->extra->
R =
fmaxf(0.0f,
R);
895 bsdf->extra->TT =
fmaxf(0.0f, TT);
896 bsdf->extra->TRT =
fmaxf(0.0f, TRT);
898 bsdf->extra->pixel_coverage = 1.0f;
906 const int k1 = k0 + 1;
907 const float radius =
mix(
910 bsdf->extra->pixel_coverage = 0.5f * sd->dP / radius;
914 if (bsdf->aspect_ratio != 1.0f) {
917 bsdf->N = curve_attribute_float3(kg, sd, attr_descr_normal,
NULL,
NULL);
920 bsdf->roughness = roughness;
925 sd->flag |= bsdf_hair_huang_setup(sd, bsdf, path_flag);
940 bsdf->roughness1 = param1;
941 bsdf->roughness2 = param2;
976 bssrdf->albedo = closure_weight;