Cycles: option to make background visible through glass transparent.
[blender-staging.git] / intern / cycles / kernel / kernel_path.h
index 1099064038bcd4faa43c2365212f0e1caab278db..1e98bca66ad5ae6a48ee6c82c3d977d5020d9732 100644 (file)
@@ -59,6 +59,11 @@ ccl_device_forceinline bool kernel_path_scene_intersect(
 {
        uint visibility = path_state_ray_visibility(kg, state);
 
+       if(path_state_ao_bounce(kg, state)) {
+               visibility = PATH_RAY_SHADOW;
+               ray->t = kernel_data.background.ao_distance;
+       }
+
 #ifdef __HAIR__
        float difl = 0.0f, extmax = 0.0f;
        uint lcg_state = 0;
@@ -74,11 +79,6 @@ ccl_device_forceinline bool kernel_path_scene_intersect(
                lcg_state = lcg_state_init_addrspace(state, 0x51633e2d);
        }
 
-       if(path_state_ao_bounce(kg, state)) {
-               visibility = PATH_RAY_SHADOW;
-               ray->t = kernel_data.background.ao_distance;
-       }
-
        bool hit = scene_intersect(kg, *ray, visibility, isect, &lcg_state, difl, extmax);
 #else
        bool hit = scene_intersect(kg, *ray, visibility, isect, NULL, 0.0f, 0.0f);
@@ -136,11 +136,11 @@ ccl_device_forceinline void kernel_path_background(
        PathRadiance *L)
 {
        /* eval background shader if nothing hit */
-       if(kernel_data.background.transparent && (state->flag & PATH_RAY_CAMERA)) {
+       if(kernel_data.background.transparent && (state->flag & PATH_RAY_TRANSPARENT_BACKGROUND)) {
                L->transparent += average(throughput);
 
 #ifdef __PASSES__
-               if(!(kernel_data.film.pass_flag & PASS_BACKGROUND))
+               if(!(kernel_data.film.light_pass_flag & PASSMASK(BACKGROUND)))
 #endif  /* __PASSES__ */
                        return;
        }
@@ -280,7 +280,7 @@ ccl_device_forceinline bool kernel_path_shader_apply(
 {
 #ifdef __SHADOW_TRICKS__
        if((sd->object_flag & SD_OBJECT_SHADOW_CATCHER)) {
-               if(state->flag & PATH_RAY_CAMERA) {
+               if(state->flag & PATH_RAY_TRANSPARENT_BACKGROUND) {
                        state->flag |= (PATH_RAY_SHADOW_CATCHER |
                                                   PATH_RAY_STORE_SHADOW_INFO);
 
@@ -302,7 +302,7 @@ ccl_device_forceinline bool kernel_path_shader_apply(
 #ifdef __HOLDOUT__
        if(((sd->flag & SD_HOLDOUT) ||
                (sd->object_flag & SD_OBJECT_HOLDOUT_MASK)) &&
-          (state->flag & PATH_RAY_CAMERA))
+          (state->flag & PATH_RAY_TRANSPARENT_BACKGROUND))
        {
                if(kernel_data.background.transparent) {
                        float3 holdout_weight;
@@ -443,7 +443,7 @@ ccl_device void kernel_path_indirect(KernelGlobals *kg,
                                      sd,
                                      &isect,
                                      ray);
-               shader_eval_surface(kg, sd, state, state->flag);
+               shader_eval_surface(kg, sd, state, state->flag, kernel_data.integrator.max_closures);
                shader_prepare_closures(sd, state);
 
                /* Apply shadow catcher, holdout, emission. */
@@ -561,7 +561,7 @@ ccl_device_forceinline void kernel_path_integrate(
                bool hit = kernel_path_scene_intersect(kg, state, ray, &isect, L);
 
                /* Find intersection with lamps and compute emission for MIS. */
-               kernel_path_lamp_emission(kg, state, ray, throughput, &isect, emission_sd, L);
+               kernel_path_lamp_emission(kg, state, ray, throughput, &isect, &sd, L);
 
 #ifdef __VOLUME__
                /* Volume integration. */
@@ -585,7 +585,7 @@ ccl_device_forceinline void kernel_path_integrate(
 
                /* Shade background. */
                if(!hit) {
-                       kernel_path_background(kg, state, ray, throughput, emission_sd, L);
+                       kernel_path_background(kg, state, ray, throughput, &sd, L);
                        break;
                }
                else if(path_state_ao_bounce(kg, state)) {
@@ -594,7 +594,7 @@ ccl_device_forceinline void kernel_path_integrate(
 
                /* Setup and evaluate shader. */
                shader_setup_from_ray(kg, &sd, &isect, ray);
-               shader_eval_surface(kg, &sd, state, state->flag);
+               shader_eval_surface(kg, &sd, state, state->flag, kernel_data.integrator.max_closures);
                shader_prepare_closures(&sd, state);
 
                /* Apply shadow catcher, holdout, emission. */
@@ -706,9 +706,11 @@ ccl_device void kernel_path_trace(KernelGlobals *kg,
        PathRadiance L;
        path_radiance_init(&L, kernel_data.film.use_light_pass);
 
-       ShaderData emission_sd;
+       ShaderDataTinyStorage emission_sd_storage;
+       ShaderData *emission_sd = AS_SHADER_DATA(&emission_sd_storage);
+
        PathState state;
-       path_state_init(kg, &emission_sd, &state, rng_hash, sample, &ray);
+       path_state_init(kg, emission_sd, &state, rng_hash, sample, &ray);
 
        /* Integrate. */
        kernel_path_integrate(kg,
@@ -717,7 +719,7 @@ ccl_device void kernel_path_trace(KernelGlobals *kg,
                              &ray,
                              &L,
                              buffer,
-                             &emission_sd);
+                             emission_sd);
 
        kernel_write_result(kg, buffer, sample, &L);
 }