Blender V4.3
surface_shader.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5/* Functions to evaluate shaders. */
6
7#pragma once
8
10#include "kernel/closure/bsdf.h"
13
15
16#ifdef __SVM__
17# include "kernel/svm/svm.h"
18#endif
19#ifdef __OSL__
20# include "kernel/osl/osl.h"
21#endif
22
24
25/* Guiding */
26
27#ifdef __PATH_GUIDING__
28
29ccl_device float surface_shader_average_sample_weight_squared_roughness(
30 ccl_private const ShaderData *sd)
31{
32 float avg_squared_roughness = 0.0f;
33 float sum_sample_weight = 0.0f;
34 for (int i = 0; i < sd->num_closure; i++) {
35 ccl_private const ShaderClosure *sc = &sd->closure[i];
36
37 if (!CLOSURE_IS_BSDF_OR_BSSRDF(sc->type)) {
38 continue;
39 }
40 avg_squared_roughness += sc->sample_weight * bsdf_get_specular_roughness_squared(sc);
41 sum_sample_weight += sc->sample_weight;
42 }
43
44 avg_squared_roughness = avg_squared_roughness > 0.0f ?
45 avg_squared_roughness / sum_sample_weight :
46 0.0f;
47 return avg_squared_roughness;
48}
49
50ccl_device_inline void surface_shader_prepare_guiding(KernelGlobals kg,
53 ccl_private const RNGState *rng_state)
54{
55 /* Have any BSDF to guide? */
56 if (!(kernel_data.integrator.use_surface_guiding && (sd->flag & SD_BSDF_HAS_EVAL))) {
57 state->guiding.use_surface_guiding = false;
58 return;
59 }
60
61 const float surface_guiding_probability = kernel_data.integrator.surface_guiding_probability;
62 const int guiding_directional_sampling_type =
63 kernel_data.integrator.guiding_directional_sampling_type;
64 const float guiding_roughness_threshold = kernel_data.integrator.guiding_roughness_threshold;
65 float rand_bsdf_guiding = path_state_rng_1D(kg, rng_state, PRNG_SURFACE_BSDF_GUIDING);
66
67 /* Compute proportion of diffuse BSDF and BSSRDFs. */
68 float diffuse_sampling_fraction = 0.0f;
69 float bssrdf_sampling_fraction = 0.0f;
70 float bsdf_bssrdf_sampling_sum = 0.0f;
71
72 bool fully_opaque = true;
73
74 for (int i = 0; i < sd->num_closure; i++) {
75 ShaderClosure *sc = &sd->closure[i];
76 if (CLOSURE_IS_BSDF_OR_BSSRDF(sc->type)) {
77 const float sweight = sc->sample_weight;
78 kernel_assert(sweight >= 0.0f);
79
80 bsdf_bssrdf_sampling_sum += sweight;
81 if (CLOSURE_IS_BSDF_DIFFUSE(sc->type) && sc->type < CLOSURE_BSDF_TRANSLUCENT_ID) {
82 diffuse_sampling_fraction += sweight;
83 }
84 if (CLOSURE_IS_BSSRDF(sc->type)) {
85 bssrdf_sampling_fraction += sweight;
86 }
87
89 fully_opaque = false;
90 }
91 }
92 }
93
94 if (bsdf_bssrdf_sampling_sum > 0.0f) {
95 diffuse_sampling_fraction /= bsdf_bssrdf_sampling_sum;
96 bssrdf_sampling_fraction /= bsdf_bssrdf_sampling_sum;
97 }
98
99 /* Initial guiding */
100 /* The roughness because the function returns `alpha.x * alpha.y`.
101 * In addition alpha is squared again. */
102 float avg_roughness = surface_shader_average_sample_weight_squared_roughness(sd);
103 avg_roughness = safe_sqrtf(avg_roughness);
104 if (!fully_opaque || avg_roughness < guiding_roughness_threshold ||
105 ((guiding_directional_sampling_type == GUIDING_DIRECTIONAL_SAMPLING_TYPE_PRODUCT_MIS) &&
106 (diffuse_sampling_fraction <= 0.0f)) ||
107 !guiding_bsdf_init(kg, state, sd->P, sd->N, rand_bsdf_guiding))
108 {
109 state->guiding.use_surface_guiding = false;
110 state->guiding.surface_guiding_sampling_prob = 0.0f;
111 return;
112 }
113
114 state->guiding.use_surface_guiding = true;
115 if (kernel_data.integrator.guiding_directional_sampling_type ==
117 {
118 state->guiding.surface_guiding_sampling_prob = surface_guiding_probability *
119 diffuse_sampling_fraction;
120 }
121 else if (kernel_data.integrator.guiding_directional_sampling_type ==
123 {
124 state->guiding.surface_guiding_sampling_prob = surface_guiding_probability;
125 }
126 else { // GUIDING_DIRECTIONAL_SAMPLING_TYPE_ROUGHNESS
127 state->guiding.surface_guiding_sampling_prob = surface_guiding_probability * avg_roughness;
128 }
129 state->guiding.bssrdf_sampling_prob = bssrdf_sampling_fraction;
130 state->guiding.sample_surface_guiding_rand = rand_bsdf_guiding;
131
132 kernel_assert(state->guiding.surface_guiding_sampling_prob > 0.0f &&
133 state->guiding.surface_guiding_sampling_prob <= 1.0f);
134}
135#endif
136
140 const uint32_t path_flag)
141{
142 /* Filter out closures. */
143 if (kernel_data.integrator.filter_closures) {
144 const int filter_closures = kernel_data.integrator.filter_closures;
145 if (filter_closures & FILTER_CLOSURE_EMISSION) {
146 sd->closure_emission_background = zero_spectrum();
147 }
148
149 if (path_flag & PATH_RAY_CAMERA) {
150 if (filter_closures & FILTER_CLOSURE_DIRECT_LIGHT) {
151 sd->flag &= ~SD_BSDF_HAS_EVAL;
152 }
153
154 for (int i = 0; i < sd->num_closure; i++) {
155 ccl_private ShaderClosure *sc = &sd->closure[i];
156
157 const bool filter_diffuse = (filter_closures & FILTER_CLOSURE_DIFFUSE);
158 const bool filter_glossy = (filter_closures & FILTER_CLOSURE_GLOSSY);
159 const bool filter_transmission = (filter_closures & FILTER_CLOSURE_TRANSMISSION);
160 const bool filter_glass = filter_glossy && filter_transmission;
161 if ((CLOSURE_IS_BSDF_DIFFUSE(sc->type) && filter_diffuse) ||
162 (CLOSURE_IS_BSDF_GLOSSY(sc->type) && filter_glossy) ||
163 (CLOSURE_IS_BSDF_TRANSMISSION(sc->type) && filter_transmission) ||
164 (CLOSURE_IS_GLASS(sc->type) && filter_glass))
165 {
166 sc->type = CLOSURE_NONE_ID;
167 sc->sample_weight = 0.0f;
168 }
169 else if ((CLOSURE_IS_BSDF_TRANSPARENT(sc->type) &&
170 (filter_closures & FILTER_CLOSURE_TRANSPARENT)))
171 {
172 sc->type = CLOSURE_HOLDOUT_ID;
173 sc->sample_weight = 0.0f;
174 sd->flag |= SD_HOLDOUT;
175 }
176 }
177 }
178 }
179
180 /* Filter glossy.
181 *
182 * Blurring of bsdf after bounces, for rays that have a small likelihood
183 * of following this particular path (diffuse, rough glossy) */
184 if (kernel_data.integrator.filter_glossy != FLT_MAX
185#ifdef __MNEE__
186 && !(INTEGRATOR_STATE(state, path, mnee) & PATH_MNEE_VALID)
187#endif
188 )
189 {
190 float blur_pdf = kernel_data.integrator.filter_glossy *
191 INTEGRATOR_STATE(state, path, min_ray_pdf);
192
193 if (blur_pdf < 1.0f) {
194 float blur_roughness = sqrtf(1.0f - blur_pdf) * 0.5f;
195
196 for (int i = 0; i < sd->num_closure; i++) {
197 ccl_private ShaderClosure *sc = &sd->closure[i];
198 if (CLOSURE_IS_BSDF(sc->type)) {
199 bsdf_blur(kg, sc, blur_roughness);
200 }
201 }
202
203 /* NOTE: this is a sufficient condition. If `blur_roughness < THRESH < original_roughness`
204 * then the flag was already set. */
205 if (sqr(blur_roughness) > BSDF_ROUGHNESS_SQ_THRESH) {
206 sd->flag |= SD_BSDF_HAS_EVAL;
207 }
208 }
209 }
210}
211
212/* BSDF */
213#ifdef WITH_CYCLES_DEBUG
214ccl_device_inline void surface_shader_validate_bsdf_sample(const KernelGlobals kg,
215 ccl_private const ShaderClosure *sc,
216 const float3 wo,
217 const int org_label,
218 const float2 org_roughness,
219 const float org_eta)
220{
221 /* Validate the #bsdf_label and #bsdf_roughness_eta functions
222 * by estimating the values after a BSDF sample. */
223 kernel_assert(org_label == bsdf_label(kg, sc, wo));
224
225 float2 comp_roughness;
226 float comp_eta;
227 bsdf_roughness_eta(kg, sc, wo, &comp_roughness, &comp_eta);
228 kernel_assert(org_eta == comp_eta);
229 kernel_assert(org_roughness.x == comp_roughness.x);
230 kernel_assert(org_roughness.y == comp_roughness.y);
231}
232#endif
233
235{
236 if (!(light_shader_flags & SHADER_EXCLUDE_ANY)) {
237 return false;
238 }
239 if (light_shader_flags & SHADER_EXCLUDE_DIFFUSE) {
240 if (CLOSURE_IS_BSDF_DIFFUSE(type)) {
241 return true;
242 }
243 }
244 if (light_shader_flags & SHADER_EXCLUDE_GLOSSY) {
245 if (CLOSURE_IS_BSDF_GLOSSY(type)) {
246 return true;
247 }
248 }
249 if (light_shader_flags & SHADER_EXCLUDE_TRANSMIT) {
251 return true;
252 }
253 }
254 /* Glass closures are both glossy and transmissive, so only exclude them if both are filtered. */
255 const uint exclude_glass = SHADER_EXCLUDE_TRANSMIT | SHADER_EXCLUDE_GLOSSY;
256 if ((light_shader_flags & exclude_glass) == exclude_glass) {
257 if (CLOSURE_IS_GLASS(type)) {
258 return true;
259 }
260 }
261 return false;
262}
263
266 const float3 wo,
267 ccl_private const ShaderClosure *skip_sc,
268 ccl_private BsdfEval *result_eval,
269 float sum_pdf,
270 float sum_sample_weight,
271 const uint light_shader_flags)
272{
273 /* This is the veach one-sample model with balance heuristic,
274 * some PDF factors drop out when using balance heuristic weighting. */
275 for (int i = 0; i < sd->num_closure; i++) {
276 ccl_private const ShaderClosure *sc = &sd->closure[i];
277
278 if (sc == skip_sc) {
279 continue;
280 }
281
282 if (CLOSURE_IS_BSDF_OR_BSSRDF(sc->type)) {
283 if (CLOSURE_IS_BSDF(sc->type) && !_surface_shader_exclude(sc->type, light_shader_flags)) {
284 float bsdf_pdf = 0.0f;
285 Spectrum eval = bsdf_eval(kg, sd, sc, wo, &bsdf_pdf);
286
287 if (bsdf_pdf != 0.0f) {
288 bsdf_eval_accum(result_eval, sc, wo, eval * sc->weight);
289 sum_pdf += bsdf_pdf * sc->sample_weight;
290 }
291 }
292
293 sum_sample_weight += sc->sample_weight;
294 }
295 }
296
297 return (sum_sample_weight > 0.0f) ? sum_pdf / sum_sample_weight : 0.0f;
298}
299
302 const float3 wo,
303 ccl_private BsdfEval *result_eval,
304 ccl_private float *pdfs,
305 const uint light_shader_flags)
306{
307 /* This is the veach one-sample model with balance heuristic, some pdf
308 * factors drop out when using balance heuristic weighting. */
309 float sum_pdf = 0.0f;
310 float sum_sample_weight = 0.0f;
311 bsdf_eval_init(result_eval, zero_spectrum());
312 for (int i = 0; i < sd->num_closure; i++) {
313 ccl_private const ShaderClosure *sc = &sd->closure[i];
314
315 if (CLOSURE_IS_BSDF_OR_BSSRDF(sc->type)) {
316 if (CLOSURE_IS_BSDF(sc->type) && !_surface_shader_exclude(sc->type, light_shader_flags)) {
317 float bsdf_pdf = 0.0f;
318 Spectrum eval = bsdf_eval(kg, sd, sc, wo, &bsdf_pdf);
319 kernel_assert(bsdf_pdf >= 0.0f);
320 if (bsdf_pdf != 0.0f) {
321 bsdf_eval_accum(result_eval, sc, wo, eval * sc->weight);
322 sum_pdf += bsdf_pdf * sc->sample_weight;
323 kernel_assert(bsdf_pdf * sc->sample_weight >= 0.0f);
324 pdfs[i] = bsdf_pdf * sc->sample_weight;
325 }
326 else {
327 pdfs[i] = 0.0f;
328 }
329 }
330 else {
331 pdfs[i] = 0.0f;
332 }
333
334 sum_sample_weight += sc->sample_weight;
335 }
336 else {
337 pdfs[i] = 0.0f;
338 }
339 }
340 if (sum_pdf > 0.0f) {
341 for (int i = 0; i < sd->num_closure; i++) {
342 pdfs[i] /= sum_pdf;
343 }
344 }
345
346 return (sum_sample_weight > 0.0f) ? sum_pdf / sum_sample_weight : 0.0f;
347}
348
349#ifndef __KERNEL_CUDA__
351#else
353#endif
354 float
358 const float3 wo,
360 const uint light_shader_flags)
361{
363
365 kg, sd, wo, NULL, bsdf_eval, 0.0f, 0.0f, light_shader_flags);
366
367 /* If the light does not use MIS, then it is only sampled via NEE, so the probability of hitting
368 * the light using BSDF sampling is zero. */
369 if (!(light_shader_flags & SHADER_USE_MIS)) {
370 pdf = 0.0f;
371 }
372
373#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
374 if (pdf > 0.0f && state->guiding.use_surface_guiding) {
375 const float guiding_sampling_prob = state->guiding.surface_guiding_sampling_prob;
376 const float bssrdf_sampling_prob = state->guiding.bssrdf_sampling_prob;
377 const float guide_pdf = guiding_bsdf_pdf(kg, state, wo);
378
379 if (kernel_data.integrator.guiding_directional_sampling_type ==
381 {
382 pdf = (0.5f * guide_pdf * (1.0f - bssrdf_sampling_prob)) + 0.5f * pdf;
383 }
384 else {
385 pdf = (guiding_sampling_prob * guide_pdf * (1.0f - bssrdf_sampling_prob)) +
386 (1.0f - guiding_sampling_prob) * pdf;
387 }
388 }
389#endif
390
391 return pdf;
392}
393
394/* Randomly sample a BSSRDF or BSDF proportional to ShaderClosure.sample_weight. */
397{
398 int sampled = 0;
399
400 if (sd->num_closure > 1) {
401 /* Pick a BSDF or based on sample weights. */
402 float sum = 0.0f;
403
404 for (int i = 0; i < sd->num_closure; i++) {
405 ccl_private const ShaderClosure *sc = &sd->closure[i];
406
407 if (CLOSURE_IS_BSDF_OR_BSSRDF(sc->type)) {
408 sum += sc->sample_weight;
409 }
410 }
411
412 float r = (*rand_bsdf).z * sum;
413 float partial_sum = 0.0f;
414
415 for (int i = 0; i < sd->num_closure; i++) {
416 ccl_private const ShaderClosure *sc = &sd->closure[i];
417
418 if (CLOSURE_IS_BSDF_OR_BSSRDF(sc->type)) {
419 float next_sum = partial_sum + sc->sample_weight;
420
421 if (r < next_sum) {
422 sampled = i;
423
424 /* Rescale to reuse for direction sample, to better preserve stratification. */
425 (*rand_bsdf).z = (r - partial_sum) / sc->sample_weight;
426 break;
427 }
428
429 partial_sum = next_sum;
430 }
431 }
432 }
433
434 return &sd->closure[sampled];
435}
436
437/* Return weight for picked BSSRDF. */
440 ccl_private const ShaderClosure *ccl_restrict bssrdf_sc)
441{
442 Spectrum weight = bssrdf_sc->weight;
443
444 if (sd->num_closure > 1) {
445 float sum = 0.0f;
446 for (int i = 0; i < sd->num_closure; i++) {
447 ccl_private const ShaderClosure *sc = &sd->closure[i];
448
449 if (CLOSURE_IS_BSDF_OR_BSSRDF(sc->type)) {
450 sum += sc->sample_weight;
451 }
452 }
453 weight *= sum / bssrdf_sc->sample_weight;
454 }
455
456 return weight;
457}
458
459#ifdef __PATH_GUIDING__
460/* Sample direction for picked BSDF, and return evaluation and pdf for all
461 * BSDFs combined using MIS. */
462
463ccl_device int surface_shader_bsdf_guided_sample_closure_mis(KernelGlobals kg,
466 ccl_private const ShaderClosure *sc,
467 const float3 rand_bsdf,
470 ccl_private float *bsdf_pdf,
471 ccl_private float *unguided_bsdf_pdf,
472 ccl_private float2 *sampled_roughness,
473 ccl_private float *eta)
474{
475 /* BSSRDF should already have been handled elsewhere. */
477
478 const bool use_surface_guiding = state->guiding.use_surface_guiding;
479 const float guiding_sampling_prob = state->guiding.surface_guiding_sampling_prob;
480 const float bssrdf_sampling_prob = state->guiding.bssrdf_sampling_prob;
481
482 /* Decide between sampling guiding distribution and BSDF. */
483 bool sample_guiding = false;
484 float rand_bsdf_guiding = state->guiding.sample_surface_guiding_rand;
485
486 if (use_surface_guiding && rand_bsdf_guiding < guiding_sampling_prob) {
487 sample_guiding = true;
488 rand_bsdf_guiding /= guiding_sampling_prob;
489 }
490 else {
491 rand_bsdf_guiding -= guiding_sampling_prob;
492 rand_bsdf_guiding /= (1.0f - guiding_sampling_prob);
493 }
494
495 /* Initialize to zero. */
496 int label = LABEL_NONE;
497 Spectrum eval = zero_spectrum();
499
500 *unguided_bsdf_pdf = 0.0f;
501 float guide_pdf = 0.0f;
502
503 if (sample_guiding) {
504 /* Sample guiding distribution. */
505 guide_pdf = guiding_bsdf_sample(kg, state, float3_to_float2(rand_bsdf), wo);
506 *bsdf_pdf = 0.0f;
507
508 if (guide_pdf != 0.0f) {
509 float unguided_bsdf_pdfs[MAX_CLOSURE];
510
511 *unguided_bsdf_pdf = surface_shader_bsdf_eval_pdfs(
512 kg, sd, *wo, bsdf_eval, unguided_bsdf_pdfs, 0);
513 *bsdf_pdf = (guiding_sampling_prob * guide_pdf * (1.0f - bssrdf_sampling_prob)) +
514 ((1.0f - guiding_sampling_prob) * (*unguided_bsdf_pdf));
515 float sum_pdfs = 0.0f;
516
517 if (*unguided_bsdf_pdf > 0.0f) {
518 int idx = -1;
519 for (int i = 0; i < sd->num_closure; i++) {
520 sum_pdfs += unguided_bsdf_pdfs[i];
521 if (rand_bsdf_guiding <= sum_pdfs) {
522 idx = i;
523 break;
524 }
525 }
526
527 kernel_assert(idx >= 0);
528 /* Set the default idx to the last in the list.
529 * in case of numerical problems and rand_bsdf_guiding is just >=1.0f and
530 * the sum of all unguided_bsdf_pdfs is just < 1.0f. */
531 idx = (rand_bsdf_guiding > sum_pdfs) ? sd->num_closure - 1 : idx;
532
533 label = bsdf_label(kg, &sd->closure[idx], *wo);
534 }
535 else {
536 *bsdf_pdf = 0.0f;
537 *unguided_bsdf_pdf = 0.0f;
538 }
539 }
540
542
543 *sampled_roughness = make_float2(1.0f, 1.0f);
544 *eta = 1.0f;
545 }
546 else {
547 /* Sample BSDF. */
548 *bsdf_pdf = 0.0f;
549 label = bsdf_sample(kg,
550 sd,
551 sc,
553 rand_bsdf,
554 &eval,
555 wo,
556 unguided_bsdf_pdf,
557 sampled_roughness,
558 eta);
559# ifdef WITH_CYCLES_DEBUG
560 /* Code path to validate the estimation of the label, sampled roughness and eta. This should be
561 * activated from time to time when the BSDFs change to check if everything is still working
562 * correctly. */
563 if (*unguided_bsdf_pdf > 0.0f) {
564 surface_shader_validate_bsdf_sample(kg, sc, *wo, label, *sampled_roughness, *eta);
565 }
566# endif
567
568 if (*unguided_bsdf_pdf != 0.0f) {
569 bsdf_eval_init(bsdf_eval, sc, *wo, eval * sc->weight);
570
572
573 if (sd->num_closure > 1) {
574 float sweight = sc->sample_weight;
575 *unguided_bsdf_pdf = _surface_shader_bsdf_eval_mis(
576 kg, sd, *wo, sc, bsdf_eval, (*unguided_bsdf_pdf) * sweight, sweight, 0);
578 }
579 *bsdf_pdf = *unguided_bsdf_pdf;
580
581 if (use_surface_guiding) {
582 guide_pdf = guiding_bsdf_pdf(kg, state, *wo);
583 *bsdf_pdf *= 1.0f - guiding_sampling_prob;
584 *bsdf_pdf += guiding_sampling_prob * guide_pdf * (1.0f - bssrdf_sampling_prob);
585 }
586 }
587
589 }
590
591 return label;
592}
593
594ccl_device int surface_shader_bsdf_guided_sample_closure_ris(KernelGlobals kg,
597 ccl_private const ShaderClosure *sc,
598 const float3 rand_bsdf,
599 ccl_private const RNGState *rng_state,
602 ccl_private float *bsdf_pdf,
603 ccl_private float *mis_pdf,
604 ccl_private float *unguided_bsdf_pdf,
605 ccl_private float2 *sampled_roughness,
606 ccl_private float *eta)
607{
608 /* BSSRDF should already have been handled elsewhere. */
610
611 const bool use_surface_guiding = state->guiding.use_surface_guiding;
612 const float guiding_sampling_prob = state->guiding.surface_guiding_sampling_prob;
613 const float bssrdf_sampling_prob = state->guiding.bssrdf_sampling_prob;
614
615 /* Decide between sampling guiding distribution and BSDF. */
616 float rand_bsdf_guiding = state->guiding.sample_surface_guiding_rand;
617
618 /* Initialize to zero. */
619 int label = LABEL_NONE;
620 Spectrum eval = zero_spectrum();
622
623 *unguided_bsdf_pdf = 0.0f;
624 float guide_pdf = 0.0f;
625
626 if (use_surface_guiding && guiding_sampling_prob > 0.0f) {
627 /* Performing guided sampling using RIS */
628
629 // selected RIS candidate
630 int ris_idx = 0;
631
632 // meta data for the two RIS candidates
633 GuidingRISSample ris_samples[2];
634 ris_samples[0].rand = rand_bsdf;
635 ris_samples[1].rand = path_state_rng_3D(kg, rng_state, PRNG_SURFACE_RIS_GUIDING_0);
636
637 // ----------------------------------------------------
638 // generate the first RIS candidate using a BSDF sample
639 // ----------------------------------------------------
640 ris_samples[0].label = bsdf_sample(kg,
641 sd,
642 sc,
644 ris_samples[0].rand,
645 &ris_samples[0].eval,
646 &ris_samples[0].wo,
647 &ris_samples[0].bsdf_pdf,
648 &ris_samples[0].sampled_roughness,
649 &ris_samples[0].eta);
650
652 &ris_samples[0].bsdf_eval, sc, ris_samples[0].wo, ris_samples[0].eval * sc->weight);
653 if (ris_samples[0].bsdf_pdf > 0.0f) {
654 if (sd->num_closure > 1) {
655 float sweight = sc->sample_weight;
656 ris_samples[0].bsdf_pdf = _surface_shader_bsdf_eval_mis(kg,
657 sd,
658 ris_samples[0].wo,
659 sc,
660 &ris_samples[0].bsdf_eval,
661 (ris_samples[0].bsdf_pdf) *
662 sweight,
663 sweight,
664 0);
665 kernel_assert(reduce_min(bsdf_eval_sum(&ris_samples[0].bsdf_eval)) >= 0.0f);
666 }
667 ris_samples[0].avg_bsdf_eval = average(ris_samples[0].bsdf_eval.sum);
668 ris_samples[0].guide_pdf = guiding_bsdf_pdf(kg, state, ris_samples[0].wo);
669 ris_samples[0].guide_pdf *= (1.0f - bssrdf_sampling_prob);
671 kg, state, ris_samples[0].wo);
672 ris_samples[0].bsdf_pdf = max(0.0f, ris_samples[0].bsdf_pdf);
673 }
674
675 // ------------------------------------------------------------------------------
676 // generate the second RIS candidate using a sample from the guiding distribution
677 // ------------------------------------------------------------------------------
678 float unguided_bsdf_pdfs[MAX_CLOSURE];
679 bsdf_eval_init(&ris_samples[1].bsdf_eval, eval);
680 ris_samples[1].guide_pdf = guiding_bsdf_sample(
681 kg, state, float3_to_float2(ris_samples[1].rand), &ris_samples[1].wo);
682 ris_samples[1].guide_pdf *= (1.0f - bssrdf_sampling_prob);
684 kg, state, ris_samples[1].wo);
686 kg, sd, ris_samples[1].wo, &ris_samples[1].bsdf_eval, unguided_bsdf_pdfs, 0);
687 ris_samples[1].label = ris_samples[0].label;
688 ris_samples[1].avg_bsdf_eval = average(ris_samples[1].bsdf_eval.sum);
689 ris_samples[1].bsdf_pdf = max(0.0f, ris_samples[1].bsdf_pdf);
690
691 // ------------------------------------------------------------------------------
692 // calculate the RIS target functions for each RIS candidate
693 // ------------------------------------------------------------------------------
694 int num_ris_candidates = 0;
695 float sum_ris_weights = 0.0f;
696 if (calculate_ris_target(&ris_samples[0], guiding_sampling_prob)) {
697 sum_ris_weights += ris_samples[0].ris_weight;
698 num_ris_candidates++;
699 }
700 kernel_assert(ris_samples[0].ris_weight >= 0.0f);
701 kernel_assert(sum_ris_weights >= 0.0f);
702
703 if (calculate_ris_target(&ris_samples[1], guiding_sampling_prob)) {
704 sum_ris_weights += ris_samples[1].ris_weight;
705 num_ris_candidates++;
706 }
707 kernel_assert(ris_samples[1].ris_weight >= 0.0f);
708 kernel_assert(sum_ris_weights >= 0.0f);
709
710 // ------------------------------------------------------------------------------
711 // Sample/Select a sample from the RIS candidates proportional to the target
712 // ------------------------------------------------------------------------------
713 if (num_ris_candidates == 0 || !(sum_ris_weights > 1e-10f)) {
714 *bsdf_pdf = 0.0f;
715 *mis_pdf = 0.0f;
716 return label;
717 }
718
719 float rand_ris_select = rand_bsdf_guiding * sum_ris_weights;
720
721 float sum_ris = 0.0f;
722 for (int i = 0; i < 2; i++) {
723 sum_ris += ris_samples[i].ris_weight;
724 if (rand_ris_select <= sum_ris) {
725 ris_idx = i;
726 break;
727 }
728 }
729
730 kernel_assert(sum_ris >= 0.0f);
731 kernel_assert(ris_idx < 2);
732
733 // ------------------------------------------------------------------------------
734 // Fill in the sample data for the selected RIS candidate
735 // ------------------------------------------------------------------------------
736 guide_pdf = ris_samples[ris_idx].ris_target * (2.0f / sum_ris_weights);
737 *unguided_bsdf_pdf = ris_samples[ris_idx].bsdf_pdf;
738 *mis_pdf = 0.5f * (ris_samples[ris_idx].bsdf_pdf + ris_samples[ris_idx].guide_pdf);
739 *bsdf_pdf = guide_pdf;
740
741 *wo = ris_samples[ris_idx].wo;
742 label = ris_samples[ris_idx].label;
743
744 *sampled_roughness = ris_samples[ris_idx].sampled_roughness;
745 *eta = ris_samples[ris_idx].eta;
746 *bsdf_eval = ris_samples[ris_idx].bsdf_eval;
747
748 kernel_assert(isfinite_safe(guide_pdf));
749 kernel_assert(isfinite_safe(*bsdf_pdf));
750
751 if (!(*bsdf_pdf > 1e-10f)) {
752 *bsdf_pdf = 0.0f;
753 *mis_pdf = 0.0f;
754 return label;
755 }
756
757 kernel_assert(*bsdf_pdf > 0.0f);
758 kernel_assert(*bsdf_pdf >= 1e-20f);
759 kernel_assert(guide_pdf >= 0.0f);
760
762 if (ris_idx == 1 && ris_samples[1].bsdf_pdf > 0.0f) {
763
764 float rnd = path_state_rng_1D(kg, rng_state, PRNG_SURFACE_RIS_GUIDING_1);
765
766 float sum_pdfs = 0.0f;
767 int idx = -1;
768 for (int i = 0; i < sd->num_closure; i++) {
769 sum_pdfs += unguided_bsdf_pdfs[i];
770 if (rnd <= sum_pdfs) {
771 idx = i;
772 break;
773 }
774 }
775 // kernel_assert(idx >= 0);
776 /* Set the default idx to the last in the list.
777 * in case of numerical problems and rand_bsdf_guiding is just >=1.0f and
778 * the sum of all unguided_bsdf_pdfs is just < 1.0f. */
779 idx = (rnd > sum_pdfs) ? sd->num_closure - 1 : idx;
780
781 label = bsdf_label(kg, &sd->closure[idx], *wo);
782 bsdf_roughness_eta(kg, &sd->closure[idx], *wo, sampled_roughness, eta);
783 }
784
785 kernel_assert(isfinite_safe(*bsdf_pdf));
786 kernel_assert(*bsdf_pdf >= 0.0f);
788 }
789 else {
790 /* Sample BSDF. */
791 *bsdf_pdf = 0.0f;
792 label = bsdf_sample(kg,
793 sd,
794 sc,
796 rand_bsdf,
797 &eval,
798 wo,
799 unguided_bsdf_pdf,
800 sampled_roughness,
801 eta);
802# ifdef WITH_CYCLES_DEBUG
803 // Code path to validate the estimation of the label, sampled roughness and eta
804 // This should be activated from time to time when the BSDFs change to check if everything
805 // is still working correctly.
806 if (*unguided_bsdf_pdf > 0.0f) {
807 surface_shader_validate_bsdf_sample(kg, sc, *wo, label, *sampled_roughness, *eta);
808 }
809# endif
810
811 if (*unguided_bsdf_pdf != 0.0f) {
812 bsdf_eval_init(bsdf_eval, sc, *wo, eval * sc->weight);
813
815
816 if (sd->num_closure > 1) {
817 float sweight = sc->sample_weight;
818 *unguided_bsdf_pdf = _surface_shader_bsdf_eval_mis(
819 kg, sd, *wo, sc, bsdf_eval, (*unguided_bsdf_pdf) * sweight, sweight, 0);
821 }
822 *bsdf_pdf = *unguided_bsdf_pdf;
823 *mis_pdf = *bsdf_pdf;
824 }
825
827 }
828
829 return label;
830}
831
832ccl_device int surface_shader_bsdf_guided_sample_closure(KernelGlobals kg,
835 ccl_private const ShaderClosure *sc,
836 const float3 rand_bsdf,
839 ccl_private float *bsdf_pdf,
840 ccl_private float *mis_pdf,
841 ccl_private float *unguided_bsdf_pdf,
842 ccl_private float2 *sampled_roughness,
843 ccl_private float *eta,
844 ccl_private const RNGState *rng_state)
845{
846 int label = LABEL_NONE;
847 if (kernel_data.integrator.guiding_directional_sampling_type ==
849 kernel_data.integrator.guiding_directional_sampling_type ==
851 {
852 label = surface_shader_bsdf_guided_sample_closure_mis(kg,
853 state,
854 sd,
855 sc,
856 rand_bsdf,
857 bsdf_eval,
858 wo,
859 bsdf_pdf,
860 unguided_bsdf_pdf,
861 sampled_roughness,
862 eta);
863 *mis_pdf = (*unguided_bsdf_pdf > 0.0f) ? *bsdf_pdf : 0.0f;
864 }
865 else if (kernel_data.integrator.guiding_directional_sampling_type ==
867 {
868 label = surface_shader_bsdf_guided_sample_closure_ris(kg,
869 state,
870 sd,
871 sc,
872 rand_bsdf,
873 rng_state,
874 bsdf_eval,
875 wo,
876 bsdf_pdf,
877 mis_pdf,
878 unguided_bsdf_pdf,
879 sampled_roughness,
880 eta);
881 }
882 if (!(*unguided_bsdf_pdf > 0.0f)) {
883 *bsdf_pdf = 0.0f;
884 *mis_pdf = 0.0f;
885 }
886 return label;
887}
888
889#endif
890
891/* Sample direction for picked BSDF, and return evaluation and pdf for all
892 * BSDFs combined using MIS. */
895 ccl_private const ShaderClosure *sc,
896 const int path_flag,
897 const float3 rand_bsdf,
900 ccl_private float *pdf,
901 ccl_private float2 *sampled_roughness,
902 ccl_private float *eta)
903{
904 /* BSSRDF should already have been handled elsewhere. */
906
907 int label;
908 Spectrum eval = zero_spectrum();
909
910 *pdf = 0.0f;
911 label = bsdf_sample(kg, sd, sc, path_flag, rand_bsdf, &eval, wo, pdf, sampled_roughness, eta);
912
913 if (*pdf != 0.0f) {
914 bsdf_eval_init(bsdf_eval, sc, *wo, eval * sc->weight);
915
916 if (sd->num_closure > 1) {
917 float sweight = sc->sample_weight;
918 *pdf = _surface_shader_bsdf_eval_mis(kg, sd, *wo, sc, bsdf_eval, *pdf * sweight, sweight, 0);
919 }
920 }
921 else {
923 }
924
925 return label;
926}
927
929{
930 float roughness = 0.0f;
931 float sum_weight = 0.0f;
932
933 for (int i = 0; i < sd->num_closure; i++) {
934 ccl_private const ShaderClosure *sc = &sd->closure[i];
935
936 if (CLOSURE_IS_BSDF(sc->type)) {
937 /* `sqrt()` once to undo the squaring from multiplying roughness on the
938 * two axes, and once for the squared roughness convention. */
939 float value = bsdf_get_roughness_pass_squared(sc);
940 if (value >= 0.0f) {
941 float weight = fabsf(average(sc->weight));
942 roughness += weight * sqrtf(sqrtf(value));
943 sum_weight += weight;
944 }
945 }
946 }
947
948 return (sum_weight > 0.0f) ? roughness / sum_weight : 1.0f;
949}
950
952{
953 if (sd->flag & SD_HAS_ONLY_VOLUME) {
954 return one_spectrum();
955 }
956 else if (sd->flag & (SD_TRANSPARENT | SD_RAY_PORTAL)) {
957 return sd->closure_transparent_extinction;
958 }
959 else {
960 return zero_spectrum();
961 }
962}
963
965{
967
968 alpha = saturate(alpha);
969
970 return alpha;
971}
972
974{
975 Spectrum eval = zero_spectrum();
976
977 for (int i = 0; i < sd->num_closure; i++) {
978 ccl_private const ShaderClosure *sc = &sd->closure[i];
979
980 if (CLOSURE_IS_BSDF_DIFFUSE(sc->type) || CLOSURE_IS_BSSRDF(sc->type))
981 eval += bsdf_albedo(kg, sd, sc, true, true);
982 }
983
984 return eval;
985}
986
988{
989 Spectrum eval = zero_spectrum();
990
991 for (int i = 0; i < sd->num_closure; i++) {
992 ccl_private const ShaderClosure *sc = &sd->closure[i];
993
994 if (CLOSURE_IS_BSDF_GLOSSY(sc->type) || CLOSURE_IS_GLASS(sc->type))
995 eval += bsdf_albedo(kg, sd, sc, true, false);
996 }
997
998 return eval;
999}
1000
1002{
1003 Spectrum eval = zero_spectrum();
1004
1005 for (int i = 0; i < sd->num_closure; i++) {
1006 ccl_private const ShaderClosure *sc = &sd->closure[i];
1007
1008 if (CLOSURE_IS_BSDF_TRANSMISSION(sc->type) || CLOSURE_IS_GLASS(sc->type))
1009 eval += bsdf_albedo(kg, sd, sc, false, true);
1010 }
1011
1012 return eval;
1013}
1014
1016{
1017 float3 N = zero_float3();
1018
1019 for (int i = 0; i < sd->num_closure; i++) {
1020 ccl_private const ShaderClosure *sc = &sd->closure[i];
1021 if (CLOSURE_IS_BSDF_OR_BSSRDF(sc->type)) {
1022 N += sc->N * fabsf(average(sc->weight));
1023 }
1024 }
1025
1026 return (is_zero(N)) ? sd->N : normalize(N);
1027}
1028
1030 ccl_private const ShaderData *sd,
1031 const float ao_factor,
1033{
1034 Spectrum eval = zero_spectrum();
1035 float3 N = zero_float3();
1036
1037 for (int i = 0; i < sd->num_closure; i++) {
1038 ccl_private const ShaderClosure *sc = &sd->closure[i];
1039
1040 if (CLOSURE_IS_BSDF_DIFFUSE(sc->type)) {
1041 ccl_private const DiffuseBsdf *bsdf = (ccl_private const DiffuseBsdf *)sc;
1042 eval += sc->weight * ao_factor;
1043 N += bsdf->N * fabsf(average(sc->weight));
1044 }
1045 }
1046
1047 *N_ = (is_zero(N)) ? sd->N : normalize(N);
1048 return eval;
1049}
1050
1051#ifdef __SUBSURFACE__
1052ccl_device float3 surface_shader_bssrdf_normal(ccl_private const ShaderData *sd)
1053{
1054 float3 N = zero_float3();
1055
1056 for (int i = 0; i < sd->num_closure; i++) {
1057 ccl_private const ShaderClosure *sc = &sd->closure[i];
1058
1059 if (CLOSURE_IS_BSSRDF(sc->type)) {
1060 ccl_private const Bssrdf *bssrdf = (ccl_private const Bssrdf *)sc;
1061 float avg_weight = fabsf(average(sc->weight));
1062
1063 N += bssrdf->N * avg_weight;
1064 }
1065 }
1066
1067 return (is_zero(N)) ? sd->N : normalize(N);
1068}
1069#endif /* __SUBSURFACE__ */
1070
1071/* Constant emission optimization */
1072
1074 int shader,
1075 ccl_private Spectrum *eval)
1076{
1077 int shader_index = shader & SHADER_MASK;
1078 int shader_flag = kernel_data_fetch(shaders, shader_index).flags;
1079
1080 if (shader_flag & SD_HAS_CONSTANT_EMISSION) {
1081 const float3 emission_rgb = make_float3(
1082 kernel_data_fetch(shaders, shader_index).constant_emission[0],
1083 kernel_data_fetch(shaders, shader_index).constant_emission[1],
1084 kernel_data_fetch(shaders, shader_index).constant_emission[2]);
1085 *eval = rgb_to_spectrum(emission_rgb);
1086
1087 return true;
1088 }
1089
1090 return false;
1091}
1092
1093/* Background */
1094
1096{
1097 if (sd->flag & SD_EMISSION) {
1098 return sd->closure_emission_background;
1099 }
1100 else {
1101 return zero_spectrum();
1102 }
1103}
1104
1105/* Emission */
1106
1108{
1109 if (sd->flag & SD_EMISSION) {
1110 return emissive_simple_eval(sd->Ng, sd->wi) * sd->closure_emission_background;
1111 }
1112 else {
1113 return zero_spectrum();
1114 }
1115}
1116
1117/* Holdout */
1118
1120{
1121 Spectrum weight = zero_spectrum();
1122
1123 /* For objects marked as holdout, preserve transparency and remove all other
1124 * closures, replacing them with a holdout weight. */
1125 if (sd->object_flag & SD_OBJECT_HOLDOUT_MASK) {
1126 if ((sd->flag & SD_TRANSPARENT) && !(sd->flag & SD_HAS_ONLY_VOLUME)) {
1127 weight = one_spectrum() - sd->closure_transparent_extinction;
1128
1129 for (int i = 0; i < sd->num_closure; i++) {
1130 ccl_private ShaderClosure *sc = &sd->closure[i];
1131 if (!CLOSURE_IS_BSDF_TRANSPARENT(sc->type)) {
1132 sc->type = NBUILTIN_CLOSURES;
1133 }
1134 }
1135
1136 sd->flag &= ~(SD_CLOSURE_FLAGS - (SD_TRANSPARENT | SD_BSDF));
1137 }
1138 else {
1139 weight = one_spectrum();
1140 }
1141 }
1142 else {
1143 for (int i = 0; i < sd->num_closure; i++) {
1144 ccl_private const ShaderClosure *sc = &sd->closure[i];
1145 if (CLOSURE_IS_HOLDOUT(sc->type)) {
1146 weight += sc->weight;
1147 }
1148 }
1149 }
1150
1151 return weight;
1152}
1153
1154/* Surface Evaluation */
1155
1156template<uint node_feature_mask, typename ConstIntegratorGenericState>
1158 ConstIntegratorGenericState state,
1160 ccl_global float *ccl_restrict buffer,
1161 uint32_t path_flag,
1162 bool use_caustics_storage = false)
1163{
1164 /* If path is being terminated, we are tracing a shadow ray or evaluating
1165 * emission, then we don't need to store closures. The emission and shadow
1166 * shader data also do not have a closure array to save GPU memory. */
1167 int max_closures;
1169 max_closures = 0;
1170 }
1171 else {
1172 max_closures = use_caustics_storage ? CAUSTICS_MAX_CLOSURE : kernel_data.max_closures;
1173 }
1174
1175 sd->num_closure = 0;
1176 sd->num_closure_left = max_closures;
1177 sd->closure_transparent_extinction = zero_spectrum();
1178
1179#ifdef __OSL__
1180 if (kernel_data.kernel_features & KERNEL_FEATURE_OSL) {
1181 osl_eval_nodes<SHADER_TYPE_SURFACE>(kg, state, sd, path_flag);
1182 }
1183 else
1184#endif
1185 {
1186#ifdef __SVM__
1188#else
1189 if (sd->object == OBJECT_NONE) {
1190 sd->closure_emission_background = make_spectrum(0.8f);
1191 sd->flag |= SD_EMISSION;
1192 }
1193 else {
1195 sd, sizeof(DiffuseBsdf), make_spectrum(0.8f));
1196 if (bsdf != NULL) {
1197 bsdf->N = sd->N;
1198 sd->flag |= bsdf_diffuse_setup(bsdf);
1199 }
1200 }
1201#endif
1202 }
1203}
1204
MINLINE float safe_sqrtf(float a)
unsigned int uint
#define saturate(a)
ccl_device_inline ccl_private ShaderClosure * bsdf_alloc(ccl_private ShaderData *sd, int size, Spectrum weight)
Definition alloc.h:52
ccl_device_inline int bsdf_label(const KernelGlobals kg, ccl_private const ShaderClosure *sc, const float3 wo)
Definition bsdf.h:366
ccl_device_inline void bsdf_roughness_eta(const KernelGlobals kg, ccl_private const ShaderClosure *sc, const float3 wo, ccl_private float2 *roughness, ccl_private float *eta)
Definition bsdf.h:262
CCL_NAMESPACE_BEGIN ccl_device_inline float bsdf_get_specular_roughness_squared(ccl_private const ShaderClosure *sc)
Definition bsdf.h:30
ccl_device_inline float bsdf_get_roughness_pass_squared(ccl_private const ShaderClosure *sc)
Definition bsdf.h:44
ccl_device_inline int bsdf_sample(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private const ShaderClosure *sc, const int path_flag, const float3 rand, ccl_private Spectrum *eval, ccl_private float3 *wo, ccl_private float *pdf, ccl_private float2 *sampled_roughness, ccl_private float *eta)
Definition bsdf.h:109
ccl_device void bsdf_blur(KernelGlobals kg, ccl_private ShaderClosure *sc, float roughness)
Definition bsdf.h:573
ccl_device Spectrum bsdf_eval(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private const ShaderClosure *sc, const float3 wo, ccl_private float *pdf)
Definition bsdf.h:469
ccl_device_inline Spectrum bsdf_albedo(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private const ShaderClosure *sc, const bool reflection, const bool transmission)
Definition bsdf.h:604
ccl_device int bsdf_diffuse_setup(ccl_private DiffuseBsdf *bsdf)
static T sum(const btAlignedObjectArray< T > &items)
SIMD_FORCE_INLINE btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
Definition btVector3.h:303
void osl_eval_nodes< SHADER_TYPE_SURFACE >(const KernelGlobalsCPU *kg, const void *state, ShaderData *sd, uint32_t path_flag)
Definition closures.cpp:80
const char * label
#define kernel_assert(cond)
#define kernel_data
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define kernel_data_fetch(name, index)
#define ccl_restrict
#define ccl_device_forceinline
#define ccl_device
#define ccl_private
#define ccl_device_inline
#define ccl_global
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
#define NULL
ccl_device_forceinline float2 make_float2(const float x, const float y)
#define fabsf(x)
#define sqrtf(x)
ccl_device Spectrum emissive_simple_eval(const float3 Ng, const float3 wi)
Definition emissive.h:53
ccl_device_forceinline float guiding_bsdf_pdf(KernelGlobals kg, IntegratorState state, const float3 wo)
ccl_device_forceinline bool calculate_ris_target(ccl_private GuidingRISSample *ris_sample, ccl_private const float guiding_sampling_prob)
ccl_device_forceinline float guiding_bsdf_sample(KernelGlobals kg, IntegratorState state, const float2 rand_bsdf, ccl_private float3 *wo)
ccl_device_forceinline float guiding_surface_incoming_radiance_pdf(KernelGlobals kg, IntegratorState state, const float3 wo)
ccl_device_forceinline bool guiding_bsdf_init(KernelGlobals kg, IntegratorState state, const float3 P, const float3 N, ccl_private float &rand)
ccl_device void svm_eval_nodes(KernelGlobals kg, ConstIntegratorGenericState state, ccl_private ShaderData *sd, ccl_global float *render_buffer, uint32_t path_flag)
#define CLOSURE_IS_GLASS(type)
#define CLOSURE_IS_HOLDOUT(type)
#define CLOSURE_IS_BSDF_TRANSPARENT(type)
#define CLOSURE_IS_BSDF_TRANSMISSION(type)
#define CLOSURE_IS_BSDF(type)
#define CLOSURE_IS_BSDF_GLOSSY(type)
#define CLOSURE_IS_BSDF_DIFFUSE(type)
#define CLOSURE_IS_BSDF_OR_BSSRDF(type)
ClosureType
@ CLOSURE_NONE_ID
@ CLOSURE_HOLDOUT_ID
@ NBUILTIN_CLOSURES
@ CLOSURE_BSDF_TRANSLUCENT_ID
#define CLOSURE_IS_BSSRDF(type)
#define BSDF_ROUGHNESS_SQ_THRESH
@ PATH_MNEE_VALID
@ FILTER_CLOSURE_EMISSION
@ FILTER_CLOSURE_GLOSSY
@ FILTER_CLOSURE_DIFFUSE
@ FILTER_CLOSURE_TRANSPARENT
@ FILTER_CLOSURE_DIRECT_LIGHT
@ FILTER_CLOSURE_TRANSMISSION
@ SD_CLOSURE_FLAGS
@ SD_BSDF_HAS_EVAL
@ SD_HAS_CONSTANT_EMISSION
@ SD_HAS_ONLY_VOLUME
@ SD_BSDF
@ SD_RAY_PORTAL
@ SD_TRANSPARENT
@ SD_HOLDOUT
@ SD_EMISSION
@ PRNG_SURFACE_BSDF_GUIDING
@ PRNG_SURFACE_RIS_GUIDING_0
@ PRNG_SURFACE_RIS_GUIDING_1
#define KERNEL_FEATURE_OSL
@ PATH_RAY_SHADOW
@ PATH_RAY_TERMINATE
@ PATH_RAY_EMISSION
@ PATH_RAY_CAMERA
#define OBJECT_NONE
ShaderData
@ SHADER_EXCLUDE_DIFFUSE
@ SHADER_USE_MIS
@ SHADER_EXCLUDE_ANY
@ SHADER_EXCLUDE_GLOSSY
@ SHADER_EXCLUDE_TRANSMIT
@ SHADER_MASK
@ GUIDING_DIRECTIONAL_SAMPLING_TYPE_PRODUCT_MIS
@ GUIDING_DIRECTIONAL_SAMPLING_TYPE_RIS
@ GUIDING_DIRECTIONAL_SAMPLING_TYPE_ROUGHNESS
@ SD_OBJECT_HOLDOUT_MASK
@ LABEL_NONE
#define MAX_CLOSURE
ShaderClosure
#define __MNEE__
#define CAUSTICS_MAX_CLOSURE
ccl_device_inline Spectrum rgb_to_spectrum(float3 rgb)
ccl_device_inline Spectrum bsdf_eval_sum(ccl_private const BsdfEval *eval)
CCL_NAMESPACE_BEGIN ccl_device_inline void bsdf_eval_init(ccl_private BsdfEval *eval, ccl_private const ShaderClosure *sc, const float3 wo, Spectrum value)
ccl_device_inline void bsdf_eval_accum(ccl_private BsdfEval *eval, ccl_private const ShaderClosure *sc, const float3 wo, Spectrum value)
ccl_device_inline bool is_zero(const float2 a)
ccl_device_inline float average(const float2 a)
ccl_device_inline float reduce_min(const float2 a)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
Definition math_float3.h:15
static ulong state[N]
#define N
ccl_device_inline float3 path_state_rng_3D(KernelGlobals kg, ccl_private const RNGState *rng_state, const int dimension)
Definition path_state.h:355
ccl_device_inline float path_state_rng_1D(KernelGlobals kg, ccl_private const RNGState *rng_state, const int dimension)
Definition path_state.h:339
IntegratorStateCPU *ccl_restrict IntegratorState
Definition state.h:228
const IntegratorStateCPU *ccl_restrict ConstIntegratorState
Definition state.h:229
#define INTEGRATOR_STATE(state, nested_struct, member)
Definition state.h:235
#define FLT_MAX
Definition stdcycles.h:14
closure color bssrdf(string method, normal N, vector radius, color albedo) BUILTIN
unsigned int uint32_t
Definition stdint.h:80
Definition bssrdf.h:9
float x
float y
ccl_device Spectrum surface_shader_emission(ccl_private const ShaderData *sd)
ccl_device float surface_shader_bsdf_eval(KernelGlobals kg, IntegratorState state, ccl_private ShaderData *sd, const float3 wo, ccl_private BsdfEval *bsdf_eval, const uint light_shader_flags)
ccl_device bool surface_shader_constant_emission(KernelGlobals kg, int shader, ccl_private Spectrum *eval)
ccl_device_inline float _surface_shader_bsdf_eval_mis(KernelGlobals kg, ccl_private ShaderData *sd, const float3 wo, ccl_private const ShaderClosure *skip_sc, ccl_private BsdfEval *result_eval, float sum_pdf, float sum_sample_weight, const uint light_shader_flags)
ccl_device void surface_shader_eval(KernelGlobals kg, ConstIntegratorGenericState state, ccl_private ShaderData *ccl_restrict sd, ccl_global float *ccl_restrict buffer, uint32_t path_flag, bool use_caustics_storage=false)
ccl_device_inline Spectrum surface_shader_bssrdf_sample_weight(ccl_private const ShaderData *ccl_restrict sd, ccl_private const ShaderClosure *ccl_restrict bssrdf_sc)
ccl_device_inline float surface_shader_bsdf_eval_pdfs(const KernelGlobals kg, ccl_private ShaderData *sd, const float3 wo, ccl_private BsdfEval *result_eval, ccl_private float *pdfs, const uint light_shader_flags)
CCL_NAMESPACE_BEGIN ccl_device_inline void surface_shader_prepare_closures(KernelGlobals kg, ConstIntegratorState state, ccl_private ShaderData *sd, const uint32_t path_flag)
ccl_device Spectrum surface_shader_diffuse(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device float3 surface_shader_average_normal(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device Spectrum surface_shader_glossy(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device_forceinline bool _surface_shader_exclude(ClosureType type, uint light_shader_flags)
ccl_device Spectrum surface_shader_transparency(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device_inline ccl_private const ShaderClosure * surface_shader_bsdf_bssrdf_pick(ccl_private const ShaderData *ccl_restrict sd, ccl_private float3 *rand_bsdf)
ccl_device Spectrum surface_shader_ao(KernelGlobals kg, ccl_private const ShaderData *sd, const float ao_factor, ccl_private float3 *N_)
ccl_device Spectrum surface_shader_background(ccl_private const ShaderData *sd)
ccl_device int surface_shader_bsdf_sample_closure(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private const ShaderClosure *sc, const int path_flag, const float3 rand_bsdf, ccl_private BsdfEval *bsdf_eval, ccl_private float3 *wo, ccl_private float *pdf, ccl_private float2 *sampled_roughness, ccl_private float *eta)
ccl_device Spectrum surface_shader_apply_holdout(KernelGlobals kg, ccl_private ShaderData *sd)
ccl_device float surface_shader_average_roughness(ccl_private const ShaderData *sd)
ccl_device Spectrum surface_shader_alpha(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device Spectrum surface_shader_transmission(KernelGlobals kg, ccl_private const ShaderData *sd)
float max
#define one_spectrum
#define zero_spectrum
#define make_spectrum(f)
SPECTRUM_DATA_TYPE Spectrum
ccl_device_inline float sqr(float a)
Definition util/math.h:782
ccl_device_inline bool isfinite_safe(float f)
Definition util/math.h:365
ccl_device_inline float2 float3_to_float2(const float3 a)
Definition util/math.h:530
#define N_(msgid)
uint8_t flag
Definition wm_window.cc:138