Cycles: better path termination for transparency.
[blender.git] / intern / cycles / kernel / kernel_shader.h
index 5f2f00c5cebab8c42d76729491f5976ba81dd738..8cfd33b808ece340b5f04f59fb7fbdcf86c40e94 100644 (file)
@@ -966,10 +966,21 @@ ccl_device float3 shader_holdout_eval(KernelGlobals *kg, ShaderData *sd)
 /* Surface Evaluation */
 
 ccl_device void shader_eval_surface(KernelGlobals *kg, ShaderData *sd,
-       ccl_addr_space PathState *state, int path_flag, int max_closure)
+       ccl_addr_space PathState *state, int path_flag)
 {
+       /* If path is being terminated, we are tracing a shadow ray or evaluating
+        * emission, then we don't need to store closures. The emission and shadow
+        * shader data also do not have a closure array to save GPU memory. */
+       int max_closures;
+       if(path_flag & (PATH_RAY_TERMINATE|PATH_RAY_SHADOW|PATH_RAY_EMISSION)) {
+               max_closures = 0;
+       }
+       else {
+               max_closures = kernel_data.integrator.max_closures;
+       }
+
        sd->num_closure = 0;
-       sd->num_closure_left = max_closure;
+       sd->num_closure_left = max_closures;
 
 #ifdef __OSL__
        if(kg->osl)
@@ -1140,13 +1151,23 @@ ccl_device_inline void shader_eval_volume(KernelGlobals *kg,
                                           ShaderData *sd,
                                           ccl_addr_space PathState *state,
                                           ccl_addr_space VolumeStack *stack,
-                                          int path_flag,
-                                          int max_closure)
+                                          int path_flag)
 {
+       /* If path is being terminated, we are tracing a shadow ray or evaluating
+        * emission, then we don't need to store closures. The emission and shadow
+        * shader data also do not have a closure array to save GPU memory. */
+       int max_closures;
+       if(path_flag & (PATH_RAY_TERMINATE|PATH_RAY_SHADOW|PATH_RAY_EMISSION)) {
+               max_closures = 0;
+       }
+       else {
+               max_closures = kernel_data.integrator.max_closures;
+       }
+
        /* reset closures once at the start, we will be accumulating the closures
         * for all volumes in the stack into a single array of closures */
        sd->num_closure = 0;
-       sd->num_closure_left = max_closure;
+       sd->num_closure_left = max_closures;
        sd->flag = 0;
        sd->object_flag = 0;