Cycles: add random walk subsurface scattering to Principled BSDF.
[blender.git] / intern / cycles / kernel / kernel_subsurface.h
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 CCL_NAMESPACE_BEGIN
18
19 /* BSSRDF using disk based importance sampling.
20  *
21  * BSSRDF Importance Sampling, SIGGRAPH 2013
22  * http://library.imageworks.com/pdfs/imageworks-library-BSSRDF-sampling.pdf
23  */
24
25 ccl_device_inline float3 subsurface_scatter_eval(ShaderData *sd,
26                                                  const ShaderClosure *sc,
27                                                  float disk_r,
28                                                  float r,
29                                                  bool all)
30 {
31         /* this is the veach one-sample model with balance heuristic, some pdf
32          * factors drop out when using balance heuristic weighting */
33         float3 eval_sum = make_float3(0.0f, 0.0f, 0.0f);
34         float pdf_sum = 0.0f;
35         float sample_weight_inv = 0.0f;
36
37         if(!all) {
38                 float sample_weight_sum = 0.0f;
39
40                 for(int i = 0; i < sd->num_closure; i++) {
41                         sc = &sd->closure[i];
42
43                         if(CLOSURE_IS_DISK_BSSRDF(sc->type)) {
44                                 sample_weight_sum += sc->sample_weight;
45                         }
46                 }
47
48                 sample_weight_inv = 1.0f/sample_weight_sum;
49         }
50
51         for(int i = 0; i < sd->num_closure; i++) {
52                 sc = &sd->closure[i];
53                 
54                 if(CLOSURE_IS_DISK_BSSRDF(sc->type)) {
55                         /* in case of branched path integrate we sample all bssrdf's once,
56                          * for path trace we pick one, so adjust pdf for that */
57                         float sample_weight = (all)? 1.0f: sc->sample_weight * sample_weight_inv;
58
59                         /* compute pdf */
60                         float3 eval = bssrdf_eval(sc, r);
61                         float pdf = bssrdf_pdf(sc, disk_r);
62
63                         eval_sum += sc->weight * eval;
64                         pdf_sum += sample_weight * pdf;
65                 }
66         }
67
68         return (pdf_sum > 0.0f)? eval_sum / pdf_sum : make_float3(0.0f, 0.0f, 0.0f);
69 }
70
71 /* replace closures with a single diffuse bsdf closure after scatter step */
72 ccl_device void subsurface_scatter_setup_diffuse_bsdf(KernelGlobals *kg, ShaderData *sd, const ShaderClosure *sc, float3 weight, bool hit, float3 N)
73 {
74         sd->flag &= ~SD_CLOSURE_FLAGS;
75         sd->num_closure = 0;
76         sd->num_closure_left = kernel_data.integrator.max_closures;
77
78         if(hit) {
79                 Bssrdf *bssrdf = (Bssrdf *)sc;
80 #ifdef __PRINCIPLED__
81                 if(bssrdf->type == CLOSURE_BSSRDF_PRINCIPLED_ID ||
82                    bssrdf->type == CLOSURE_BSSRDF_PRINCIPLED_RANDOM_WALK_ID)
83                 {
84                         PrincipledDiffuseBsdf *bsdf = (PrincipledDiffuseBsdf*)bsdf_alloc(sd, sizeof(PrincipledDiffuseBsdf), weight);
85
86                         if(bsdf) {
87                                 bsdf->N = N;
88                                 bsdf->roughness = bssrdf->roughness;
89                                 sd->flag |= bsdf_principled_diffuse_setup(bsdf);
90
91                                 /* replace CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID with this special ID so render passes
92                                  * can recognize it as not being a regular Disney principled diffuse closure */
93                                 bsdf->type = CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID;
94                         }
95                 }
96                 else if(CLOSURE_IS_BSDF_BSSRDF(bssrdf->type) ||
97                         CLOSURE_IS_BSSRDF(bssrdf->type))
98 #endif  /* __PRINCIPLED__ */
99                 {
100                         DiffuseBsdf *bsdf = (DiffuseBsdf*)bsdf_alloc(sd, sizeof(DiffuseBsdf), weight);
101
102                         if(bsdf) {
103                                 bsdf->N = N;
104                                 sd->flag |= bsdf_diffuse_setup(bsdf);
105
106                                 /* replace CLOSURE_BSDF_DIFFUSE_ID with this special ID so render passes
107                                  * can recognize it as not being a regular diffuse closure */
108                                 bsdf->type = CLOSURE_BSDF_BSSRDF_ID;
109                         }
110                 }
111         }
112 }
113
114 /* optionally do blurring of color and/or bump mapping, at the cost of a shader evaluation */
115 ccl_device float3 subsurface_color_pow(float3 color, float exponent)
116 {
117         color = max(color, make_float3(0.0f, 0.0f, 0.0f));
118
119         if(exponent == 1.0f) {
120                 /* nothing to do */
121         }
122         else if(exponent == 0.5f) {
123                 color.x = sqrtf(color.x);
124                 color.y = sqrtf(color.y);
125                 color.z = sqrtf(color.z);
126         }
127         else {
128                 color.x = powf(color.x, exponent);
129                 color.y = powf(color.y, exponent);
130                 color.z = powf(color.z, exponent);
131         }
132
133         return color;
134 }
135
136 ccl_device void subsurface_color_bump_blur(KernelGlobals *kg,
137                                            ShaderData *sd,
138                                            ccl_addr_space PathState *state,
139                                            float3 *eval,
140                                            float3 *N)
141 {
142         /* average color and texture blur at outgoing point */
143         float texture_blur;
144         float3 out_color = shader_bssrdf_sum(sd, NULL, &texture_blur);
145
146         /* do we have bump mapping? */
147         bool bump = (sd->flag & SD_HAS_BSSRDF_BUMP) != 0;
148
149         if(bump || texture_blur > 0.0f) {
150                 /* average color and normal at incoming point */
151                 shader_eval_surface(kg, sd, state, state->flag, kernel_data.integrator.max_closures);
152                 float3 in_color = shader_bssrdf_sum(sd, (bump)? N: NULL, NULL);
153
154                 /* we simply divide out the average color and multiply with the average
155                  * of the other one. we could try to do this per closure but it's quite
156                  * tricky to match closures between shader evaluations, their number and
157                  * order may change, this is simpler */
158                 if(texture_blur > 0.0f) {
159                         out_color = subsurface_color_pow(out_color, texture_blur);
160                         in_color = subsurface_color_pow(in_color, texture_blur);
161
162                         *eval *= safe_divide_color(in_color, out_color);
163                 }
164         }
165 }
166
167 /* Subsurface scattering step, from a point on the surface to other
168  * nearby points on the same object.
169  */
170 ccl_device_inline int subsurface_scatter_disk(
171         KernelGlobals *kg,
172         LocalIntersection *ss_isect,
173         ShaderData *sd,
174         const ShaderClosure *sc,
175         uint *lcg_state,
176         float disk_u,
177         float disk_v,
178         bool all)
179 {
180         /* pick random axis in local frame and point on disk */
181         float3 disk_N, disk_T, disk_B;
182         float pick_pdf_N, pick_pdf_T, pick_pdf_B;
183
184         disk_N = sd->Ng;
185         make_orthonormals(disk_N, &disk_T, &disk_B);
186
187         if(disk_v < 0.5f) {
188                 pick_pdf_N = 0.5f;
189                 pick_pdf_T = 0.25f;
190                 pick_pdf_B = 0.25f;
191                 disk_v *= 2.0f;
192         }
193         else if(disk_v < 0.75f) {
194                 float3 tmp = disk_N;
195                 disk_N = disk_T;
196                 disk_T = tmp;
197                 pick_pdf_N = 0.25f;
198                 pick_pdf_T = 0.5f;
199                 pick_pdf_B = 0.25f;
200                 disk_v = (disk_v - 0.5f)*4.0f;
201         }
202         else {
203                 float3 tmp = disk_N;
204                 disk_N = disk_B;
205                 disk_B = tmp;
206                 pick_pdf_N = 0.25f;
207                 pick_pdf_T = 0.25f;
208                 pick_pdf_B = 0.5f;
209                 disk_v = (disk_v - 0.75f)*4.0f;
210         }
211
212         /* sample point on disk */
213         float phi = M_2PI_F * disk_v;
214         float disk_height, disk_r;
215
216         bssrdf_sample(sc, disk_u, &disk_r, &disk_height);
217
218         float3 disk_P = (disk_r*cosf(phi)) * disk_T + (disk_r*sinf(phi)) * disk_B;
219
220         /* create ray */
221 #ifdef __SPLIT_KERNEL__
222         Ray ray_object = ss_isect->ray;
223         Ray *ray = &ray_object;
224 #else
225         Ray *ray = &ss_isect->ray;
226 #endif
227         ray->P = sd->P + disk_N*disk_height + disk_P;
228         ray->D = -disk_N;
229         ray->t = 2.0f*disk_height;
230         ray->dP = sd->dP;
231         ray->dD = differential3_zero();
232         ray->time = sd->time;
233
234         /* intersect with the same object. if multiple intersections are found it
235          * will use at most BSSRDF_MAX_HITS hits, a random subset of all hits */
236         scene_intersect_local(kg,
237                               *ray,
238                               ss_isect,
239                               sd->object,
240                               lcg_state,
241                               BSSRDF_MAX_HITS);
242         int num_eval_hits = min(ss_isect->num_hits, BSSRDF_MAX_HITS);
243
244         for(int hit = 0; hit < num_eval_hits; hit++) {
245                 /* Quickly retrieve P and Ng without setting up ShaderData. */
246                 float3 hit_P;
247                 if(sd->type & PRIMITIVE_TRIANGLE) {
248                         hit_P = triangle_refine_local(kg,
249                                                       sd,
250                                                       &ss_isect->hits[hit],
251                                                       ray);
252                 }
253 #ifdef __OBJECT_MOTION__
254                 else  if(sd->type & PRIMITIVE_MOTION_TRIANGLE) {
255                         float3 verts[3];
256                         motion_triangle_vertices(
257                                 kg,
258                                 sd->object,
259                                 kernel_tex_fetch(__prim_index, ss_isect->hits[hit].prim),
260                                 sd->time,
261                                 verts);
262                         hit_P = motion_triangle_refine_local(kg,
263                                                              sd,
264                                                              &ss_isect->hits[hit],
265                                                              ray,
266                                                              verts);
267                 }
268 #endif  /* __OBJECT_MOTION__ */
269                 else {
270                         ss_isect->weight[hit] = make_float3(0.0f, 0.0f, 0.0f);
271                         continue;
272                 }
273
274                 float3 hit_Ng = ss_isect->Ng[hit];
275                 if(ss_isect->hits[hit].object != OBJECT_NONE) {
276                         object_normal_transform(kg, sd, &hit_Ng);
277                 }
278
279                 /* Probability densities for local frame axes. */
280                 float pdf_N = pick_pdf_N * fabsf(dot(disk_N, hit_Ng));
281                 float pdf_T = pick_pdf_T * fabsf(dot(disk_T, hit_Ng));
282                 float pdf_B = pick_pdf_B * fabsf(dot(disk_B, hit_Ng));
283
284                 /* Multiple importance sample between 3 axes, power heuristic
285                  * found to be slightly better than balance heuristic. pdf_N
286                  * in the MIS weight and denominator cancelled out. */
287                 float w = pdf_N / (sqr(pdf_N) + sqr(pdf_T) + sqr(pdf_B));
288                 if(ss_isect->num_hits > BSSRDF_MAX_HITS) {
289                         w *= ss_isect->num_hits/(float)BSSRDF_MAX_HITS;
290                 }
291
292                 /* Real distance to sampled point. */
293                 float r = len(hit_P - sd->P);
294
295                 /* Evaluate profiles. */
296                 float3 eval = subsurface_scatter_eval(sd, sc, disk_r, r, all) * w;
297
298                 ss_isect->weight[hit] = eval;
299         }
300
301 #ifdef __SPLIT_KERNEL__
302         ss_isect->ray = *ray;
303 #endif
304
305         return num_eval_hits;
306 }
307
308 ccl_device_noinline void subsurface_scatter_multi_setup(
309         KernelGlobals *kg,
310         LocalIntersection* ss_isect,
311         int hit,
312         ShaderData *sd,
313         ccl_addr_space PathState *state,
314         const ShaderClosure *sc)
315 {
316 #ifdef __SPLIT_KERNEL__
317         Ray ray_object = ss_isect->ray;
318         Ray *ray = &ray_object;
319 #else
320         Ray *ray = &ss_isect->ray;
321 #endif
322
323         /* Workaround for AMD GPU OpenCL compiler. Most probably cache bypass issue. */
324 #if defined(__SPLIT_KERNEL__) && defined(__KERNEL_OPENCL_AMD__) && defined(__KERNEL_GPU__)
325         kernel_split_params.dummy_sd_flag = sd->flag;
326 #endif
327
328         /* Setup new shading point. */
329         shader_setup_from_subsurface(kg, sd, &ss_isect->hits[hit], ray);
330
331         /* Optionally blur colors and bump mapping. */
332         float3 weight = ss_isect->weight[hit];
333         float3 N = sd->N;
334         subsurface_color_bump_blur(kg, sd, state, &weight, &N);
335
336         /* Setup diffuse BSDF. */
337         subsurface_scatter_setup_diffuse_bsdf(kg, sd, sc, weight, true, N);
338 }
339
340 /* subsurface scattering step, from a point on the surface to another nearby point on the same object */
341 ccl_device void subsurface_scatter_step(KernelGlobals *kg, ShaderData *sd, ccl_addr_space PathState *state,
342         const ShaderClosure *sc, uint *lcg_state, float disk_u, float disk_v, bool all)
343 {
344         float3 eval = make_float3(0.0f, 0.0f, 0.0f);
345
346         /* pick random axis in local frame and point on disk */
347         float3 disk_N, disk_T, disk_B;
348         float pick_pdf_N, pick_pdf_T, pick_pdf_B;
349
350         disk_N = sd->Ng;
351         make_orthonormals(disk_N, &disk_T, &disk_B);
352
353         if(disk_v < 0.5f) {
354                 pick_pdf_N = 0.5f;
355                 pick_pdf_T = 0.25f;
356                 pick_pdf_B = 0.25f;
357                 disk_v *= 2.0f;
358         }
359         else if(disk_v < 0.75f) {
360                 float3 tmp = disk_N;
361                 disk_N = disk_T;
362                 disk_T = tmp;
363                 pick_pdf_N = 0.25f;
364                 pick_pdf_T = 0.5f;
365                 pick_pdf_B = 0.25f;
366                 disk_v = (disk_v - 0.5f)*4.0f;
367         }
368         else {
369                 float3 tmp = disk_N;
370                 disk_N = disk_B;
371                 disk_B = tmp;
372                 pick_pdf_N = 0.25f;
373                 pick_pdf_T = 0.25f;
374                 pick_pdf_B = 0.5f;
375                 disk_v = (disk_v - 0.75f)*4.0f;
376         }
377
378         /* sample point on disk */
379         float phi = M_2PI_F * disk_v;
380         float disk_height, disk_r;
381
382         bssrdf_sample(sc, disk_u, &disk_r, &disk_height);
383
384         float3 disk_P = (disk_r*cosf(phi)) * disk_T + (disk_r*sinf(phi)) * disk_B;
385
386         /* create ray */
387         Ray ray;
388         ray.P = sd->P + disk_N*disk_height + disk_P;
389         ray.D = -disk_N;
390         ray.t = 2.0f*disk_height;
391         ray.dP = sd->dP;
392         ray.dD = differential3_zero();
393         ray.time = sd->time;
394
395         /* intersect with the same object. if multiple intersections are
396          * found it will randomly pick one of them */
397         LocalIntersection ss_isect;
398         scene_intersect_local(kg, ray, &ss_isect, sd->object, lcg_state, 1);
399
400         /* evaluate bssrdf */
401         if(ss_isect.num_hits > 0) {
402                 float3 origP = sd->P;
403
404                 /* Workaround for AMD GPU OpenCL compiler. Most probably cache bypass issue. */
405 #if defined(__SPLIT_KERNEL__) && defined(__KERNEL_OPENCL_AMD__) && defined(__KERNEL_GPU__)
406                 kernel_split_params.dummy_sd_flag = sd->flag;
407 #endif
408                 /* setup new shading point */
409                 shader_setup_from_subsurface(kg, sd, &ss_isect.hits[0], &ray);
410
411                 /* Probability densities for local frame axes. */
412                 float pdf_N = pick_pdf_N * fabsf(dot(disk_N, sd->Ng));
413                 float pdf_T = pick_pdf_T * fabsf(dot(disk_T, sd->Ng));
414                 float pdf_B = pick_pdf_B * fabsf(dot(disk_B, sd->Ng));
415
416                 /* Multiple importance sample between 3 axes, power heuristic
417                  * found to be slightly better than balance heuristic. pdf_N
418                  * in the MIS weight and denominator cancelled out. */
419                 float w = pdf_N / (sqr(pdf_N) + sqr(pdf_T) + sqr(pdf_B));
420                 w *= ss_isect.num_hits;
421
422                 /* Real distance to sampled point. */
423                 float r = len(sd->P - origP);
424
425                 /* Evaluate profiles. */
426                 eval = subsurface_scatter_eval(sd, sc, disk_r, r, all) * w;
427         }
428
429         /* optionally blur colors and bump mapping */
430         float3 N = sd->N;
431         subsurface_color_bump_blur(kg, sd, state, &eval, &N);
432
433         /* setup diffuse bsdf */
434         subsurface_scatter_setup_diffuse_bsdf(kg, sd, sc, eval, (ss_isect.num_hits > 0), N);
435 }
436
437 /* Random walk subsurface scattering.
438  *
439  * "Practical and Controllable Subsurface Scattering for Production Path
440  *  Tracing". Matt Jen-Yuan Chiang, Peter Kutz, Brent Burley. SIGGRAPH 2016. */
441
442 ccl_device void subsurface_random_walk_remap(
443         const float A,
444         const float d,
445         float *sigma_t,
446         float *sigma_s)
447 {
448         /* Compute attenuation and scattering coefficients from albedo. */
449         const float a = 1.0f - expf(A * (-5.09406f + A * (2.61188f - A * 4.31805f)));
450         const float s = 1.9f - A + 3.5f * sqr(A - 0.8f);
451
452         *sigma_t = 1.0f / fmaxf(d * s, 1e-16f);
453         *sigma_s = *sigma_t * a;
454 }
455
456 ccl_device void subsurface_random_walk_coefficients(
457         const ShaderClosure *sc,
458         float3 *sigma_t,
459         float3 *sigma_s,
460         float3 *weight)
461 {
462         const Bssrdf *bssrdf = (const Bssrdf*)sc;
463         const float3 A = bssrdf->albedo;
464         const float3 d = bssrdf->radius;
465         float sigma_t_x, sigma_t_y, sigma_t_z;
466         float sigma_s_x, sigma_s_y, sigma_s_z;
467
468         subsurface_random_walk_remap(A.x, d.x, &sigma_t_x, &sigma_s_x);
469         subsurface_random_walk_remap(A.y, d.y, &sigma_t_y, &sigma_s_y);
470         subsurface_random_walk_remap(A.z, d.z, &sigma_t_z, &sigma_s_z);
471
472         *sigma_t = make_float3(sigma_t_x, sigma_t_y, sigma_t_z);
473         *sigma_s = make_float3(sigma_s_x, sigma_s_y, sigma_s_z);
474
475         /* Closure mixing and Fresnel weights separate from albedo. */
476         *weight = safe_divide_color(bssrdf->weight, A);
477 }
478
479 ccl_device_noinline bool subsurface_random_walk(
480         KernelGlobals *kg,
481         LocalIntersection *ss_isect,
482         ShaderData *sd,
483         ccl_addr_space PathState *state,
484         const ShaderClosure *sc,
485         const float bssrdf_u,
486         const float bssrdf_v)
487 {
488         /* Sample diffuse surface scatter into the object. */
489         float3 D;
490         float pdf;
491         sample_cos_hemisphere(-sd->N, bssrdf_u, bssrdf_v, &D, &pdf);
492         if(dot(-sd->Ng, D) <= 0.0f) {
493                 return 0;
494         }
495
496         /* Convert subsurface to volume coefficients. */
497         float3 sigma_t, sigma_s;
498         float3 throughput = make_float3(1.0f, 1.0f, 1.0f);
499         subsurface_random_walk_coefficients(sc, &sigma_t, &sigma_s, &throughput);
500
501         /* Setup ray. */
502 #ifdef __SPLIT_KERNEL__
503         Ray ray_object = ss_isect->ray;
504         Ray *ray = &ray_object;
505 #else
506         Ray *ray = &ss_isect->ray;
507 #endif
508         ray->P = ray_offset(sd->P, -sd->Ng);
509         ray->D = D;
510         ray->t = FLT_MAX;
511         ray->time = sd->time;
512
513         /* Modify state for RNGs, decorrelated from other paths. */
514         uint prev_rng_offset = state->rng_offset;
515         uint prev_rng_hash = state->rng_hash;
516         state->rng_hash = cmj_hash(state->rng_hash + state->rng_offset, 0xdeadbeef);
517
518         /* Random walk until we hit the surface again. */
519         bool hit = false;
520
521         for(int bounce = 0; bounce < BSSRDF_MAX_BOUNCES; bounce++) {
522                 /* Advance random number offset. */
523                 state->rng_offset += PRNG_BOUNCE_NUM;
524
525                 if(bounce > 0) {
526                         /* Sample scattering direction. */
527                         const float anisotropy = 0.0f;
528                         float scatter_u, scatter_v;
529                         path_state_rng_2D(kg, state, PRNG_BSDF_U, &scatter_u, &scatter_v);
530                         ray->D = henyey_greenstrein_sample(ray->D, anisotropy, scatter_u, scatter_v, NULL);
531                 }
532
533                 /* Sample color channel, use MIS with balance heuristic. */
534                 float rphase = path_state_rng_1D(kg, state, PRNG_PHASE_CHANNEL);
535                 float3 albedo = safe_divide_color(sigma_s, sigma_t);
536                 float3 channel_pdf;
537                 int channel = kernel_volume_sample_channel(albedo, throughput, rphase, &channel_pdf);
538
539                 /* Distance sampling. */
540                 float rdist = path_state_rng_1D(kg, state, PRNG_SCATTER_DISTANCE);
541                 float sample_sigma_t = kernel_volume_channel_get(sigma_t, channel);
542                 float t = -logf(1.0f - rdist)/sample_sigma_t;
543
544                 ray->t = t;
545                 scene_intersect_local(kg, *ray, ss_isect, sd->object, NULL, 1);
546                 hit = (ss_isect->num_hits > 0);
547
548                 if(hit) {
549                         /* Compute world space distance to surface hit. */
550                         float3 D = ray->D;
551                         object_inverse_dir_transform(kg, sd, &D);
552                         D = normalize(D) * ss_isect->hits[0].t;
553                         object_dir_transform(kg, sd, &D);
554                         t = len(D);
555                 }
556
557                 /* Advance to new scatter location. */
558                 ray->P += t * ray->D;
559
560                 /* Update throughput. */
561                 float3 transmittance = volume_color_transmittance(sigma_t, t);
562                 float pdf = dot(channel_pdf, (hit)? transmittance: sigma_t * transmittance);
563                 throughput *= ((hit)? transmittance: sigma_s * transmittance) / pdf;
564
565                 if(hit) {
566                         /* If we hit the surface, we are done. */
567                         break;
568                 }
569
570                 /* Russian roulette. */
571                 float terminate = path_state_rng_1D(kg, state, PRNG_TERMINATE);
572                 float probability = min(max3(fabs(throughput)), 1.0f);
573                 if(terminate >= probability) {
574                         break;
575                 }
576                 throughput /= probability;
577         }
578
579         kernel_assert(isfinite_safe(throughput.x) &&
580                       isfinite_safe(throughput.y) &&
581                       isfinite_safe(throughput.z));
582
583         state->rng_offset = prev_rng_offset;
584         state->rng_hash = prev_rng_hash;
585
586         /* Return number of hits in ss_isect. */
587         if(!hit) {
588                 return 0;
589         }
590
591         /* TODO: gain back performance lost from merging with disk BSSRDF. We
592          * only need to return on hit so this indirect ray push/pop overhead
593          * is not actually needed, but it does keep the code simpler. */
594         ss_isect->weight[0] = throughput;
595 #ifdef __SPLIT_KERNEL__
596         ss_isect->ray = *ray;
597 #endif
598
599         return 1;
600 }
601
602 ccl_device_inline int subsurface_scatter_multi_intersect(
603         KernelGlobals *kg,
604         LocalIntersection *ss_isect,
605         ShaderData *sd,
606         ccl_addr_space PathState *state,
607         const ShaderClosure *sc,
608         uint *lcg_state,
609         float bssrdf_u,
610         float bssrdf_v,
611         bool all)
612 {
613         if(CLOSURE_IS_DISK_BSSRDF(sc->type)) {
614                 return subsurface_scatter_disk(kg,
615                                                ss_isect,
616                                                sd,
617                                                sc,
618                                                lcg_state,
619                                                bssrdf_u,
620                                                bssrdf_v,
621                                                all);
622         }
623         else {
624                 return subsurface_random_walk(kg,
625                                               ss_isect,
626                                               sd,
627                                               state,
628                                               sc,
629                                               bssrdf_u,
630                                               bssrdf_v);
631         }
632 }
633
634 CCL_NAMESPACE_END
635