52 const uint32_t path_flag,
59 uint mix_weight_offset;
95 uint specular_ior_level_offset;
96 uint roughness_offset;
97 uint specular_tint_offset;
98 uint anisotropic_offset;
99 uint sheen_weight_offset;
100 uint sheen_tint_offset;
101 uint sheen_roughness_offset;
102 uint coat_weight_offset;
103 uint coat_roughness_offset;
104 uint coat_ior_offset;
106 uint transmission_weight_offset;
107 uint anisotropic_rotation_offset;
108 uint coat_tint_offset;
109 uint coat_normal_offset;
111 uint emission_strength_offset;
112 uint emission_offset;
113 uint thinfilm_thickness_offset;
114 uint diffuse_roughness_offset;
119 &specular_ior_level_offset,
121 &specular_tint_offset,
122 &anisotropic_offset);
124 &sheen_weight_offset,
126 &sheen_roughness_offset,
127 &diffuse_roughness_offset);
130 &transmission_weight_offset,
131 &anisotropic_rotation_offset,
132 &coat_normal_offset);
135 &coat_roughness_offset,
140 const float metallic =
saturatef(param1);
142 const float subsurface_weight =
saturatef(param2);
144 const float subsurface_weight = 0.0f;
159 const float transmission_weight =
saturatef(
161 const float anisotropic_rotation =
stack_load_float(stack, anisotropic_rotation_offset);
191 &emission_strength_offset,
193 &thinfilm_thickness_offset);
198 const float emission_strength =
stack_valid(emission_strength_offset) ?
209 float alpha_x =
sqr(roughness);
210 float alpha_y =
sqr(roughness);
211 if (anisotropic > 0.0f) {
212 const float aspect =
sqrtf(1.0f - anisotropic * 0.9f);
215 if (anisotropic_rotation != 0.0f) {
220#ifdef __CAUSTICS_TRICKS__
221 const bool reflective_caustics = (
kernel_data.integrator.caustics_reflective ||
223 const bool refractive_caustics = (
kernel_data.integrator.caustics_refractive ||
226 const bool reflective_caustics =
true;
227 const bool refractive_caustics =
true;
243 bsdf->roughness = sheen_roughness;
249 sd->flag |= sheen_flag;
253 kg, sd, (
ccl_private ShaderClosure *)bsdf,
true,
false);
262 if (reflective_caustics) {
267 bsdf->N = coat_normal;
269 bsdf->ior = coat_ior;
271 bsdf->alpha_x = bsdf->alpha_y =
sqr(coat_roughness);
279 kg, sd, (
ccl_private ShaderClosure *)bsdf,
true,
false);
303 const float cosNI =
dot(sd->wi, coat_normal);
306 const float cosNT =
sqrtf(1.0f -
sqr(1.0f / coat_ior) * (1 -
sqr(cosNI)));
307 const float optical_depth = 1.0f / cosNT;
320 if (reflective_caustics) {
328 if (bsdf && fresnel) {
329 bsdf->N = valid_reflection_N;
332 bsdf->alpha_x = alpha_x;
333 bsdf->alpha_y = alpha_y;
345 weight *= (1.0f - metallic);
350 if (reflective_caustics || refractive_caustics) {
358 if (bsdf && fresnel) {
359 bsdf->N = valid_reflection_N;
362 bsdf->alpha_x = bsdf->alpha_y =
sqr(roughness);
367 fresnel->exponent = -ior;
369 fresnel->transmission_tint = refractive_caustics ?
372 fresnel->thin_film.thickness = thinfilm_thickness;
373 fresnel->thin_film.ior = (sd->flag &
SD_BACKFACING) ? thinfilm_ior / ior :
383 weight *= (1.0f - transmission_weight);
389 if (specular_ior_level != 0.5f) {
390 f0 *= 2.0f * specular_ior_level;
398 if (reflective_caustics && (eta != 1.0f || thinfilm_thickness > 0.1f)) {
406 if (bsdf && fresnel) {
407 bsdf->N = valid_reflection_N;
410 bsdf->alpha_x = alpha_x;
411 bsdf->alpha_y = alpha_y;
413 fresnel->f0 = f0 * specular_tint;
415 fresnel->exponent = -eta;
418 fresnel->thin_film.thickness = thinfilm_thickness;
419 fresnel->thin_film.ior = thinfilm_ior;
428 kg, sd, (
ccl_private ShaderClosure *)bsdf,
true,
false);
467 const float diffuse_roughness =
saturatef(
474 bsdf->roughness = diffuse_roughness;
489 const float roughness = param1;
491 if (roughness == 0.0f) {
495 bsdf->roughness = roughness;
520#ifdef __CAUSTICS_TRICKS__
528 if (bsdf !=
nullptr) {
529 uint base_ior_offset;
530 uint edge_tint_k_offset;
531 uint rotation_offset;
534 node.
z, &base_ior_offset, &edge_tint_k_offset, &rotation_offset, &tangent_offset);
538 const float anisotropy =
saturatef(param2);
539 const float roughness =
saturatef(param1);
540 float alpha_x =
sqr(roughness);
541 float alpha_y =
sqr(roughness);
542 if (anisotropy > 0.0f) {
543 const float aspect =
sqrtf(1.0f - anisotropy * 0.9f);
546 const float anisotropic_rotation =
stack_load_float(stack, rotation_offset);
547 if (anisotropic_rotation != 0.0f) {
552 bsdf->N = valid_reflection_N;
555 bsdf->alpha_x = alpha_x;
556 bsdf->alpha_y = alpha_y;
605#ifdef __CAUSTICS_TRICKS__
624 const float anisotropy =
clamp(param2, -0.99f, 0.99f);
628 bsdf->alpha_x = roughness;
629 bsdf->alpha_y = roughness;
636 if (rotation != 0.0f) {
640 if (anisotropy < 0.0f) {
641 bsdf->alpha_x = roughness / (1.0f + anisotropy);
642 bsdf->alpha_y = roughness * (1.0f + anisotropy);
645 bsdf->alpha_x = roughness * (1.0f - anisotropy);
646 bsdf->alpha_y = roughness / (1.0f - anisotropy);
671#ifdef __CAUSTICS_TRICKS__
684 float eta =
fmaxf(param2, 1e-5f);
688 const float roughness =
sqr(param1);
689 bsdf->alpha_x = roughness;
690 bsdf->alpha_y = roughness;
706#ifdef __CAUSTICS_TRICKS__
707 const bool reflective_caustics = (
kernel_data.integrator.caustics_reflective ||
709 const bool refractive_caustics = (
kernel_data.integrator.caustics_refractive ||
711 if (!(reflective_caustics || refractive_caustics)) {
715 const bool reflective_caustics =
true;
716 const bool refractive_caustics =
true;
725 if (bsdf && fresnel) {
729 const float ior =
fmaxf(param2, 1e-5f);
735 fresnel->exponent = -ior;
738 fresnel->transmission_tint = refractive_caustics ?
rgb_to_spectrum(color) :
740 fresnel->thin_film.thickness = 0.0f;
741 fresnel->thin_film.ior = 0.0f;
782#ifdef __CAUSTICS_TRICKS__
796 bsdf->smooth = param2;
808# ifdef __PRINCIPLED_HAIR__
820 uint parametrization;
827 uint melanin_redness_ofs;
828 uint absorption_coefficient_ofs;
832 &melanin_redness_ofs,
833 &absorption_coefficient_ofs);
837 uint random_color_ofs;
840 data_node3.
x, &shared_ofs1, &random_ofs, &random_color_ofs, &shared_ofs2);
852 const float random_roughness = param2;
853 const float factor_random_roughness = 1.0f + 2.0f * (
random - 0.5f) * random_roughness;
854 const float roughness = param1 * factor_random_roughness;
857 stack, shared_ofs2, data_node4.
y) *
858 factor_random_roughness :
862 switch (parametrization) {
865 absorption_coefficient_ofs);
872 stack, melanin_redness_ofs, data_node2.
w);
876 random_color =
clamp(random_color, 0.0f, 1.0f);
877 const float factor_random_color = 1.0f + 2.0f * (
random - 0.5f) * random_color;
878 melanin *= factor_random_color;
881 melanin = -
logf(
fmaxf(1.0f - melanin, 0.0001f));
884 const float eumelanin = melanin * (1.0f - melanin_redness);
885 const float pheomelanin = melanin * melanin_redness;
887 eumelanin, pheomelanin);
894 sigma = melanin_sigma + tint_sigma;
917 const float m0_roughness = 1.0f -
clamp(coat, 0.0f, 1.0f);
920 bsdf->s = radial_roughness;
921 bsdf->m0_roughness = m0_roughness;
926 sd->flag |= bsdf_hair_chiang_setup(sd, bsdf);
939 if (
R <= 0.0f && TT <= 0.0f && TRT <= 0.0f) {
954 bsdf->extra->
R =
fmaxf(0.0f,
R);
955 bsdf->extra->TT =
fmaxf(0.0f, TT);
956 bsdf->extra->TRT =
fmaxf(0.0f, TRT);
958 bsdf->extra->pixel_coverage = 1.0f;
966 const int k1 = k0 + 1;
967 const float radius =
mix(
970 bsdf->extra->pixel_coverage = 0.5f * sd->dP / radius;
974 if (bsdf->aspect_ratio != 1.0f) {
977 bsdf->N = curve_attribute<float3>(kg, sd, attr_descr_normal,
nullptr,
nullptr);
980 bsdf->roughness = roughness;
985 sd->flag |= bsdf_hair_huang_setup(sd, bsdf, path_flag);
1000 bsdf->roughness1 = param1;
1001 bsdf->roughness2 = param2;
1009 bsdf->offset = 0.0f;
1027#ifdef __SUBSURFACE__
1037 bssrdf->albedo = closure_weight;