50 const uint32_t path_flag,
57 uint mix_weight_offset;
93 uint base_color_offset;
96 uint coat_normal_offset;
97 uint distribution_uint;
98 uint diffuse_roughness_offset;
99 uint specular_ior_level_offset;
100 uint specular_tint_offset;
101 uint emission_strength_offset;
102 uint emission_color_offset;
103 uint anisotropic_offset;
104 uint thin_film_thickness_offset;
105 uint subsurface_weight_offset;
106 uint coat_weight_offset;
107 uint sheen_weight_offset;
108 uint transmission_weight_offset;
109 uint coat_roughness_offset;
110 uint coat_ior_offset;
111 uint coat_tint_offset;
112 uint subsurface_method_uint;
113 uint subsurface_radius_offset;
114 uint subsurface_scale_offset;
115 uint subsurface_ior_offset;
116 uint subsurface_anisotropy_offset;
117 uint sheen_roughness_offset;
118 uint sheen_tint_offset;
119 uint anisotropic_rotation_offset;
121 uint thin_film_ior_offset;
128 data_node.
y, &base_color_offset, &metallic_offset, &alpha_offset, &coat_normal_offset);
131 &diffuse_roughness_offset,
132 &specular_ior_level_offset,
133 &specular_tint_offset);
135 &emission_strength_offset,
136 &emission_color_offset,
138 &thin_film_thickness_offset);
140 &subsurface_weight_offset,
142 &sheen_weight_offset,
143 &transmission_weight_offset);
145 &coat_roughness_offset,
148 &subsurface_method_uint);
150 &subsurface_radius_offset,
151 &subsurface_scale_offset,
152 &subsurface_ior_offset,
153 &subsurface_anisotropy_offset);
155 &sheen_roughness_offset,
157 &anisotropic_rotation_offset,
159 thin_film_ior_offset = data_node3.
x;
167 const float ior =
fmaxf(param1, 1e-5f);
168 const float roughness =
saturatef(param2);
178 const float diffuse_roughness =
saturatef(
180 const float specular_ior_level =
max(
191 stack, thin_film_thickness_offset, 0.0f);
194 const float subsurface_weight =
saturatef(
197 const float subsurface_weight = 0.0f;
203 const float transmission_weight =
saturatef(
206 float thinfilm_ior = 0.0f;
215 float alpha_x =
sqr(roughness);
216 float alpha_y =
sqr(roughness);
218 if (anisotropic > 0.0f &&
stack_valid(tangent_offset)) {
220 const float aspect =
sqrtf(1.0f - anisotropic * 0.9f);
224 stack, anisotropic_rotation_offset, 0.0f);
225 if (anisotropic_rotation != 0.0f) {
230#ifdef __CAUSTICS_TRICKS__
231 const bool reflective_caustics = (
kernel_data.integrator.caustics_reflective ||
233 const bool refractive_caustics = (
kernel_data.integrator.caustics_refractive ||
236 const bool reflective_caustics =
true;
237 const bool refractive_caustics =
true;
257 bsdf->roughness = sheen_roughness;
263 sd->flag |= sheen_flag;
267 kg, sd, (
ccl_private ShaderClosure *)bsdf,
true,
false);
281 if (reflective_caustics) {
286 bsdf->N = valid_coat_normal;
288 bsdf->ior = coat_ior;
290 bsdf->alpha_x = bsdf->alpha_y =
sqr(coat_roughness);
298 kg, sd, (
ccl_private ShaderClosure *)bsdf,
true,
false);
322 const float cosNI =
dot(sd->wi, valid_coat_normal);
325 const float cosNT =
sqrtf(1.0f -
sqr(1.0f / coat_ior) * (1 -
sqr(cosNI)));
326 const float optical_depth = 1.0f / cosNT;
339 if (reflective_caustics) {
347 if (bsdf && fresnel) {
348 bsdf->N = valid_reflection_N;
351 bsdf->alpha_x = alpha_x;
352 bsdf->alpha_y = alpha_y;
358 fresnel->thin_film.ior = thinfilm_ior;
367 weight *= (1.0f - metallic);
372 if (reflective_caustics || refractive_caustics) {
380 if (bsdf && fresnel) {
381 bsdf->N = valid_reflection_N;
384 bsdf->alpha_x = bsdf->alpha_y =
sqr(roughness);
389 fresnel->exponent = -ior;
391 fresnel->transmission_tint = refractive_caustics ?
395 fresnel->thin_film.ior = (sd->flag &
SD_BACKFACING) ? thinfilm_ior / ior :
405 weight *= (1.0f - transmission_weight);
411 if (specular_ior_level != 0.5f) {
412 f0 *= 2.0f * specular_ior_level;
428 if (bsdf && fresnel) {
429 bsdf->N = valid_reflection_N;
432 bsdf->alpha_x = alpha_x;
433 bsdf->alpha_y = alpha_y;
435 fresnel->f0 = f0 * specular_tint;
437 fresnel->exponent = -eta;
441 fresnel->thin_film.ior = thinfilm_ior;
450 kg, sd, (
ccl_private ShaderClosure *)bsdf,
true,
false);
463 const float subsurface_scale =
stack_load_float(stack, subsurface_scale_offset);
498 bsdf->roughness = diffuse_roughness;
513 const float roughness = param1;
515 if (roughness < 1e-5f) {
519 bsdf->roughness = roughness;
544#ifdef __CAUSTICS_TRICKS__
552 if (bsdf !=
nullptr) {
553 uint base_ior_offset;
554 uint edge_tint_k_offset;
555 uint rotation_offset;
558 data_node.
y, &base_ior_offset, &edge_tint_k_offset, &rotation_offset, &tangent_offset);
561 const float anisotropy =
saturatef(param2);
562 const float roughness =
saturatef(param1);
563 bsdf->alpha_x =
sqr(roughness);
564 bsdf->alpha_y =
sqr(roughness);
565 if (anisotropy > 0.0f &&
stack_valid(tangent_offset)) {
567 const float aspect =
sqrtf(1.0f - anisotropy * 0.9f);
568 bsdf->alpha_x /= aspect;
569 bsdf->alpha_y *= aspect;
570 const float anisotropic_rotation =
stack_load_float(stack, rotation_offset);
571 if (anisotropic_rotation != 0.0f) {
579 bsdf->N = valid_reflection_N;
582 uint distribution_int;
583 uint thin_film_thickness_offset;
584 uint thin_film_ior_offset;
588 &thin_film_thickness_offset,
589 &thin_film_ior_offset,
592 const float thin_film_thickness =
fmaxf(
616 fresnel->thin_film.ior = thin_film_ior;
633 fresnel->thin_film.ior = thin_film_ior;
656#ifdef __CAUSTICS_TRICKS__
675 const float anisotropy =
clamp(param2, -0.99f, 0.99f);
679 bsdf->alpha_x = roughness;
680 bsdf->alpha_y = roughness;
687 if (rotation != 0.0f) {
691 if (anisotropy < 0.0f) {
692 bsdf->alpha_x = roughness / (1.0f + anisotropy);
693 bsdf->alpha_y = roughness * (1.0f + anisotropy);
696 bsdf->alpha_x = roughness * (1.0f - anisotropy);
697 bsdf->alpha_y = roughness / (1.0f - anisotropy);
722#ifdef __CAUSTICS_TRICKS__
735 float eta =
fmaxf(param2, 1e-5f);
739 const float roughness =
sqr(param1);
740 bsdf->alpha_x = roughness;
741 bsdf->alpha_y = roughness;
757#ifdef __CAUSTICS_TRICKS__
758 const bool reflective_caustics = (
kernel_data.integrator.caustics_reflective ||
760 const bool refractive_caustics = (
kernel_data.integrator.caustics_refractive ||
762 if (!(reflective_caustics || refractive_caustics)) {
766 const bool reflective_caustics =
true;
767 const bool refractive_caustics =
true;
780 if (bsdf && fresnel) {
784 const float ior =
fmaxf(param2, 1e-5f);
790 fresnel->exponent = -ior;
793 fresnel->transmission_tint = refractive_caustics ?
rgb_to_spectrum(color) :
796 fresnel->thin_film.ior = (sd->flag &
SD_BACKFACING) ? thinfilm_ior / ior : thinfilm_ior;
836#ifdef __CAUSTICS_TRICKS__
850 bsdf->smooth = param2;
862# ifdef __PRINCIPLED_HAIR__
874 uint parametrization;
881 uint melanin_redness_ofs;
882 uint absorption_coefficient_ofs;
886 &melanin_redness_ofs,
887 &absorption_coefficient_ofs);
891 uint random_color_ofs;
894 data_node3.
x, &shared_ofs1, &random_ofs, &random_color_ofs, &shared_ofs2);
906 const float random_roughness = param2;
907 const float factor_random_roughness = 1.0f + 2.0f * (
random - 0.5f) * random_roughness;
908 const float roughness = param1 * factor_random_roughness;
911 stack, shared_ofs2, data_node4.
y) *
912 factor_random_roughness :
916 switch (parametrization) {
919 absorption_coefficient_ofs);
926 stack, melanin_redness_ofs, data_node2.
w);
930 random_color =
clamp(random_color, 0.0f, 1.0f);
931 const float factor_random_color = 1.0f + 2.0f * (
random - 0.5f) * random_color;
932 melanin *= factor_random_color;
935 melanin = -
logf(
fmaxf(1.0f - melanin, 0.0001f));
938 const float eumelanin = melanin * (1.0f - melanin_redness);
939 const float pheomelanin = melanin * melanin_redness;
941 eumelanin, pheomelanin);
948 sigma = melanin_sigma + tint_sigma;
971 const float m0_roughness = 1.0f -
clamp(coat, 0.0f, 1.0f);
974 bsdf->s = radial_roughness;
975 bsdf->m0_roughness = m0_roughness;
980 sd->flag |= bsdf_hair_chiang_setup(sd, bsdf);
993 if (
R <= 0.0f && TT <= 0.0f && TRT <= 0.0f) {
1007 bsdf->extra = extra;
1008 bsdf->extra->
R =
fmaxf(0.0f,
R);
1009 bsdf->extra->TT =
fmaxf(0.0f, TT);
1010 bsdf->extra->TRT =
fmaxf(0.0f, TRT);
1012 bsdf->extra->pixel_coverage = 1.0f;
1020 const int k1 = k0 + 1;
1021 const float radius =
mix(
1024 bsdf->extra->pixel_coverage = 0.5f * sd->dP / radius;
1028 if (bsdf->aspect_ratio != 1.0f) {
1031 bsdf->N = curve_attribute<float3>(kg, sd, attr_descr_normal).val;
1034 bsdf->roughness = roughness;
1037 bsdf->sigma = sigma;
1039 sd->flag |= bsdf_hair_huang_setup(sd, bsdf, path_flag);
1054 bsdf->roughness1 = param1;
1055 bsdf->roughness2 = param2;
1063 bsdf->offset = 0.0f;
1081#ifdef __SUBSURFACE__
1091 bssrdf->albedo = closure_weight;