Blender  V3.3
closure.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #pragma once
5 
7 
8 /* Closure Nodes */
9 
12  int type,
13  float eta,
14  float roughness,
15  bool refract)
16 {
18  if (refract) {
19  bsdf->alpha_y = 0.0f;
20  bsdf->alpha_x = 0.0f;
21  bsdf->ior = eta;
22  sd->flag |= bsdf_refraction_setup(bsdf);
23  }
24  else {
25  bsdf->alpha_y = 0.0f;
26  bsdf->alpha_x = 0.0f;
27  bsdf->ior = 0.0f;
28  sd->flag |= bsdf_reflection_setup(bsdf);
29  }
30  }
32  bsdf->alpha_x = roughness;
33  bsdf->alpha_y = roughness;
34  bsdf->ior = eta;
35 
36  if (refract)
38  else
39  sd->flag |= bsdf_microfacet_beckmann_setup(bsdf);
40  }
41  else {
42  bsdf->alpha_x = roughness;
43  bsdf->alpha_y = roughness;
44  bsdf->ior = eta;
45 
46  if (refract)
47  sd->flag |= bsdf_microfacet_ggx_refraction_setup(bsdf);
48  else
49  sd->flag |= bsdf_microfacet_ggx_setup(bsdf);
50  }
51 }
52 
54 {
56  /* Read all principled BSDF extra data to get the right offset. */
57  read_node(kg, &offset);
58  read_node(kg, &offset);
59  read_node(kg, &offset);
60  read_node(kg, &offset);
61  }
62 
63  return offset;
64 }
65 
66 template<uint node_feature_mask, ShaderType shader_type>
69  ccl_private float *stack,
70  uint4 node,
71  uint32_t path_flag,
72  int offset)
73 {
74  uint type, param1_offset, param2_offset;
75 
76  uint mix_weight_offset;
77  svm_unpack_node_uchar4(node.y, &type, &param1_offset, &param2_offset, &mix_weight_offset);
78  float mix_weight = (stack_valid(mix_weight_offset) ? stack_load_float(stack, mix_weight_offset) :
79  1.0f);
80 
81  /* note we read this extra node before weight check, so offset is added */
82  uint4 data_node = read_node(kg, &offset);
83 
84  /* Only compute BSDF for surfaces, transparent variable is shared with volume extinction. */
86  {
87  if ((shader_type != SHADER_TYPE_SURFACE) || mix_weight == 0.0f) {
89  }
90  }
91  else
92  {
94  }
95 
96  float3 N = stack_valid(data_node.x) ? stack_load_float3(stack, data_node.x) : sd->N;
97  if (!(sd->type & PRIMITIVE_CURVE)) {
98  N = ensure_valid_reflection(sd->Ng, sd->I, N);
99  }
100 
101  float param1 = (stack_valid(param1_offset)) ? stack_load_float(stack, param1_offset) :
103  float param2 = (stack_valid(param2_offset)) ? stack_load_float(stack, param2_offset) :
105 
106  switch (type) {
107 #ifdef __PRINCIPLED__
109  uint specular_offset, roughness_offset, specular_tint_offset, anisotropic_offset,
110  sheen_offset, sheen_tint_offset, clearcoat_offset, clearcoat_roughness_offset,
111  eta_offset, transmission_offset, anisotropic_rotation_offset,
112  transmission_roughness_offset;
113  uint4 data_node2 = read_node(kg, &offset);
114 
115  float3 T = stack_load_float3(stack, data_node.y);
116  svm_unpack_node_uchar4(data_node.z,
117  &specular_offset,
118  &roughness_offset,
119  &specular_tint_offset,
120  &anisotropic_offset);
121  svm_unpack_node_uchar4(data_node.w,
122  &sheen_offset,
123  &sheen_tint_offset,
124  &clearcoat_offset,
125  &clearcoat_roughness_offset);
126  svm_unpack_node_uchar4(data_node2.x,
127  &eta_offset,
128  &transmission_offset,
129  &anisotropic_rotation_offset,
130  &transmission_roughness_offset);
131 
132  // get Disney principled parameters
133  float metallic = param1;
134  float subsurface = param2;
135  float specular = stack_load_float(stack, specular_offset);
136  float roughness = stack_load_float(stack, roughness_offset);
137  float specular_tint = stack_load_float(stack, specular_tint_offset);
138  float anisotropic = stack_load_float(stack, anisotropic_offset);
139  float sheen = stack_load_float(stack, sheen_offset);
140  float sheen_tint = stack_load_float(stack, sheen_tint_offset);
141  float clearcoat = stack_load_float(stack, clearcoat_offset);
142  float clearcoat_roughness = stack_load_float(stack, clearcoat_roughness_offset);
143  float transmission = stack_load_float(stack, transmission_offset);
144  float anisotropic_rotation = stack_load_float(stack, anisotropic_rotation_offset);
145  float transmission_roughness = stack_load_float(stack, transmission_roughness_offset);
146  float eta = fmaxf(stack_load_float(stack, eta_offset), 1e-5f);
147 
148  ClosureType distribution = (ClosureType)data_node2.y;
149  ClosureType subsurface_method = (ClosureType)data_node2.z;
150 
151  /* rotate tangent */
152  if (anisotropic_rotation != 0.0f)
153  T = rotate_around_axis(T, N, anisotropic_rotation * M_2PI_F);
154 
155  /* calculate ior */
156  float ior = (sd->flag & SD_BACKFACING) ? 1.0f / eta : eta;
157 
158  // calculate fresnel for refraction
159  float cosNO = dot(N, sd->I);
160  float fresnel = fresnel_dielectric_cos(cosNO, ior);
161 
162  // calculate weights of the diffuse and specular part
163  float diffuse_weight = (1.0f - saturatef(metallic)) * (1.0f - saturatef(transmission));
164 
165  float final_transmission = saturatef(transmission) * (1.0f - saturatef(metallic));
166  float specular_weight = (1.0f - final_transmission);
167 
168  // get the base color
169  uint4 data_base_color = read_node(kg, &offset);
170  float3 base_color = stack_valid(data_base_color.x) ?
171  stack_load_float3(stack, data_base_color.x) :
172  make_float3(__uint_as_float(data_base_color.y),
173  __uint_as_float(data_base_color.z),
174  __uint_as_float(data_base_color.w));
175 
176  // get the additional clearcoat normal and subsurface scattering radius
177  uint4 data_cn_ssr = read_node(kg, &offset);
178  float3 clearcoat_normal = stack_valid(data_cn_ssr.x) ?
179  stack_load_float3(stack, data_cn_ssr.x) :
180  sd->N;
181  if (!(sd->type & PRIMITIVE_CURVE)) {
182  clearcoat_normal = ensure_valid_reflection(sd->Ng, sd->I, clearcoat_normal);
183  }
184  float3 subsurface_radius = stack_valid(data_cn_ssr.y) ?
185  stack_load_float3(stack, data_cn_ssr.y) :
186  make_float3(1.0f, 1.0f, 1.0f);
187  float subsurface_ior = stack_valid(data_cn_ssr.z) ? stack_load_float(stack, data_cn_ssr.z) :
188  1.4f;
189  float subsurface_anisotropy = stack_valid(data_cn_ssr.w) ?
190  stack_load_float(stack, data_cn_ssr.w) :
191  0.0f;
192 
193  // get the subsurface color
194  uint4 data_subsurface_color = read_node(kg, &offset);
195  float3 subsurface_color = stack_valid(data_subsurface_color.x) ?
196  stack_load_float3(stack, data_subsurface_color.x) :
197  make_float3(__uint_as_float(data_subsurface_color.y),
198  __uint_as_float(data_subsurface_color.z),
199  __uint_as_float(data_subsurface_color.w));
200 
201  float3 weight = sd->svm_closure_weight * mix_weight;
202 
203 # ifdef __SUBSURFACE__
204  float3 mixed_ss_base_color = subsurface_color * subsurface +
205  base_color * (1.0f - subsurface);
206  float3 subsurf_weight = weight * mixed_ss_base_color * diffuse_weight;
207 
208  /* disable in case of diffuse ancestor, can't see it well then and
209  * adds considerably noise due to probabilities of continuing path
210  * getting lower and lower */
211  if (path_flag & PATH_RAY_DIFFUSE_ANCESTOR) {
212  subsurface = 0.0f;
213 
214  /* need to set the base color in this case such that the
215  * rays get the correctly mixed color after transmitting
216  * the object */
217  base_color = mixed_ss_base_color;
218  }
219 
220  /* diffuse */
221  if (fabsf(average(mixed_ss_base_color)) > CLOSURE_WEIGHT_CUTOFF) {
222  if (subsurface <= CLOSURE_WEIGHT_CUTOFF && diffuse_weight > CLOSURE_WEIGHT_CUTOFF) {
223  float3 diff_weight = weight * base_color * diffuse_weight;
224 
226  bsdf_alloc(sd, sizeof(PrincipledDiffuseBsdf), diff_weight);
227 
228  if (bsdf) {
229  bsdf->N = N;
230  bsdf->roughness = roughness;
231 
232  /* setup bsdf */
234  }
235  }
236  else if (subsurface > CLOSURE_WEIGHT_CUTOFF) {
237  ccl_private Bssrdf *bssrdf = bssrdf_alloc(sd, subsurf_weight);
238 
239  if (bssrdf) {
240  bssrdf->radius = subsurface_radius * subsurface;
241  bssrdf->albedo = mixed_ss_base_color;
242  bssrdf->N = N;
243  bssrdf->roughness = roughness;
244 
245  /* Clamps protecting against bad/extreme and non physical values. */
246  subsurface_ior = clamp(subsurface_ior, 1.01f, 3.8f);
247  bssrdf->anisotropy = clamp(subsurface_anisotropy, 0.0f, 0.9f);
248 
249  /* setup bsdf */
250  sd->flag |= bssrdf_setup(sd, bssrdf, subsurface_method, subsurface_ior);
251  }
252  }
253  }
254 # else
255  /* diffuse */
256  if (diffuse_weight > CLOSURE_WEIGHT_CUTOFF) {
257  float3 diff_weight = weight * base_color * diffuse_weight;
258 
260  sd, sizeof(PrincipledDiffuseBsdf), diff_weight);
261 
262  if (bsdf) {
263  bsdf->N = N;
264  bsdf->roughness = roughness;
265 
266  /* setup bsdf */
268  }
269  }
270 # endif
271 
272  /* sheen */
273  if (diffuse_weight > CLOSURE_WEIGHT_CUTOFF && sheen > CLOSURE_WEIGHT_CUTOFF) {
274  float m_cdlum = linear_rgb_to_gray(kg, base_color);
275  float3 m_ctint = m_cdlum > 0.0f ?
276  base_color / m_cdlum :
277  make_float3(1.0f, 1.0f, 1.0f); // normalize lum. to isolate hue+sat
278 
279  /* color of the sheen component */
280  float3 sheen_color = make_float3(1.0f, 1.0f, 1.0f) * (1.0f - sheen_tint) +
281  m_ctint * sheen_tint;
282 
283  float3 sheen_weight = weight * sheen * sheen_color * diffuse_weight;
284 
286  sd, sizeof(PrincipledSheenBsdf), sheen_weight);
287 
288  if (bsdf) {
289  bsdf->N = N;
290 
291  /* setup bsdf */
292  sd->flag |= bsdf_principled_sheen_setup(sd, bsdf);
293  }
294  }
295 
296  /* specular reflection */
297 # ifdef __CAUSTICS_TRICKS__
298  if (kernel_data.integrator.caustics_reflective || (path_flag & PATH_RAY_DIFFUSE) == 0) {
299 # endif
300  if (specular_weight > CLOSURE_WEIGHT_CUTOFF &&
302  float3 spec_weight = weight * specular_weight;
303 
305  sd, sizeof(MicrofacetBsdf), spec_weight);
307  (bsdf != NULL) ?
309  NULL;
310 
311  if (bsdf && extra) {
312  bsdf->N = N;
313  bsdf->ior = (2.0f / (1.0f - safe_sqrtf(0.08f * specular))) - 1.0f;
314  bsdf->T = T;
315  bsdf->extra = extra;
316 
317  float aspect = safe_sqrtf(1.0f - anisotropic * 0.9f);
318  float r2 = roughness * roughness;
319 
320  bsdf->alpha_x = r2 / aspect;
321  bsdf->alpha_y = r2 * aspect;
322 
323  float m_cdlum = 0.3f * base_color.x + 0.6f * base_color.y +
324  0.1f * base_color.z; // luminance approx.
325  float3 m_ctint = m_cdlum > 0.0f ?
326  base_color / m_cdlum :
327  make_float3(
328  1.0f, 1.0f, 1.0f); // normalize lum. to isolate hue+sat
329  float3 tmp_col = make_float3(1.0f, 1.0f, 1.0f) * (1.0f - specular_tint) +
330  m_ctint * specular_tint;
331 
332  bsdf->extra->cspec0 = (specular * 0.08f * tmp_col) * (1.0f - metallic) +
333  base_color * metallic;
334  bsdf->extra->color = base_color;
335  bsdf->extra->clearcoat = 0.0f;
336 
337  /* setup bsdf */
338  if (distribution == CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID ||
339  roughness <= 0.075f) /* use single-scatter GGX */
340  sd->flag |= bsdf_microfacet_ggx_fresnel_setup(bsdf, sd);
341  else /* use multi-scatter GGX */
342  sd->flag |= bsdf_microfacet_multi_ggx_fresnel_setup(bsdf, sd);
343  }
344  }
345 # ifdef __CAUSTICS_TRICKS__
346  }
347 # endif
348 
349  /* BSDF */
350 # ifdef __CAUSTICS_TRICKS__
351  if (kernel_data.integrator.caustics_reflective ||
352  kernel_data.integrator.caustics_refractive || (path_flag & PATH_RAY_DIFFUSE) == 0) {
353 # endif
354  if (final_transmission > CLOSURE_WEIGHT_CUTOFF) {
355  float3 glass_weight = weight * final_transmission;
356  float3 cspec0 = base_color * specular_tint +
357  make_float3(1.0f, 1.0f, 1.0f) * (1.0f - specular_tint);
358 
359  if (roughness <= 5e-2f ||
360  distribution == CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID) { /* use single-scatter GGX */
361  float refl_roughness = roughness;
362 
363  /* reflection */
364 # ifdef __CAUSTICS_TRICKS__
365  if (kernel_data.integrator.caustics_reflective || (path_flag & PATH_RAY_DIFFUSE) == 0)
366 # endif
367  {
369  sd, sizeof(MicrofacetBsdf), glass_weight * fresnel);
372  sd, sizeof(MicrofacetExtra)) :
373  NULL;
374 
375  if (bsdf && extra) {
376  bsdf->N = N;
377  bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
378  bsdf->extra = extra;
379 
380  bsdf->alpha_x = refl_roughness * refl_roughness;
381  bsdf->alpha_y = refl_roughness * refl_roughness;
382  bsdf->ior = ior;
383 
384  bsdf->extra->color = base_color;
385  bsdf->extra->cspec0 = cspec0;
386  bsdf->extra->clearcoat = 0.0f;
387 
388  /* setup bsdf */
389  sd->flag |= bsdf_microfacet_ggx_fresnel_setup(bsdf, sd);
390  }
391  }
392 
393  /* refraction */
394 # ifdef __CAUSTICS_TRICKS__
395  if (kernel_data.integrator.caustics_refractive || (path_flag & PATH_RAY_DIFFUSE) == 0)
396 # endif
397  {
398  /* This is to prevent MNEE from receiving a null BSDF. */
399  float refraction_fresnel = fmaxf(0.0001f, 1.0f - fresnel);
401  sd, sizeof(MicrofacetBsdf), base_color * glass_weight * refraction_fresnel);
402  if (bsdf) {
403  bsdf->N = N;
404  bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
405  bsdf->extra = NULL;
406 
407  if (distribution == CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID)
408  transmission_roughness = 1.0f - (1.0f - refl_roughness) *
409  (1.0f - transmission_roughness);
410  else
411  transmission_roughness = refl_roughness;
412 
413  bsdf->alpha_x = transmission_roughness * transmission_roughness;
414  bsdf->alpha_y = transmission_roughness * transmission_roughness;
415  bsdf->ior = ior;
416 
417  /* setup bsdf */
418  sd->flag |= bsdf_microfacet_ggx_refraction_setup(bsdf);
419  }
420  }
421  }
422  else { /* use multi-scatter GGX */
424  sd, sizeof(MicrofacetBsdf), glass_weight);
427  sd, sizeof(MicrofacetExtra)) :
428  NULL;
429 
430  if (bsdf && extra) {
431  bsdf->N = N;
432  bsdf->extra = extra;
433  bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
434 
435  bsdf->alpha_x = roughness * roughness;
436  bsdf->alpha_y = roughness * roughness;
437  bsdf->ior = ior;
438 
439  bsdf->extra->color = base_color;
440  bsdf->extra->cspec0 = cspec0;
441  bsdf->extra->clearcoat = 0.0f;
442 
443  /* setup bsdf */
444  sd->flag |= bsdf_microfacet_multi_ggx_glass_fresnel_setup(bsdf, sd);
445  }
446  }
447  }
448 # ifdef __CAUSTICS_TRICKS__
449  }
450 # endif
451 
452  /* clearcoat */
453 # ifdef __CAUSTICS_TRICKS__
454  if (kernel_data.integrator.caustics_reflective || (path_flag & PATH_RAY_DIFFUSE) == 0) {
455 # endif
458  sd, sizeof(MicrofacetBsdf), weight);
460  (bsdf != NULL) ?
462  NULL;
463 
464  if (bsdf && extra) {
465  bsdf->N = clearcoat_normal;
466  bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
467  bsdf->ior = 1.5f;
468  bsdf->extra = extra;
469 
470  bsdf->alpha_x = clearcoat_roughness * clearcoat_roughness;
471  bsdf->alpha_y = clearcoat_roughness * clearcoat_roughness;
472 
473  bsdf->extra->color = make_float3(0.0f, 0.0f, 0.0f);
474  bsdf->extra->cspec0 = make_float3(0.04f, 0.04f, 0.04f);
475  bsdf->extra->clearcoat = clearcoat;
476 
477  /* setup bsdf */
478  sd->flag |= bsdf_microfacet_ggx_clearcoat_setup(bsdf, sd);
479  }
480  }
481 # ifdef __CAUSTICS_TRICKS__
482  }
483 # endif
484 
485  break;
486  }
487 #endif /* __PRINCIPLED__ */
489  float3 weight = sd->svm_closure_weight * mix_weight;
491  sd, sizeof(OrenNayarBsdf), weight);
492 
493  if (bsdf) {
494  bsdf->N = N;
495 
496  float roughness = param1;
497 
498  if (roughness == 0.0f) {
499  sd->flag |= bsdf_diffuse_setup((ccl_private DiffuseBsdf *)bsdf);
500  }
501  else {
502  bsdf->roughness = roughness;
503  sd->flag |= bsdf_oren_nayar_setup(bsdf);
504  }
505  }
506  break;
507  }
509  float3 weight = sd->svm_closure_weight * mix_weight;
511  sd, sizeof(DiffuseBsdf), weight);
512 
513  if (bsdf) {
514  bsdf->N = N;
515  sd->flag |= bsdf_translucent_setup(bsdf);
516  }
517  break;
518  }
520  float3 weight = sd->svm_closure_weight * mix_weight;
521  bsdf_transparent_setup(sd, weight, path_flag);
522  break;
523  }
529 #ifdef __CAUSTICS_TRICKS__
530  if (!kernel_data.integrator.caustics_reflective && (path_flag & PATH_RAY_DIFFUSE))
531  break;
532 #endif
533  float3 weight = sd->svm_closure_weight * mix_weight;
535  sd, sizeof(MicrofacetBsdf), weight);
536 
537  if (!bsdf) {
538  break;
539  }
540 
541  float roughness = sqr(param1);
542 
543  bsdf->N = N;
544  bsdf->ior = 0.0f;
545  bsdf->extra = NULL;
546 
547  if (data_node.y == SVM_STACK_INVALID) {
548  bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
549  bsdf->alpha_x = roughness;
550  bsdf->alpha_y = roughness;
551  }
552  else {
553  bsdf->T = stack_load_float3(stack, data_node.y);
554 
555  /* rotate tangent */
556  float rotation = stack_load_float(stack, data_node.z);
557  if (rotation != 0.0f)
558  bsdf->T = rotate_around_axis(bsdf->T, bsdf->N, rotation * M_2PI_F);
559 
560  /* compute roughness */
561  float anisotropy = clamp(param2, -0.99f, 0.99f);
562  if (anisotropy < 0.0f) {
563  bsdf->alpha_x = roughness / (1.0f + anisotropy);
564  bsdf->alpha_y = roughness * (1.0f + anisotropy);
565  }
566  else {
567  bsdf->alpha_x = roughness * (1.0f - anisotropy);
568  bsdf->alpha_y = roughness / (1.0f - anisotropy);
569  }
570  }
571 
572  /* setup bsdf */
574  sd->flag |= bsdf_reflection_setup(bsdf);
576  sd->flag |= bsdf_microfacet_beckmann_setup(bsdf);
578  sd->flag |= bsdf_microfacet_ggx_setup(bsdf);
580  kernel_assert(stack_valid(data_node.w));
581  bsdf->extra = (ccl_private MicrofacetExtra *)closure_alloc_extra(sd,
582  sizeof(MicrofacetExtra));
583  if (bsdf->extra) {
584  bsdf->extra->color = stack_load_float3(stack, data_node.w);
585  bsdf->extra->cspec0 = make_float3(0.0f, 0.0f, 0.0f);
586  bsdf->extra->clearcoat = 0.0f;
587  sd->flag |= bsdf_microfacet_multi_ggx_setup(bsdf);
588  }
589  }
590  else {
591  sd->flag |= bsdf_ashikhmin_shirley_setup(bsdf);
592  }
593 
594  break;
595  }
599 #ifdef __CAUSTICS_TRICKS__
600  if (!kernel_data.integrator.caustics_refractive && (path_flag & PATH_RAY_DIFFUSE))
601  break;
602 #endif
603  float3 weight = sd->svm_closure_weight * mix_weight;
605  sd, sizeof(MicrofacetBsdf), weight);
606 
607  if (bsdf) {
608  bsdf->N = N;
609  bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
610  bsdf->extra = NULL;
611 
612  float eta = fmaxf(param2, 1e-5f);
613  eta = (sd->flag & SD_BACKFACING) ? 1.0f / eta : eta;
614 
615  /* setup bsdf */
617  bsdf->alpha_x = 0.0f;
618  bsdf->alpha_y = 0.0f;
619  bsdf->ior = eta;
620 
621  sd->flag |= bsdf_refraction_setup(bsdf);
622  }
623  else {
624  float roughness = sqr(param1);
625  bsdf->alpha_x = roughness;
626  bsdf->alpha_y = roughness;
627  bsdf->ior = eta;
628 
631  else
632  sd->flag |= bsdf_microfacet_ggx_refraction_setup(bsdf);
633  }
634  }
635 
636  break;
637  }
641 #ifdef __CAUSTICS_TRICKS__
642  if (!kernel_data.integrator.caustics_reflective &&
643  !kernel_data.integrator.caustics_refractive && (path_flag & PATH_RAY_DIFFUSE)) {
644  break;
645  }
646 #endif
647  float3 weight = sd->svm_closure_weight * mix_weight;
648 
649  /* index of refraction */
650  float eta = fmaxf(param2, 1e-5f);
651  eta = (sd->flag & SD_BACKFACING) ? 1.0f / eta : eta;
652 
653  /* fresnel */
654  float cosNO = dot(N, sd->I);
655  float fresnel = fresnel_dielectric_cos(cosNO, eta);
656  float roughness = sqr(param1);
657 
658  /* reflection */
659 #ifdef __CAUSTICS_TRICKS__
660  if (kernel_data.integrator.caustics_reflective || (path_flag & PATH_RAY_DIFFUSE) == 0)
661 #endif
662  {
664  sd, sizeof(MicrofacetBsdf), weight * fresnel);
665 
666  if (bsdf) {
667  bsdf->N = N;
668  bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
669  bsdf->extra = NULL;
670  svm_node_glass_setup(sd, bsdf, type, eta, roughness, false);
671  }
672  }
673 
674  /* refraction */
675 #ifdef __CAUSTICS_TRICKS__
676  if (kernel_data.integrator.caustics_refractive || (path_flag & PATH_RAY_DIFFUSE) == 0)
677 #endif
678  {
679  /* This is to prevent MNEE from receiving a null BSDF. */
680  float refraction_fresnel = fmaxf(0.0001f, 1.0f - fresnel);
682  sd, sizeof(MicrofacetBsdf), weight * refraction_fresnel);
683 
684  if (bsdf) {
685  bsdf->N = N;
686  bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
687  bsdf->extra = NULL;
688  svm_node_glass_setup(sd, bsdf, type, eta, roughness, true);
689  }
690  }
691 
692  break;
693  }
695 #ifdef __CAUSTICS_TRICKS__
696  if (!kernel_data.integrator.caustics_reflective &&
697  !kernel_data.integrator.caustics_refractive && (path_flag & PATH_RAY_DIFFUSE))
698  break;
699 #endif
700  float3 weight = sd->svm_closure_weight * mix_weight;
702  sd, sizeof(MicrofacetBsdf), weight);
703  if (!bsdf) {
704  break;
705  }
706 
708  sd, sizeof(MicrofacetExtra));
709  if (!extra) {
710  break;
711  }
712 
713  bsdf->N = N;
714  bsdf->extra = extra;
715  bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
716 
717  float roughness = sqr(param1);
718  bsdf->alpha_x = roughness;
719  bsdf->alpha_y = roughness;
720  float eta = fmaxf(param2, 1e-5f);
721  bsdf->ior = (sd->flag & SD_BACKFACING) ? 1.0f / eta : eta;
722 
723  kernel_assert(stack_valid(data_node.z));
724  bsdf->extra->color = stack_load_float3(stack, data_node.z);
725  bsdf->extra->cspec0 = make_float3(0.0f, 0.0f, 0.0f);
726  bsdf->extra->clearcoat = 0.0f;
727 
728  /* setup bsdf */
729  sd->flag |= bsdf_microfacet_multi_ggx_glass_setup(bsdf);
730  break;
731  }
733  float3 weight = sd->svm_closure_weight * mix_weight;
735  sd, sizeof(VelvetBsdf), weight);
736 
737  if (bsdf) {
738  bsdf->N = N;
739 
740  bsdf->sigma = saturatef(param1);
741  sd->flag |= bsdf_ashikhmin_velvet_setup(bsdf);
742  }
743  break;
744  }
746 #ifdef __CAUSTICS_TRICKS__
747  if (!kernel_data.integrator.caustics_reflective && (path_flag & PATH_RAY_DIFFUSE))
748  break;
750 #endif
752  float3 weight = sd->svm_closure_weight * mix_weight;
754  sd, sizeof(ToonBsdf), weight);
755 
756  if (bsdf) {
757  bsdf->N = N;
758  bsdf->size = param1;
759  bsdf->smooth = param2;
760 
762  sd->flag |= bsdf_diffuse_toon_setup(bsdf);
763  else
764  sd->flag |= bsdf_glossy_toon_setup(bsdf);
765  }
766  break;
767  }
768 #ifdef __HAIR__
770  uint4 data_node2 = read_node(kg, &offset);
771  uint4 data_node3 = read_node(kg, &offset);
772  uint4 data_node4 = read_node(kg, &offset);
773 
774  float3 weight = sd->svm_closure_weight * mix_weight;
775 
776  uint offset_ofs, ior_ofs, color_ofs, parametrization;
777  svm_unpack_node_uchar4(data_node.y, &offset_ofs, &ior_ofs, &color_ofs, &parametrization);
778  float alpha = stack_load_float_default(stack, offset_ofs, data_node.z);
779  float ior = stack_load_float_default(stack, ior_ofs, data_node.w);
780 
781  uint coat_ofs, melanin_ofs, melanin_redness_ofs, absorption_coefficient_ofs;
782  svm_unpack_node_uchar4(data_node2.x,
783  &coat_ofs,
784  &melanin_ofs,
785  &melanin_redness_ofs,
786  &absorption_coefficient_ofs);
787 
788  uint tint_ofs, random_ofs, random_color_ofs, random_roughness_ofs;
790  data_node3.x, &tint_ofs, &random_ofs, &random_color_ofs, &random_roughness_ofs);
791 
792  const AttributeDescriptor attr_descr_random = find_attribute(kg, sd, data_node4.y);
793  float random = 0.0f;
794  if (attr_descr_random.offset != ATTR_STD_NOT_FOUND) {
795  random = primitive_surface_attribute_float(kg, sd, attr_descr_random, NULL, NULL);
796  }
797  else {
798  random = stack_load_float_default(stack, random_ofs, data_node3.y);
799  }
800 
802  sd, sizeof(PrincipledHairBSDF), weight);
803  if (bsdf) {
806 
807  if (!extra)
808  break;
809 
810  /* Random factors range: [-randomization/2, +randomization/2]. */
811  float random_roughness = stack_load_float_default(
812  stack, random_roughness_ofs, data_node3.w);
813  float factor_random_roughness = 1.0f + 2.0f * (random - 0.5f) * random_roughness;
814  float roughness = param1 * factor_random_roughness;
815  float radial_roughness = param2 * factor_random_roughness;
816 
817  /* Remap Coat value to [0, 100]% of Roughness. */
818  float coat = stack_load_float_default(stack, coat_ofs, data_node2.y);
819  float m0_roughness = 1.0f - clamp(coat, 0.0f, 1.0f);
820 
821  bsdf->N = N;
822  bsdf->v = roughness;
823  bsdf->s = radial_roughness;
824  bsdf->m0_roughness = m0_roughness;
825  bsdf->alpha = alpha;
826  bsdf->eta = ior;
827  bsdf->extra = extra;
828 
829  switch (parametrization) {
831  float3 absorption_coefficient = stack_load_float3(stack, absorption_coefficient_ofs);
832  bsdf->sigma = absorption_coefficient;
833  break;
834  }
836  float melanin = stack_load_float_default(stack, melanin_ofs, data_node2.z);
837  float melanin_redness = stack_load_float_default(
838  stack, melanin_redness_ofs, data_node2.w);
839 
840  /* Randomize melanin. */
841  float random_color = stack_load_float_default(stack, random_color_ofs, data_node3.z);
842  random_color = clamp(random_color, 0.0f, 1.0f);
843  float factor_random_color = 1.0f + 2.0f * (random - 0.5f) * random_color;
844  melanin *= factor_random_color;
845 
846  /* Map melanin 0..inf from more perceptually linear 0..1. */
847  melanin = -logf(fmaxf(1.0f - melanin, 0.0001f));
848 
849  /* Benedikt Bitterli's melanin ratio remapping. */
850  float eumelanin = melanin * (1.0f - melanin_redness);
851  float pheomelanin = melanin * melanin_redness;
852  float3 melanin_sigma = bsdf_principled_hair_sigma_from_concentration(eumelanin,
853  pheomelanin);
854 
855  /* Optional tint. */
856  float3 tint = stack_load_float3(stack, tint_ofs);
858  radial_roughness);
859 
860  bsdf->sigma = melanin_sigma + tint_sigma;
861  break;
862  }
864  float3 color = stack_load_float3(stack, color_ofs);
865  bsdf->sigma = bsdf_principled_hair_sigma_from_reflectance(color, radial_roughness);
866  break;
867  }
868  default: {
869  /* Fallback to brownish hair, same as defaults for melanin. */
870  kernel_assert(!"Invalid Principled Hair parametrization!");
871  bsdf->sigma = bsdf_principled_hair_sigma_from_concentration(0.0f, 0.8054375f);
872  break;
873  }
874  }
875 
876  sd->flag |= bsdf_principled_hair_setup(sd, bsdf);
877  }
878  break;
879  }
882  float3 weight = sd->svm_closure_weight * mix_weight;
883 
885  sd, sizeof(HairBsdf), weight);
886 
887  if (bsdf) {
888  bsdf->N = N;
889  bsdf->roughness1 = param1;
890  bsdf->roughness2 = param2;
891  bsdf->offset = -stack_load_float(stack, data_node.z);
892 
893  if (stack_valid(data_node.y)) {
894  bsdf->T = normalize(stack_load_float3(stack, data_node.y));
895  }
896  else if (!(sd->type & PRIMITIVE_CURVE)) {
897  bsdf->T = normalize(sd->dPdv);
898  bsdf->offset = 0.0f;
899  }
900  else
901  bsdf->T = normalize(sd->dPdu);
902 
904  sd->flag |= bsdf_hair_reflection_setup(bsdf);
905  }
906  else {
907  sd->flag |= bsdf_hair_transmission_setup(bsdf);
908  }
909  }
910 
911  break;
912  }
913 #endif /* __HAIR__ */
914 
915 #ifdef __SUBSURFACE__
919  float3 weight = sd->svm_closure_weight * mix_weight;
920  ccl_private Bssrdf *bssrdf = bssrdf_alloc(sd, weight);
921 
922  if (bssrdf) {
923  /* disable in case of diffuse ancestor, can't see it well then and
924  * adds considerably noise due to probabilities of continuing path
925  * getting lower and lower */
926  if (path_flag & PATH_RAY_DIFFUSE_ANCESTOR)
927  param1 = 0.0f;
928 
929  bssrdf->radius = stack_load_float3(stack, data_node.z) * param1;
930  bssrdf->albedo = sd->svm_closure_weight;
931  bssrdf->N = N;
932  bssrdf->roughness = FLT_MAX;
933 
934  const float subsurface_ior = clamp(param2, 1.01f, 3.8f);
935  const float subsurface_anisotropy = stack_load_float(stack, data_node.w);
936  bssrdf->anisotropy = clamp(subsurface_anisotropy, 0.0f, 0.9f);
937 
938  sd->flag |= bssrdf_setup(sd, bssrdf, (ClosureType)type, subsurface_ior);
939  }
940 
941  break;
942  }
943 #endif
944  default:
945  break;
946  }
947 
948  return offset;
949 }
950 
951 template<ShaderType shader_type>
954  ccl_private float *stack,
955  uint4 node)
956 {
957 #ifdef __VOLUME__
958  /* Only sum extinction for volumes, variable is shared with surface transparency. */
959  if (shader_type != SHADER_TYPE_VOLUME) {
960  return;
961  }
962 
963  uint type, density_offset, anisotropy_offset;
964 
965  uint mix_weight_offset;
966  svm_unpack_node_uchar4(node.y, &type, &density_offset, &anisotropy_offset, &mix_weight_offset);
967  float mix_weight = (stack_valid(mix_weight_offset) ? stack_load_float(stack, mix_weight_offset) :
968  1.0f);
969 
970  if (mix_weight == 0.0f) {
971  return;
972  }
973 
974  float density = (stack_valid(density_offset)) ? stack_load_float(stack, density_offset) :
976  density = mix_weight * fmaxf(density, 0.0f);
977 
978  /* Compute scattering coefficient. */
979  float3 weight = sd->svm_closure_weight;
980 
982  weight = make_float3(1.0f, 1.0f, 1.0f) - weight;
983  }
984 
985  weight *= density;
986 
987  /* Add closure for volume scattering. */
990  sd, sizeof(HenyeyGreensteinVolume), weight);
991 
992  if (volume) {
993  float anisotropy = (stack_valid(anisotropy_offset)) ?
994  stack_load_float(stack, anisotropy_offset) :
996  volume->g = anisotropy; /* g */
997  sd->flag |= volume_henyey_greenstein_setup(volume);
998  }
999  }
1000 
1001  /* Sum total extinction weight. */
1002  volume_extinction_setup(sd, weight);
1003 #endif
1004 }
1005 
1006 template<ShaderType shader_type>
1008  ccl_private ShaderData *sd,
1009  ccl_private float *stack,
1010  uint4 node,
1011  uint32_t path_flag,
1012  int offset)
1013 {
1014 #ifdef __VOLUME__
1015  uint4 value_node = read_node(kg, &offset);
1016  uint4 attr_node = read_node(kg, &offset);
1017 
1018  /* Only sum extinction for volumes, variable is shared with surface transparency. */
1019  if (shader_type != SHADER_TYPE_VOLUME) {
1020  return offset;
1021  }
1022 
1023  uint density_offset, anisotropy_offset, absorption_color_offset, mix_weight_offset;
1025  node.y, &density_offset, &anisotropy_offset, &absorption_color_offset, &mix_weight_offset);
1026  float mix_weight = (stack_valid(mix_weight_offset) ? stack_load_float(stack, mix_weight_offset) :
1027  1.0f);
1028 
1029  if (mix_weight == 0.0f) {
1030  return offset;
1031  }
1032 
1033  /* Compute density. */
1034  float primitive_density = 1.0f;
1035  float density = (stack_valid(density_offset)) ? stack_load_float(stack, density_offset) :
1036  __uint_as_float(value_node.x);
1037  density = mix_weight * fmaxf(density, 0.0f);
1038 
1040  /* Density and color attribute lookup if available. */
1041  const AttributeDescriptor attr_density = find_attribute(kg, sd, attr_node.x);
1042  if (attr_density.offset != ATTR_STD_NOT_FOUND) {
1043  primitive_density = primitive_volume_attribute_float(kg, sd, attr_density);
1044  density = fmaxf(density * primitive_density, 0.0f);
1045  }
1046  }
1047 
1049  /* Compute scattering color. */
1050  float3 color = sd->svm_closure_weight;
1051 
1052  const AttributeDescriptor attr_color = find_attribute(kg, sd, attr_node.y);
1053  if (attr_color.offset != ATTR_STD_NOT_FOUND) {
1054  color *= primitive_volume_attribute_float3(kg, sd, attr_color);
1055  }
1056 
1057  /* Add closure for volume scattering. */
1059  sd, sizeof(HenyeyGreensteinVolume), color * density);
1060  if (volume) {
1061  float anisotropy = (stack_valid(anisotropy_offset)) ?
1062  stack_load_float(stack, anisotropy_offset) :
1063  __uint_as_float(value_node.y);
1064  volume->g = anisotropy;
1065  sd->flag |= volume_henyey_greenstein_setup(volume);
1066  }
1067 
1068  /* Add extinction weight. */
1069  float3 zero = make_float3(0.0f, 0.0f, 0.0f);
1070  float3 one = make_float3(1.0f, 1.0f, 1.0f);
1071  float3 absorption_color = max(sqrt(stack_load_float3(stack, absorption_color_offset)), zero);
1072  float3 absorption = max(one - color, zero) * max(one - absorption_color, zero);
1074  }
1075 
1076  /* Compute emission. */
1077  if (path_flag & PATH_RAY_SHADOW) {
1078  /* Don't need emission for shadows. */
1079  return offset;
1080  }
1081 
1082  uint emission_offset, emission_color_offset, blackbody_offset, temperature_offset;
1084  node.z, &emission_offset, &emission_color_offset, &blackbody_offset, &temperature_offset);
1085  float emission = (stack_valid(emission_offset)) ? stack_load_float(stack, emission_offset) :
1086  __uint_as_float(value_node.z);
1087  float blackbody = (stack_valid(blackbody_offset)) ? stack_load_float(stack, blackbody_offset) :
1088  __uint_as_float(value_node.w);
1089 
1090  if (emission > CLOSURE_WEIGHT_CUTOFF) {
1091  float3 emission_color = stack_load_float3(stack, emission_color_offset);
1092  emission_setup(sd, emission * emission_color);
1093  }
1094 
1095  if (blackbody > CLOSURE_WEIGHT_CUTOFF) {
1096  float T = stack_load_float(stack, temperature_offset);
1097 
1098  /* Add flame temperature from attribute if available. */
1099  const AttributeDescriptor attr_temperature = find_attribute(kg, sd, attr_node.z);
1100  if (attr_temperature.offset != ATTR_STD_NOT_FOUND) {
1101  float temperature = primitive_volume_attribute_float(kg, sd, attr_temperature);
1102  T *= fmaxf(temperature, 0.0f);
1103  }
1104 
1105  T = fmaxf(T, 0.0f);
1106 
1107  /* Stefan-Boltzmann law. */
1108  float T4 = sqr(sqr(T));
1109  float sigma = 5.670373e-8f * 1e-6f / M_PI_F;
1110  float intensity = sigma * mix(1.0f, T4, blackbody);
1111 
1112  if (intensity > CLOSURE_WEIGHT_CUTOFF) {
1113  float3 blackbody_tint = stack_load_float3(stack, node.w);
1114  float3 bb = blackbody_tint * intensity *
1116  emission_setup(sd, bb);
1117  }
1118  }
1119 #endif
1120  return offset;
1121 }
1122 
1124  ccl_private float *stack,
1125  uint4 node)
1126 {
1127  uint mix_weight_offset = node.y;
1128  float3 weight = sd->svm_closure_weight;
1129 
1130  if (stack_valid(mix_weight_offset)) {
1131  float mix_weight = stack_load_float(stack, mix_weight_offset);
1132 
1133  if (mix_weight == 0.0f)
1134  return;
1135 
1136  weight *= mix_weight;
1137  }
1138 
1139  emission_setup(sd, weight);
1140 }
1141 
1143  ccl_private float *stack,
1144  uint4 node)
1145 {
1146  uint mix_weight_offset = node.y;
1147  float3 weight = sd->svm_closure_weight;
1148 
1149  if (stack_valid(mix_weight_offset)) {
1150  float mix_weight = stack_load_float(stack, mix_weight_offset);
1151 
1152  if (mix_weight == 0.0f)
1153  return;
1154 
1155  weight *= mix_weight;
1156  }
1157 
1158  background_setup(sd, weight);
1159 }
1160 
1162  ccl_private float *stack,
1163  uint4 node)
1164 {
1165  uint mix_weight_offset = node.y;
1166 
1167  if (stack_valid(mix_weight_offset)) {
1168  float mix_weight = stack_load_float(stack, mix_weight_offset);
1169 
1170  if (mix_weight == 0.0f)
1171  return;
1172 
1173  closure_alloc(
1174  sd, sizeof(ShaderClosure), CLOSURE_HOLDOUT_ID, sd->svm_closure_weight * mix_weight);
1175  }
1176  else
1177  closure_alloc(sd, sizeof(ShaderClosure), CLOSURE_HOLDOUT_ID, sd->svm_closure_weight);
1178 
1179  sd->flag |= SD_HOLDOUT;
1180 }
1181 
1182 /* Closure Nodes */
1183 
1185 {
1186  sd->svm_closure_weight = weight;
1187 }
1188 
1190 {
1192  svm_node_closure_store_weight(sd, weight);
1193 }
1194 
1196  ccl_private float *stack,
1197  uint weight_offset)
1198 {
1199  float3 weight = stack_load_float3(stack, weight_offset);
1200  svm_node_closure_store_weight(sd, weight);
1201 }
1202 
1204  ccl_private ShaderData *sd,
1205  ccl_private float *stack,
1206  uint4 node)
1207 {
1208  uint color_offset = node.y;
1209  uint strength_offset = node.z;
1210 
1211  float strength = stack_load_float(stack, strength_offset);
1212  float3 weight = stack_load_float3(stack, color_offset) * strength;
1213 
1214  svm_node_closure_store_weight(sd, weight);
1215 }
1216 
1218  ccl_private float *stack,
1219  uint4 node)
1220 {
1221  /* fetch weight from blend input, previous mix closures,
1222  * and write to stack to be used by closure nodes later */
1223  uint weight_offset, in_weight_offset, weight1_offset, weight2_offset;
1225  node.y, &weight_offset, &in_weight_offset, &weight1_offset, &weight2_offset);
1226 
1227  float weight = stack_load_float(stack, weight_offset);
1228  weight = saturatef(weight);
1229 
1230  float in_weight = (stack_valid(in_weight_offset)) ? stack_load_float(stack, in_weight_offset) :
1231  1.0f;
1232 
1233  if (stack_valid(weight1_offset))
1234  stack_store_float(stack, weight1_offset, in_weight * (1.0f - weight));
1235  if (stack_valid(weight2_offset))
1236  stack_store_float(stack, weight2_offset, in_weight * weight);
1237 }
1238 
1239 /* (Bump) normal */
1240 
1242  ccl_private ShaderData *sd,
1243  ccl_private float *stack,
1244  uint in_direction,
1245  uint out_normal)
1246 {
1247  float3 normal = stack_load_float3(stack, in_direction);
1248  sd->N = normal;
1249  stack_store_float3(stack, out_normal, normal);
1250 }
1251 
#define ATTR_FALLTHROUGH
sqrt(x)+1/max(0
MINLINE float safe_sqrtf(float a)
unsigned int uint
Definition: BLI_sys_types.h:67
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
static float mix_weight(float weight, float weight2, char mix_mode)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a producing a negative Combine Generate a color from its and blue Hue Saturation Apply a color transformation in the HSV color model Specular Similar to the Principled BSDF node but uses the specular workflow instead of metallic
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a producing a negative Combine Generate a color from its and blue Hue Saturation Apply a color transformation in the HSV color model Specular BSDF
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a color
CCL_NAMESPACE_BEGIN ccl_device ccl_private ShaderClosure * closure_alloc(ccl_private ShaderData *sd, int size, ClosureType type, float3 weight)
Definition: alloc.h:8
ccl_device ccl_private void * closure_alloc_extra(ccl_private ShaderData *sd, int size)
Definition: alloc.h:29
ccl_device_inline ccl_private ShaderClosure * bsdf_alloc(ccl_private ShaderData *sd, int size, float3 weight)
Definition: alloc.h:50
CCL_NAMESPACE_BEGIN ccl_device int bsdf_ashikhmin_shirley_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device int bsdf_ashikhmin_velvet_setup(ccl_private VelvetBsdf *bsdf)
ccl_device int bsdf_translucent_setup(ccl_private DiffuseBsdf *bsdf)
Definition: bsdf_diffuse.h:87
ccl_device int bsdf_diffuse_setup(ccl_private DiffuseBsdf *bsdf)
Definition: bsdf_diffuse.h:23
ccl_device int bsdf_hair_reflection_setup(ccl_private HairBsdf *bsdf)
Definition: bsdf_hair.h:24
ccl_device int bsdf_hair_transmission_setup(ccl_private HairBsdf *bsdf)
Definition: bsdf_hair.h:32
ccl_device_inline float3 bsdf_principled_hair_sigma_from_concentration(const float eumelanin, const float pheomelanin)
ccl_device_inline float3 bsdf_principled_hair_sigma_from_reflectance(const float3 color, const float azimuthal_roughness)
ccl_device int bsdf_microfacet_beckmann_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device int bsdf_microfacet_ggx_fresnel_setup(ccl_private MicrofacetBsdf *bsdf, ccl_private const ShaderData *sd)
ccl_device int bsdf_microfacet_ggx_clearcoat_setup(ccl_private MicrofacetBsdf *bsdf, ccl_private const ShaderData *sd)
ccl_device int bsdf_microfacet_beckmann_refraction_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device int bsdf_microfacet_ggx_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device int bsdf_microfacet_ggx_refraction_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device int bsdf_microfacet_multi_ggx_glass_fresnel_setup(ccl_private MicrofacetBsdf *bsdf, ccl_private const ShaderData *sd)
ccl_device int bsdf_microfacet_multi_ggx_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device int bsdf_microfacet_multi_ggx_glass_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device int bsdf_microfacet_multi_ggx_fresnel_setup(ccl_private MicrofacetBsdf *bsdf, ccl_private const ShaderData *sd)
ccl_device int bsdf_oren_nayar_setup(ccl_private OrenNayarBsdf *bsdf)
ccl_device int bsdf_principled_diffuse_setup(ccl_private PrincipledDiffuseBsdf *bsdf)
@ PRINCIPLED_DIFFUSE_FULL
ccl_device int bsdf_principled_sheen_setup(ccl_private const ShaderData *sd, ccl_private PrincipledSheenBsdf *bsdf)
CCL_NAMESPACE_BEGIN ccl_device int bsdf_reflection_setup(ccl_private MicrofacetBsdf *bsdf)
CCL_NAMESPACE_BEGIN ccl_device int bsdf_refraction_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device int bsdf_diffuse_toon_setup(ccl_private ToonBsdf *bsdf)
Definition: bsdf_toon.h:24
ccl_device int bsdf_glossy_toon_setup(ccl_private ToonBsdf *bsdf)
Definition: bsdf_toon.h:129
CCL_NAMESPACE_BEGIN ccl_device void bsdf_transparent_setup(ccl_private ShaderData *sd, const float3 weight, uint32_t path_flag)
ccl_device float3 ensure_valid_reflection(float3 Ng, float3 I, float3 N)
Definition: bsdf_util.h:127
ccl_device float fresnel_dielectric_cos(float cosi, float eta)
Definition: bsdf_util.h:79
ccl_device_inline ccl_private Bssrdf * bssrdf_alloc(ccl_private ShaderData *sd, float3 weight)
Definition: bssrdf.h:259
ccl_device int bssrdf_setup(ccl_private ShaderData *sd, ccl_private Bssrdf *bssrdf, ClosureType type, const float ior)
Definition: bssrdf.h:273
ccl_device_noinline void svm_node_emission_weight(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, uint4 node)
Definition: closure.h:1203
ccl_device_noinline void svm_node_mix_closure(ccl_private ShaderData *sd, ccl_private float *stack, uint4 node)
Definition: closure.h:1217
ccl_device void svm_node_set_normal(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, uint in_direction, uint out_normal)
Definition: closure.h:1241
ccl_device_noinline void svm_node_closure_background(ccl_private ShaderData *sd, ccl_private float *stack, uint4 node)
Definition: closure.h:1142
ccl_device_noinline void svm_node_closure_volume(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, uint4 node)
Definition: closure.h:952
ccl_device void svm_node_closure_weight(ccl_private ShaderData *sd, ccl_private float *stack, uint weight_offset)
Definition: closure.h:1195
ccl_device_noinline int svm_node_principled_volume(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, uint4 node, uint32_t path_flag, int offset)
Definition: closure.h:1007
ccl_device void svm_node_closure_set_weight(ccl_private ShaderData *sd, uint r, uint g, uint b)
Definition: closure.h:1189
ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, uint4 node, uint32_t path_flag, int offset)
Definition: closure.h:67
ccl_device_noinline void svm_node_closure_emission(ccl_private ShaderData *sd, ccl_private float *stack, uint4 node)
Definition: closure.h:1123
CCL_NAMESPACE_BEGIN ccl_device void svm_node_glass_setup(ccl_private ShaderData *sd, ccl_private MicrofacetBsdf *bsdf, int type, float eta, float roughness, bool refract)
Definition: closure.h:10
ccl_device_noinline void svm_node_closure_holdout(ccl_private ShaderData *sd, ccl_private float *stack, uint4 node)
Definition: closure.h:1161
ccl_device_inline int svm_node_closure_bsdf_skip(KernelGlobals kg, int offset, uint type)
Definition: closure.h:53
ccl_device_inline void svm_node_closure_store_weight(ccl_private ShaderData *sd, float3 weight)
Definition: closure.h:1184
#define kernel_assert(cond)
Definition: cpu/compat.h:34
#define logf(x)
Definition: cuda/compat.h:105
#define ccl_device
Definition: cuda/compat.h:32
#define ccl_private
Definition: cuda/compat.h:48
#define ccl_device_inline
Definition: cuda/compat.h:34
#define ccl_device_noinline
Definition: cuda/compat.h:40
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
OperationNode * node
#define kernel_data
const KernelGlobalsCPU *ccl_restrict KernelGlobals
CCL_NAMESPACE_BEGIN ccl_device void background_setup(ccl_private ShaderData *sd, const float3 weight)
Definition: emissive.h:15
ccl_device void emission_setup(ccl_private ShaderData *sd, const float3 weight)
Definition: emissive.h:28
IMETHOD void random(Vector &a)
addDelta operator for displacement rotational velocity.
Definition: frames.inl:1282
#define mix(a, b, c)
Definition: hash.h:17
IconTextureDrawCall normal
ccl_device int volume_henyey_greenstein_setup(ccl_private HenyeyGreensteinVolume *volume)
CCL_NAMESPACE_BEGIN ccl_device void volume_extinction_setup(ccl_private ShaderData *sd, float3 weight)
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
ccl_device_inline AttributeDescriptor find_attribute(KernelGlobals kg, ccl_private const ShaderData *sd, uint id)
ccl_device_inline void stack_store_float3(ccl_private float *stack, uint a, float3 f)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 stack_load_float3(ccl_private float *stack, uint a)
ccl_device_inline uint4 read_node(KernelGlobals kg, ccl_private int *offset)
ccl_device_inline float stack_load_float_default(ccl_private float *stack, uint a, uint value)
ccl_device_inline void stack_store_float(ccl_private float *stack, uint a, float f)
ccl_device_inline float stack_load_float(ccl_private float *stack, uint a)
ccl_device_forceinline void svm_unpack_node_uchar4(uint i, ccl_private uint *x, ccl_private uint *y, ccl_private uint *z, ccl_private uint *w)
ccl_device_inline bool stack_valid(uint a)
@ NODE_PRINCIPLED_HAIR_REFLECTANCE
@ NODE_PRINCIPLED_HAIR_DIRECT_ABSORPTION
@ NODE_PRINCIPLED_HAIR_PIGMENT_CONCENTRATION
@ SHADER_TYPE_SURFACE
@ SHADER_TYPE_VOLUME
#define SVM_STACK_INVALID
ClosureType
@ CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID
@ CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID
@ CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID
@ CLOSURE_BSSRDF_RANDOM_WALK_FIXED_RADIUS_ID
@ CLOSURE_BSDF_HAIR_PRINCIPLED_ID
@ CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID
@ CLOSURE_BSDF_DIFFUSE_ID
@ CLOSURE_BSSRDF_BURLEY_ID
@ CLOSURE_BSDF_PRINCIPLED_ID
@ CLOSURE_BSDF_TRANSPARENT_ID
@ CLOSURE_BSDF_DIFFUSE_TOON_ID
@ CLOSURE_BSDF_MICROFACET_GGX_ID
@ CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID
@ CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID
@ CLOSURE_BSDF_HAIR_TRANSMISSION_ID
@ CLOSURE_BSDF_SHARP_GLASS_ID
@ CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID
@ CLOSURE_BSSRDF_RANDOM_WALK_ID
@ CLOSURE_BSDF_REFRACTION_ID
@ CLOSURE_BSDF_MICROFACET_BECKMANN_ID
@ CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID
@ CLOSURE_HOLDOUT_ID
@ CLOSURE_BSDF_GLOSSY_TOON_ID
@ CLOSURE_VOLUME_ABSORPTION_ID
@ CLOSURE_BSDF_HAIR_REFLECTION_ID
@ CLOSURE_BSDF_TRANSLUCENT_ID
@ CLOSURE_BSDF_REFLECTION_ID
@ CLOSURE_BSDF_ASHIKHMIN_VELVET_ID
#define CLOSURE_WEIGHT_CUTOFF
@ SD_BACKFACING
Definition: kernel/types.h:738
@ SD_HOLDOUT
Definition: kernel/types.h:748
@ PRIMITIVE_CURVE
Definition: kernel/types.h:564
@ ATTR_STD_NOT_FOUND
Definition: kernel/types.h:647
#define IF_KERNEL_NODES_FEATURE(feature)
@ PATH_RAY_SHADOW
Definition: kernel/types.h:206
@ PATH_RAY_DIFFUSE
Definition: kernel/types.h:197
@ PATH_RAY_DIFFUSE_ANCESTOR
Definition: kernel/types.h:229
ShaderData
Definition: kernel/types.h:925
ShaderClosure
Definition: kernel/types.h:726
ccl_device float3 rec709_to_rgb(KernelGlobals kg, float3 rec709)
ccl_device float linear_rgb_to_gray(KernelGlobals kg, float3 c)
ccl_device_inline float average(const float2 &a)
Definition: math_float2.h:170
ccl_device_inline float3 refract(const float3 incident, const float3 normal, const float eta)
Definition: math_float3.h:435
ccl_device float3 svm_math_blackbody_color_rec709(float t)
Definition: math_util.h:192
#define N
#define T
#define T4
Definition: md5.cpp:20
#define fmaxf(x, y)
Definition: metal/compat.h:228
#define fabsf(x)
Definition: metal/compat.h:219
#define make_float3(x, y, z)
Definition: metal/compat.h:204
T dot(const vec_base< T, Size > &a, const vec_base< T, Size > &b)
T clamp(const T &a, const T &min, const T &max)
vec_base< T, Size > normalize(const vec_base< T, Size > &v)
static const pxr::TfToken clearcoat("clearcoat", pxr::TfToken::Immortal)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
static const pxr::TfToken ior("ior", pxr::TfToken::Immortal)
static const pxr::TfToken g("g", pxr::TfToken::Immortal)
static const pxr::TfToken density("density", pxr::TfToken::Immortal)
static const pxr::TfToken roughness("roughness", pxr::TfToken::Immortal)
static const pxr::TfToken specular("specular", pxr::TfToken::Immortal)
CCL_NAMESPACE_BEGIN ccl_device_forceinline float primitive_surface_attribute_float(KernelGlobals kg, ccl_private const ShaderData *sd, const AttributeDescriptor desc, ccl_private float *dx, ccl_private float *dy)
Definition: primitive.h:21
closure color absorption() BUILTIN
closure color bssrdf(string method, normal N, vector radius, color albedo) BUILTIN
unsigned int uint32_t
Definition: stdint.h:80
Definition: bssrdf.h:8
float z
float y
float x
uint x
Definition: types_uint4.h:15
uint y
Definition: types_uint4.h:15
uint z
Definition: types_uint4.h:15
uint w
Definition: types_uint4.h:15
float max
ccl_device_inline float __uint_as_float(uint i)
Definition: util/math.h:273
ccl_device_inline float sqr(float a)
Definition: util/math.h:746
#define M_2PI_F
Definition: util/math.h:60
ccl_device_inline float saturatef(float a)
Definition: util/math.h:404
#define M_PI_F
Definition: util/math.h:34
ccl_device_inline float3 rotate_around_axis(float3 p, float3 axis, float angle)
Definition: util/math.h:654