Merge branch 'master' into blender2.8
[blender.git] / intern / cycles / kernel / kernel_path_branched.h
index 441a06eeba33850ff7a3d1eb227a51d47b4556f4..80fcf5b056557153e55a7b03891167cc1a5f4488 100644 (file)
@@ -480,6 +480,12 @@ ccl_device void kernel_branched_path_integrate(KernelGlobals *kg,
 
                /* Setup and evaluate shader. */
                shader_setup_from_ray(kg, &sd, &isect, &ray);
+
+               /* Skip most work for volume bounding surface. */
+#ifdef __VOLUME__
+               if(!(sd.flag & SD_HAS_ONLY_VOLUME)) {
+#endif
+
                shader_eval_surface(kg, &sd, &state, state.flag);
                shader_merge_closures(&sd);
 
@@ -520,7 +526,7 @@ ccl_device void kernel_branched_path_integrate(KernelGlobals *kg,
 
 #ifdef __AO__
                /* ambient occlusion */
-               if(kernel_data.integrator.use_ambient_occlusion || (sd.flag & SD_AO)) {
+               if(kernel_data.integrator.use_ambient_occlusion) {
                        kernel_branched_path_ao(kg, &sd, emission_sd, L, &state, throughput);
                }
 #endif  /* __AO__ */
@@ -533,37 +539,43 @@ ccl_device void kernel_branched_path_integrate(KernelGlobals *kg,
                }
 #endif  /* __SUBSURFACE__ */
 
-               if(!(sd.flag & SD_HAS_ONLY_VOLUME)) {
-                       PathState hit_state = state;
+               PathState hit_state = state;
 
 #ifdef __EMISSION__
-                       /* direct light */
-                       if(kernel_data.integrator.use_direct_light) {
-                               int all = (kernel_data.integrator.sample_all_lights_direct) ||
-                                         (state.flag & PATH_RAY_SHADOW_CATCHER);
-                               kernel_branched_path_surface_connect_light(kg,
-                                       &sd, emission_sd, &hit_state, throughput, 1.0f, L, all);
-                       }
+               /* direct light */
+               if(kernel_data.integrator.use_direct_light) {
+                       int all = (kernel_data.integrator.sample_all_lights_direct) ||
+                                         (state.flag & PATH_RAY_SHADOW_CATCHER);
+                       kernel_branched_path_surface_connect_light(kg,
+                               &sd, emission_sd, &hit_state, throughput, 1.0f, L, all);
+               }
 #endif  /* __EMISSION__ */
 
-                       /* indirect light */
-                       kernel_branched_path_surface_indirect_light(kg,
-                               &sd, &indirect_sd, emission_sd, throughput, 1.0f, &hit_state, L);
+               /* indirect light */
+               kernel_branched_path_surface_indirect_light(kg,
+                       &sd, &indirect_sd, emission_sd, throughput, 1.0f, &hit_state, L);
 
-                       /* continue in case of transparency */
-                       throughput *= shader_bsdf_transparency(kg, &sd);
+               /* continue in case of transparency */
+               throughput *= shader_bsdf_transparency(kg, &sd);
 
-                       if(is_zero(throughput))
-                               break;
-               }
+               if(is_zero(throughput))
+                       break;
 
                /* Update Path State */
                path_state_next(kg, &state, LABEL_TRANSPARENT);
 
+#ifdef __VOLUME__
+               }
+               else {
+                       if(!path_state_volume_next(kg, &state)) {
+                               break;
+                       }
+               }
+#endif
+
                ray.P = ray_offset(sd.P, -sd.Ng);
                ray.t -= sd.ray_length; /* clipping works through transparent */
 
-
 #ifdef __RAY_DIFFERENTIALS__
                ray.dP = sd.dP;
                ray.dD.dx = -sd.dI.dx;