d58960cae4eb36c75c54d8f60ff7d58460be5f35
[blender.git] / intern / cycles / kernel / kernel_path_branched.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 #ifdef __BRANCHED_PATH__
20
21 ccl_device_inline void kernel_branched_path_ao(KernelGlobals *kg,
22                                                ShaderData *sd,
23                                                ShaderData *emission_sd,
24                                                PathRadiance *L,
25                                                PathState *state,
26                                                RNG *rng,
27                                                float3 throughput)
28 {
29         int num_samples = kernel_data.integrator.ao_samples;
30         float num_samples_inv = 1.0f/num_samples;
31         float ao_factor = kernel_data.background.ao_factor;
32         float3 ao_N;
33         float3 ao_bsdf = shader_bsdf_ao(kg, sd, ao_factor, &ao_N);
34         float3 ao_alpha = shader_bsdf_alpha(kg, sd);
35
36         for(int j = 0; j < num_samples; j++) {
37                 float bsdf_u, bsdf_v;
38                 path_branched_rng_2D(kg, rng, state, j, num_samples, PRNG_BSDF_U, &bsdf_u, &bsdf_v);
39
40                 float3 ao_D;
41                 float ao_pdf;
42
43                 sample_cos_hemisphere(ao_N, bsdf_u, bsdf_v, &ao_D, &ao_pdf);
44
45                 if(dot(sd->Ng, ao_D) > 0.0f && ao_pdf != 0.0f) {
46                         Ray light_ray;
47                         float3 ao_shadow;
48
49                         light_ray.P = ray_offset(sd->P, sd->Ng);
50                         light_ray.D = ao_D;
51                         light_ray.t = kernel_data.background.ao_distance;
52 #ifdef __OBJECT_MOTION__
53                         light_ray.time = sd->time;
54 #endif  /* __OBJECT_MOTION__ */
55                         light_ray.dP = sd->dP;
56                         light_ray.dD = differential3_zero();
57
58                         if(!shadow_blocked(kg, emission_sd, state, &light_ray, &ao_shadow))
59                                 path_radiance_accum_ao(L, throughput*num_samples_inv, ao_alpha, ao_bsdf, ao_shadow, state->bounce);
60                 }
61         }
62 }
63
64
65 /* bounce off surface and integrate indirect light */
66 ccl_device_noinline void kernel_branched_path_surface_indirect_light(KernelGlobals *kg,
67         RNG *rng, ShaderData *sd, ShaderData *indirect_sd, ShaderData *emission_sd,
68         float3 throughput, float num_samples_adjust, PathState *state, PathRadiance *L)
69 {
70         for(int i = 0; i < sd->num_closure; i++) {
71                 const ShaderClosure *sc = &sd->closure[i];
72
73                 if(!CLOSURE_IS_BSDF(sc->type))
74                         continue;
75                 /* transparency is not handled here, but in outer loop */
76                 if(sc->type == CLOSURE_BSDF_TRANSPARENT_ID)
77                         continue;
78
79                 int num_samples;
80
81                 if(CLOSURE_IS_BSDF_DIFFUSE(sc->type))
82                         num_samples = kernel_data.integrator.diffuse_samples;
83                 else if(CLOSURE_IS_BSDF_BSSRDF(sc->type))
84                         num_samples = 1;
85                 else if(CLOSURE_IS_BSDF_GLOSSY(sc->type))
86                         num_samples = kernel_data.integrator.glossy_samples;
87                 else
88                         num_samples = kernel_data.integrator.transmission_samples;
89
90                 num_samples = ceil_to_int(num_samples_adjust*num_samples);
91
92                 float num_samples_inv = num_samples_adjust/num_samples;
93                 RNG bsdf_rng = cmj_hash(*rng, i);
94
95                 for(int j = 0; j < num_samples; j++) {
96                         PathState ps = *state;
97                         float3 tp = throughput;
98                         Ray bsdf_ray;
99
100                         if(!kernel_branched_path_surface_bounce(kg,
101                                                                 &bsdf_rng,
102                                                                 sd,
103                                                                 sc,
104                                                                 j,
105                                                                 num_samples,
106                                                                 &tp,
107                                                                 &ps,
108                                                                 L,
109                                                                 &bsdf_ray))
110                         {
111                                 continue;
112                         }
113
114                         kernel_path_indirect(kg,
115                                              indirect_sd,
116                                              emission_sd,
117                                              rng,
118                                              &bsdf_ray,
119                                              tp*num_samples_inv,
120                                              num_samples,
121                                              &ps,
122                                              L);
123
124                         /* for render passes, sum and reset indirect light pass variables
125                          * for the next samples */
126                         path_radiance_sum_indirect(L);
127                         path_radiance_reset_indirect(L);
128                 }
129         }
130 }
131
132 #ifdef __SUBSURFACE__
133 ccl_device void kernel_branched_path_subsurface_scatter(KernelGlobals *kg,
134                                                         ShaderData *sd,
135                                                         ShaderData *indirect_sd,
136                                                         ShaderData *emission_sd,
137                                                         PathRadiance *L,
138                                                         PathState *state,
139                                                         RNG *rng,
140                                                         Ray *ray,
141                                                         float3 throughput)
142 {
143         for(int i = 0; i < sd->num_closure; i++) {
144                 ShaderClosure *sc = &sd->closure[i];
145
146                 if(!CLOSURE_IS_BSSRDF(sc->type))
147                         continue;
148
149                 /* set up random number generator */
150                 uint lcg_state = lcg_state_init(rng, state, 0x68bc21eb);
151                 int num_samples = kernel_data.integrator.subsurface_samples;
152                 float num_samples_inv = 1.0f/num_samples;
153                 RNG bssrdf_rng = cmj_hash(*rng, i);
154
155                 /* do subsurface scatter step with copy of shader data, this will
156                  * replace the BSSRDF with a diffuse BSDF closure */
157                 for(int j = 0; j < num_samples; j++) {
158                         SubsurfaceIntersection ss_isect;
159                         float bssrdf_u, bssrdf_v;
160                         path_branched_rng_2D(kg, &bssrdf_rng, state, j, num_samples, PRNG_BSDF_U, &bssrdf_u, &bssrdf_v);
161                         int num_hits = subsurface_scatter_multi_intersect(kg,
162                                                                           &ss_isect,
163                                                                           sd,
164                                                                           sc,
165                                                                           &lcg_state,
166                                                                           bssrdf_u, bssrdf_v,
167                                                                           true);
168 #ifdef __VOLUME__
169                         Ray volume_ray = *ray;
170                         bool need_update_volume_stack =
171                                 kernel_data.integrator.use_volumes &&
172                                 sd->object_flag & SD_OBJECT_INTERSECTS_VOLUME;
173 #endif  /* __VOLUME__ */
174
175                         /* compute lighting with the BSDF closure */
176                         for(int hit = 0; hit < num_hits; hit++) {
177                                 ShaderData bssrdf_sd = *sd;
178                                 subsurface_scatter_multi_setup(kg,
179                                                                &ss_isect,
180                                                                hit,
181                                                                &bssrdf_sd,
182                                                                state,
183                                                                state->flag,
184                                                                sc,
185                                                                true);
186
187                                 PathState hit_state = *state;
188
189                                 path_state_branch(&hit_state, j, num_samples);
190
191 #ifdef __VOLUME__
192                                 if(need_update_volume_stack) {
193                                         /* Setup ray from previous surface point to the new one. */
194                                         float3 P = ray_offset(bssrdf_sd.P, -bssrdf_sd.Ng);
195                                         volume_ray.D = normalize_len(P - volume_ray.P,
196                                                                      &volume_ray.t);
197
198                                         kernel_volume_stack_update_for_subsurface(
199                                             kg,
200                                             emission_sd,
201                                             &volume_ray,
202                                             hit_state.volume_stack);
203                                 }
204 #endif  /* __VOLUME__ */
205
206 #ifdef __EMISSION__
207                                 /* direct light */
208                                 if(kernel_data.integrator.use_direct_light) {
209                                         int all = kernel_data.integrator.sample_all_lights_direct;
210                                         kernel_branched_path_surface_connect_light(
211                                                 kg,
212                                                 rng,
213                                                 &bssrdf_sd,
214                                                 emission_sd,
215                                                 &hit_state,
216                                                 throughput,
217                                                 num_samples_inv,
218                                                 L,
219                                                 all);
220                                 }
221 #endif  /* __EMISSION__ */
222
223                                 /* indirect light */
224                                 kernel_branched_path_surface_indirect_light(
225                                         kg,
226                                         rng,
227                                         &bssrdf_sd,
228                                         indirect_sd,
229                                         emission_sd,
230                                         throughput,
231                                         num_samples_inv,
232                                         &hit_state,
233                                         L);
234                         }
235                 }
236         }
237 }
238 #endif  /* __SUBSURFACE__ */
239
240 ccl_device float4 kernel_branched_path_integrate(KernelGlobals *kg, RNG *rng, int sample, Ray ray, ccl_global float *buffer)
241 {
242         /* initialize */
243         PathRadiance L;
244         float3 throughput = make_float3(1.0f, 1.0f, 1.0f);
245         float L_transparent = 0.0f;
246
247         path_radiance_init(&L, kernel_data.film.use_light_pass);
248
249         /* shader data memory used for both volumes and surfaces, saves stack space */
250         ShaderData sd;
251         /* shader data used by emission, shadows, volume stacks, indirect path */
252         ShaderData emission_sd, indirect_sd;
253
254         PathState state;
255         path_state_init(kg, &emission_sd, &state, rng, sample, &ray);
256
257 #ifdef __KERNEL_DEBUG__
258         DebugData debug_data;
259         debug_data_init(&debug_data);
260 #endif  /* __KERNEL_DEBUG__ */
261
262         /* Main Loop
263          * Here we only handle transparency intersections from the camera ray.
264          * Indirect bounces are handled in kernel_branched_path_surface_indirect_light().
265          */
266         for(;;) {
267                 /* intersect scene */
268                 Intersection isect;
269                 uint visibility = path_state_ray_visibility(kg, &state);
270
271 #ifdef __HAIR__
272                 float difl = 0.0f, extmax = 0.0f;
273                 uint lcg_state = 0;
274
275                 if(kernel_data.bvh.have_curves) {
276                         if(kernel_data.cam.resolution == 1) {
277                                 float3 pixdiff = ray.dD.dx + ray.dD.dy;
278                                 /*pixdiff = pixdiff - dot(pixdiff, ray.D)*ray.D;*/
279                                 difl = kernel_data.curve.minimum_width * len(pixdiff) * 0.5f;
280                         }
281
282                         extmax = kernel_data.curve.maximum_width;
283                         lcg_state = lcg_state_init(rng, &state, 0x51633e2d);
284                 }
285
286                 bool hit = scene_intersect(kg, ray, visibility, &isect, &lcg_state, difl, extmax);
287 #else
288                 bool hit = scene_intersect(kg, ray, visibility, &isect, NULL, 0.0f, 0.0f);
289 #endif  /* __HAIR__ */
290
291 #ifdef __KERNEL_DEBUG__
292                 debug_data.num_bvh_traversed_nodes += isect.num_traversed_nodes;
293                 debug_data.num_bvh_traversed_instances += isect.num_traversed_instances;
294                 debug_data.num_bvh_intersections += isect.num_intersections;
295                 debug_data.num_ray_bounces++;
296 #endif  /* __KERNEL_DEBUG__ */
297
298 #ifdef __VOLUME__
299                 /* Sanitize volume stack. */
300                 if(!hit) {
301                         kernel_volume_clean_stack(kg, state.volume_stack);
302                 }
303                 /* volume attenuation, emission, scatter */
304                 if(state.volume_stack[0].shader != SHADER_NONE) {
305                         Ray volume_ray = ray;
306                         volume_ray.t = (hit)? isect.t: FLT_MAX;
307                         
308                         bool heterogeneous = volume_stack_is_heterogeneous(kg, state.volume_stack);
309
310 #ifdef __VOLUME_DECOUPLED__
311                         /* decoupled ray marching only supported on CPU */
312
313                         /* cache steps along volume for repeated sampling */
314                         VolumeSegment volume_segment;
315
316                         shader_setup_from_volume(kg, &sd, &volume_ray);
317                         kernel_volume_decoupled_record(kg, &state,
318                                 &volume_ray, &sd, &volume_segment, heterogeneous);
319
320                         /* direct light sampling */
321                         if(volume_segment.closure_flag & SD_SCATTER) {
322                                 volume_segment.sampling_method = volume_stack_sampling_method(kg, state.volume_stack);
323
324                                 int all = kernel_data.integrator.sample_all_lights_direct;
325
326                                 kernel_branched_path_volume_connect_light(kg, rng, &sd,
327                                         &emission_sd, throughput, &state, &L, all,
328                                         &volume_ray, &volume_segment);
329
330                                 /* indirect light sampling */
331                                 int num_samples = kernel_data.integrator.volume_samples;
332                                 float num_samples_inv = 1.0f/num_samples;
333
334                                 for(int j = 0; j < num_samples; j++) {
335                                         /* workaround to fix correlation bug in T38710, can find better solution
336                                          * in random number generator later, for now this is done here to not impact
337                                          * performance of rendering without volumes */
338                                         RNG tmp_rng = cmj_hash(*rng, state.rng_offset);
339
340                                         PathState ps = state;
341                                         Ray pray = ray;
342                                         float3 tp = throughput;
343
344                                         /* branch RNG state */
345                                         path_state_branch(&ps, j, num_samples);
346
347                                         /* scatter sample. if we use distance sampling and take just one
348                                          * sample for direct and indirect light, we could share this
349                                          * computation, but makes code a bit complex */
350                                         float rphase = path_state_rng_1D_for_decision(kg, &tmp_rng, &ps, PRNG_PHASE);
351                                         float rscatter = path_state_rng_1D_for_decision(kg, &tmp_rng, &ps, PRNG_SCATTER_DISTANCE);
352
353                                         VolumeIntegrateResult result = kernel_volume_decoupled_scatter(kg,
354                                                 &ps, &pray, &sd, &tp, rphase, rscatter, &volume_segment, NULL, false);
355
356                                         (void)result;
357                                         kernel_assert(result == VOLUME_PATH_SCATTERED);
358
359                                         if(kernel_path_volume_bounce(kg,
360                                                                      rng,
361                                                                      &sd,
362                                                                      &tp,
363                                                                      &ps,
364                                                                      &L,
365                                                                      &pray))
366                                         {
367                                                 kernel_path_indirect(kg,
368                                                                      &indirect_sd,
369                                                                      &emission_sd,
370                                                                      rng,
371                                                                      &pray,
372                                                                      tp*num_samples_inv,
373                                                                      num_samples,
374                                                                      &ps,
375                                                                      &L);
376
377                                                 /* for render passes, sum and reset indirect light pass variables
378                                                  * for the next samples */
379                                                 path_radiance_sum_indirect(&L);
380                                                 path_radiance_reset_indirect(&L);
381                                         }
382                                 }
383                         }
384
385                         /* emission and transmittance */
386                         if(volume_segment.closure_flag & SD_EMISSION)
387                                 path_radiance_accum_emission(&L, throughput, volume_segment.accum_emission, state.bounce);
388                         throughput *= volume_segment.accum_transmittance;
389
390                         /* free cached steps */
391                         kernel_volume_decoupled_free(kg, &volume_segment);
392 #else
393                         /* GPU: no decoupled ray marching, scatter probalistically */
394                         int num_samples = kernel_data.integrator.volume_samples;
395                         float num_samples_inv = 1.0f/num_samples;
396
397                         /* todo: we should cache the shader evaluations from stepping
398                          * through the volume, for now we redo them multiple times */
399
400                         for(int j = 0; j < num_samples; j++) {
401                                 PathState ps = state;
402                                 Ray pray = ray;
403                                 float3 tp = throughput * num_samples_inv;
404
405                                 /* branch RNG state */
406                                 path_state_branch(&ps, j, num_samples);
407
408                                 VolumeIntegrateResult result = kernel_volume_integrate(
409                                         kg, &ps, &sd, &volume_ray, &L, &tp, rng, heterogeneous);
410
411 #ifdef __VOLUME_SCATTER__
412                                 if(result == VOLUME_PATH_SCATTERED) {
413                                         /* todo: support equiangular, MIS and all light sampling.
414                                          * alternatively get decoupled ray marching working on the GPU */
415                                         kernel_path_volume_connect_light(kg, rng, &sd, &emission_sd, tp, &state, &L);
416
417                                         if(kernel_path_volume_bounce(kg,
418                                                                      rng,
419                                                                      &sd,
420                                                                      &tp,
421                                                                      &ps,
422                                                                      &L,
423                                                                      &pray))
424                                         {
425                                                 kernel_path_indirect(kg,
426                                                                      &indirect_sd,
427                                                                      &emission_sd,
428                                                                      rng,
429                                                                      &pray,
430                                                                      tp,
431                                                                      num_samples,
432                                                                      &ps,
433                                                                      &L);
434
435                                                 /* for render passes, sum and reset indirect light pass variables
436                                                  * for the next samples */
437                                                 path_radiance_sum_indirect(&L);
438                                                 path_radiance_reset_indirect(&L);
439                                         }
440                                 }
441 #endif  /* __VOLUME_SCATTER__ */
442                         }
443
444                         /* todo: avoid this calculation using decoupled ray marching */
445                         kernel_volume_shadow(kg, &emission_sd, &state, &volume_ray, &throughput);
446 #endif  /* __VOLUME_DECOUPLED__ */
447                 }
448 #endif  /* __VOLUME__ */
449
450                 if(!hit) {
451                         /* eval background shader if nothing hit */
452                         if(kernel_data.background.transparent) {
453                                 L_transparent += average(throughput);
454
455 #ifdef __PASSES__
456                                 if(!(kernel_data.film.pass_flag & PASS_BACKGROUND))
457 #endif  /* __PASSES__ */
458                                         break;
459                         }
460
461 #ifdef __BACKGROUND__
462                         /* sample background shader */
463                         float3 L_background = indirect_background(kg, &emission_sd, &state, &ray);
464                         path_radiance_accum_background(&L, throughput, L_background, state.bounce);
465 #endif  /* __BACKGROUND__ */
466
467                         break;
468                 }
469
470                 /* setup shading */
471                 shader_setup_from_ray(kg, &sd, &isect, &ray);
472                 shader_eval_surface(kg, &sd, rng, &state, 0.0f, state.flag, SHADER_CONTEXT_MAIN);
473                 shader_merge_closures(&sd);
474
475                 /* holdout */
476 #ifdef __HOLDOUT__
477                 if((sd.flag & SD_HOLDOUT) || (sd.object_flag & SD_OBJECT_HOLDOUT_MASK)) {
478                         if(kernel_data.background.transparent) {
479                                 float3 holdout_weight;
480                                 if(sd.object_flag & SD_OBJECT_HOLDOUT_MASK) {
481                                         holdout_weight = make_float3(1.0f, 1.0f, 1.0f);
482                                 }
483                                 else {
484                                         holdout_weight = shader_holdout_eval(kg, &sd);
485                                 }
486                                 /* any throughput is ok, should all be identical here */
487                                 L_transparent += average(holdout_weight*throughput);
488                         }
489                         if(sd.object_flag & SD_OBJECT_HOLDOUT_MASK) {
490                                 break;
491                         }
492                 }
493 #endif  /* __HOLDOUT__ */
494
495                 /* holdout mask objects do not write data passes */
496                 kernel_write_data_passes(kg, buffer, &L, &sd, sample, &state, throughput);
497
498 #ifdef __EMISSION__
499                 /* emission */
500                 if(sd.flag & SD_EMISSION) {
501                         float3 emission = indirect_primitive_emission(kg, &sd, isect.t, state.flag, state.ray_pdf);
502                         path_radiance_accum_emission(&L, throughput, emission, state.bounce);
503                 }
504 #endif  /* __EMISSION__ */
505
506                 /* transparency termination */
507                 if(state.flag & PATH_RAY_TRANSPARENT) {
508                         /* path termination. this is a strange place to put the termination, it's
509                          * mainly due to the mixed in MIS that we use. gives too many unneeded
510                          * shader evaluations, only need emission if we are going to terminate */
511                         float probability = path_state_terminate_probability(kg, &state, throughput);
512
513                         if(probability == 0.0f) {
514                                 break;
515                         }
516                         else if(probability != 1.0f) {
517                                 float terminate = path_state_rng_1D_for_decision(kg, rng, &state, PRNG_TERMINATE);
518
519                                 if(terminate >= probability)
520                                         break;
521
522                                 throughput /= probability;
523                         }
524                 }
525
526 #ifdef __AO__
527                 /* ambient occlusion */
528                 if(kernel_data.integrator.use_ambient_occlusion || (sd.flag & SD_AO)) {
529                         kernel_branched_path_ao(kg, &sd, &emission_sd, &L, &state, rng, throughput);
530                 }
531 #endif  /* __AO__ */
532
533 #ifdef __SUBSURFACE__
534                 /* bssrdf scatter to a different location on the same object */
535                 if(sd.flag & SD_BSSRDF) {
536                         kernel_branched_path_subsurface_scatter(kg, &sd, &indirect_sd, &emission_sd,
537                                                                 &L, &state, rng, &ray, throughput);
538                 }
539 #endif  /* __SUBSURFACE__ */
540
541                 if(!(sd.flag & SD_HAS_ONLY_VOLUME)) {
542                         PathState hit_state = state;
543
544 #ifdef __EMISSION__
545                         /* direct light */
546                         if(kernel_data.integrator.use_direct_light) {
547                                 int all = kernel_data.integrator.sample_all_lights_direct;
548                                 kernel_branched_path_surface_connect_light(kg, rng,
549                                         &sd, &emission_sd, &hit_state, throughput, 1.0f, &L, all);
550                         }
551 #endif  /* __EMISSION__ */
552
553                         /* indirect light */
554                         kernel_branched_path_surface_indirect_light(kg, rng,
555                                 &sd, &indirect_sd, &emission_sd, throughput, 1.0f, &hit_state, &L);
556
557                         /* continue in case of transparency */
558                         throughput *= shader_bsdf_transparency(kg, &sd);
559
560                         if(is_zero(throughput))
561                                 break;
562                 }
563
564                 /* Update Path State */
565                 state.flag |= PATH_RAY_TRANSPARENT;
566                 state.transparent_bounce++;
567
568                 ray.P = ray_offset(sd.P, -sd.Ng);
569                 ray.t -= sd.ray_length; /* clipping works through transparent */
570
571
572 #ifdef __RAY_DIFFERENTIALS__
573                 ray.dP = sd.dP;
574                 ray.dD.dx = -sd.dI.dx;
575                 ray.dD.dy = -sd.dI.dy;
576 #endif  /* __RAY_DIFFERENTIALS__ */
577
578 #ifdef __VOLUME__
579                 /* enter/exit volume */
580                 kernel_volume_stack_enter_exit(kg, &sd, state.volume_stack);
581 #endif  /* __VOLUME__ */
582         }
583
584         float3 L_sum = path_radiance_clamp_and_sum(kg, &L);
585
586         kernel_write_light_passes(kg, buffer, &L, sample);
587
588 #ifdef __KERNEL_DEBUG__
589         kernel_write_debug_passes(kg, buffer, &state, &debug_data, sample);
590 #endif  /* __KERNEL_DEBUG__ */
591
592         return make_float4(L_sum.x, L_sum.y, L_sum.z, 1.0f - L_transparent);
593 }
594
595 ccl_device void kernel_branched_path_trace(KernelGlobals *kg,
596         ccl_global float *buffer, ccl_global uint *rng_state,
597         int sample, int x, int y, int offset, int stride)
598 {
599         /* buffer offset */
600         int index = offset + x + y*stride;
601         int pass_stride = kernel_data.film.pass_stride;
602
603         rng_state += index;
604         buffer += index*pass_stride;
605
606         /* initialize random numbers and ray */
607         RNG rng;
608         Ray ray;
609
610         kernel_path_trace_setup(kg, rng_state, sample, x, y, &rng, &ray);
611
612         /* integrate */
613         float4 L;
614
615         if(ray.t != 0.0f)
616                 L = kernel_branched_path_integrate(kg, &rng, sample, ray, buffer);
617         else
618                 L = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
619
620         /* accumulate result in output buffer */
621         kernel_write_pass_float4(buffer, sample, L);
622
623         path_rng_end(kg, rng_state, rng);
624 }
625
626 #endif  /* __BRANCHED_PATH__ */
627
628 CCL_NAMESPACE_END
629