Code cleanup: make L_transparent part of PathRadiance.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Sat, 12 Aug 2017 21:15:58 +0000 (23:15 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Sat, 12 Aug 2017 23:19:07 +0000 (01:19 +0200)
intern/cycles/kernel/kernel_accumulate.h
intern/cycles/kernel/kernel_passes.h
intern/cycles/kernel/kernel_path.h
intern/cycles/kernel/kernel_path_branched.h
intern/cycles/kernel/kernel_types.h
intern/cycles/kernel/split/kernel_buffer_update.h
intern/cycles/kernel/split/kernel_holdout_emission_blurring_pathtermination_ao.h
intern/cycles/kernel/split/kernel_indirect_background.h
intern/cycles/kernel/split/kernel_path_init.h
intern/cycles/kernel/split/kernel_split_data_types.h

index dce5004ae87e39ae06f8fab25ae377e721690362..82d3c153bf5e0cc97267ec1146bfc6a1b527333e 100644 (file)
@@ -208,6 +208,7 @@ ccl_device_inline void path_radiance_init(PathRadiance *L, int use_light_pass)
                L->path_subsurface = make_float3(0.0f, 0.0f, 0.0f);
                L->path_scatter = make_float3(0.0f, 0.0f, 0.0f);
 
+               L->transparent = 0.0f;
                L->emission = make_float3(0.0f, 0.0f, 0.0f);
                L->background = make_float3(0.0f, 0.0f, 0.0f);
                L->ao = make_float3(0.0f, 0.0f, 0.0f);
@@ -217,6 +218,7 @@ ccl_device_inline void path_radiance_init(PathRadiance *L, int use_light_pass)
        else
 #endif
        {
+               L->transparent = 0.0f;
                L->emission = make_float3(0.0f, 0.0f, 0.0f);
        }
 
index d8adaec9d17675ac2f6a308d490fed40f64a6348..de65e8ef27b979b87bf77709adb04139cf58df4b 100644 (file)
@@ -364,10 +364,12 @@ ccl_device_inline void kernel_write_light_passes(KernelGlobals *kg, ccl_global f
 }
 
 ccl_device_inline void kernel_write_result(KernelGlobals *kg, ccl_global float *buffer,
-       int sample, PathRadiance *L, float alpha, bool is_shadow_catcher)
+       int sample, PathRadiance *L, bool is_shadow_catcher)
 {
        if(L) {
                float3 L_sum;
+               float alpha = 1.0f - L->transparent;
+
 #ifdef __SHADOW_TRICKS__
                if(is_shadow_catcher) {
                        L_sum = path_radiance_sum_shadowcatcher(kg, L, &alpha);
index ed4c2c33aeb89d0c60dce7e6dff683160c6fa27a..c454228eab52fa1733c401669a97bf3e56405768 100644 (file)
@@ -432,17 +432,16 @@ ccl_device void kernel_path_indirect(KernelGlobals *kg,
 
 #endif /* defined(__BRANCHED_PATH__) || defined(__BAKING__) */
 
-ccl_device_inline float kernel_path_integrate(KernelGlobals *kg,
-                                              RNG *rng,
-                                              int sample,
-                                              Ray ray,
-                                              ccl_global float *buffer,
-                                              PathRadiance *L,
-                                              bool *is_shadow_catcher)
+ccl_device_inline void kernel_path_integrate(KernelGlobals *kg,
+                                             RNG *rng,
+                                             int sample,
+                                             Ray ray,
+                                             ccl_global float *buffer,
+                                             PathRadiance *L,
+                                             bool *is_shadow_catcher)
 {
        /* initialize */
        float3 throughput = make_float3(1.0f, 1.0f, 1.0f);
-       float L_transparent = 0.0f;
 
        path_radiance_init(L, kernel_data.film.use_light_pass);
 
@@ -496,7 +495,7 @@ ccl_device_inline float kernel_path_integrate(KernelGlobals *kg,
                if(state.flag & PATH_RAY_CAMERA) {
                        L->debug_data.num_bvh_traversed_nodes += isect.num_traversed_nodes;
                        L->debug_data.num_bvh_traversed_instances += isect.num_traversed_instances;
-                       L.->ebug_data.num_bvh_intersections += isect.num_intersections;
+                       L->debug_data.num_bvh_intersections += isect.num_intersections;
                }
                L->debug_data.num_ray_bounces++;
 #endif  /* __KERNEL_DEBUG__ */
@@ -613,7 +612,7 @@ ccl_device_inline float kernel_path_integrate(KernelGlobals *kg,
                if(!hit) {
                        /* eval background shader if nothing hit */
                        if(kernel_data.background.transparent && (state.flag & PATH_RAY_CAMERA)) {
-                               L_transparent += average(throughput);
+                               L->transparent += average(throughput);
 
 #ifdef __PASSES__
                                if(!(kernel_data.film.pass_flag & PASS_BACKGROUND))
@@ -673,7 +672,7 @@ ccl_device_inline float kernel_path_integrate(KernelGlobals *kg,
                                        holdout_weight = shader_holdout_eval(kg, &sd);
                                }
                                /* any throughput is ok, should all be identical here */
-                               L_transparent += average(holdout_weight*throughput);
+                               L->transparent += average(holdout_weight*throughput);
                        }
 
                        if(sd.object_flag & SD_OBJECT_HOLDOUT_MASK) {
@@ -780,8 +779,6 @@ ccl_device_inline float kernel_path_integrate(KernelGlobals *kg,
 #ifdef __SHADOW_TRICKS__
        *is_shadow_catcher = (state.flag & PATH_RAY_SHADOW_CATCHER) != 0;
 #endif  /* __SHADOW_TRICKS__ */
-
-       return 1.0f - L_transparent;
 }
 
 ccl_device void kernel_path_trace(KernelGlobals *kg,
@@ -806,11 +803,11 @@ ccl_device void kernel_path_trace(KernelGlobals *kg,
        bool is_shadow_catcher;
 
        if(ray.t != 0.0f) {
-               float alpha = kernel_path_integrate(kg, &rng, sample, ray, buffer, &L, &is_shadow_catcher);
-               kernel_write_result(kg, buffer, sample, &L, alpha, is_shadow_catcher);
+               kernel_path_integrate(kg, &rng, sample, ray, buffer, &L, &is_shadow_catcher);
+               kernel_write_result(kg, buffer, sample, &L, is_shadow_catcher);
        }
        else {
-               kernel_write_result(kg, buffer, sample, NULL, 0.0f, false);
+               kernel_write_result(kg, buffer, sample, NULL, false);
        }
 }
 
index a6c6c934bc0050aafa026daceb94dd2c5fd214f7..abc291bc7e3a7d51ae2d69f63edcca6e4ce32d5d 100644 (file)
@@ -269,17 +269,16 @@ ccl_device void kernel_branched_path_subsurface_scatter(KernelGlobals *kg,
 }
 #endif  /* __SUBSURFACE__ */
 
-ccl_device float kernel_branched_path_integrate(KernelGlobals *kg,
-                                                RNG *rng,
-                                                int sample,
-                                                Ray ray,
-                                                ccl_global float *buffer,
-                                                PathRadiance *L,
-                                                bool *is_shadow_catcher)
+ccl_device void kernel_branched_path_integrate(KernelGlobals *kg,
+                                               RNG *rng,
+                                               int sample,
+                                               Ray ray,
+                                               ccl_global float *buffer,
+                                               PathRadiance *L,
+                                               bool *is_shadow_catcher)
 {
        /* initialize */
        float3 throughput = make_float3(1.0f, 1.0f, 1.0f);
-       float L_transparent = 0.0f;
 
        path_radiance_init(L, kernel_data.film.use_light_pass);
 
@@ -477,7 +476,7 @@ ccl_device float kernel_branched_path_integrate(KernelGlobals *kg,
                if(!hit) {
                        /* eval background shader if nothing hit */
                        if(kernel_data.background.transparent) {
-                               L_transparent += average(throughput);
+                               L->transparent += average(throughput);
 
 #ifdef __PASSES__
                                if(!(kernel_data.film.pass_flag & PASS_BACKGROUND))
@@ -529,7 +528,7 @@ ccl_device float kernel_branched_path_integrate(KernelGlobals *kg,
                                        holdout_weight = shader_holdout_eval(kg, &sd);
                                }
                                /* any throughput is ok, should all be identical here */
-                               L_transparent += average(holdout_weight*throughput);
+                               L->transparent += average(holdout_weight*throughput);
                        }
                        if(sd.object_flag & SD_OBJECT_HOLDOUT_MASK) {
                                break;
@@ -632,8 +631,6 @@ ccl_device float kernel_branched_path_integrate(KernelGlobals *kg,
 #ifdef __SHADOW_TRICKS__
        *is_shadow_catcher = (state.flag & PATH_RAY_SHADOW_CATCHER) != 0;
 #endif  /* __SHADOW_TRICKS__ */
-
-       return 1.0f - L_transparent;
 }
 
 ccl_device void kernel_branched_path_trace(KernelGlobals *kg,
@@ -658,11 +655,11 @@ ccl_device void kernel_branched_path_trace(KernelGlobals *kg,
        bool is_shadow_catcher;
 
        if(ray.t != 0.0f) {
-               float alpha = kernel_branched_path_integrate(kg, &rng, sample, ray, buffer, &L, &is_shadow_catcher);
-               kernel_write_result(kg, buffer, sample, &L, alpha, is_shadow_catcher);
+               kernel_branched_path_integrate(kg, &rng, sample, ray, buffer, &L, &is_shadow_catcher);
+               kernel_write_result(kg, buffer, sample, &L, is_shadow_catcher);
        }
        else {
-               kernel_write_result(kg, buffer, sample, NULL, 0.0f, false);
+               kernel_write_result(kg, buffer, sample, NULL, false);
        }
 }
 
index 94ff49a9b082c019dd7789cb005b532d65314b3c..f1b82eee3524ce43d61a5368a21a3d7b3fa6ee2c 100644 (file)
@@ -485,6 +485,7 @@ typedef ccl_addr_space struct PathRadiance {
        int use_light_pass;
 #endif
 
+       float transparent;
        float3 emission;
 #ifdef __PASSES__
        float3 background;
index 30fc56b5609a58d0be408cc9c481945e12f605da..6aa0d6948d032fe51355c11c725a28d11b068ba5 100644 (file)
@@ -83,7 +83,6 @@ ccl_device void kernel_buffer_update(KernelGlobals *kg,
        PathRadiance *L = &kernel_split_state.path_radiance[ray_index];
        ccl_global Ray *ray = &kernel_split_state.ray[ray_index];
        ccl_global float3 *throughput = &kernel_split_state.throughput[ray_index];
-       ccl_global float *L_transparent = &kernel_split_state.L_transparent[ray_index];
        RNG rng = kernel_split_state.rng[ray_index];
        ccl_global float *buffer = kernel_split_params.buffer;
 
@@ -110,7 +109,7 @@ ccl_device void kernel_buffer_update(KernelGlobals *kg,
        if(IS_STATE(ray_state, ray_index, RAY_UPDATE_BUFFER)) {
                /* accumulate result in output buffer */
                bool is_shadow_catcher = (state->flag & PATH_RAY_SHADOW_CATCHER);
-               kernel_write_result(kg, buffer, sample, L, 1.0f - (*L_transparent), is_shadow_catcher);
+               kernel_write_result(kg, buffer, sample, L, is_shadow_catcher);
 
                ASSIGN_RAY_STATE(ray_state, ray_index, RAY_TO_REGENERATE);
        }
@@ -139,11 +138,10 @@ ccl_device void kernel_buffer_update(KernelGlobals *kg,
                        kernel_path_trace_setup(kg, rng_state, sample, pixel_x, pixel_y, &rng, ray);
 
                        if(ray->t != 0.0f) {
-                               /* Initialize throughput, L_transparent, Ray, PathState;
+                               /* Initialize throughput, path radiance, Ray, PathState;
                                 * These rays proceed with path-iteration.
                                 */
                                *throughput = make_float3(1.0f, 1.0f, 1.0f);
-                               *L_transparent = 0.0f;
                                path_radiance_init(L, kernel_data.film.use_light_pass);
                                path_state_init(kg, &kernel_split_state.sd_DL_shadow[ray_index], state, &rng, sample, ray);
 #ifdef __SUBSURFACE__
index adcb1bdc3773417b5bb365021eec9faf79eb9e65..95f57fbff57630c89fc1471f54e603df75c6c7b5 100644 (file)
@@ -162,7 +162,8 @@ ccl_device void kernel_holdout_emission_blurring_pathtermination_ao(
                                        holdout_weight = shader_holdout_eval(kg, sd);
                                }
                                /* any throughput is ok, should all be identical here */
-                               kernel_split_state.L_transparent[ray_index] += average(holdout_weight*throughput);
+                               PathRadiance *L = &kernel_split_state.path_radiance[ray_index];
+                               L->transparent += average(holdout_weight*throughput);
                        }
                        if(sd->object_flag & SD_OBJECT_HOLDOUT_MASK) {
                                kernel_split_path_end(kg, ray_index);
index f0ebb90f60ad450dc6262fa42467676842fd6f1e..04d5769ef0db233b2c7dc1ffc7c75fdbed65ce06 100644 (file)
@@ -54,12 +54,11 @@ ccl_device void kernel_indirect_background(KernelGlobals *kg)
        PathRadiance *L = &kernel_split_state.path_radiance[ray_index];
        ccl_global Ray *ray = &kernel_split_state.ray[ray_index];
        ccl_global float3 *throughput = &kernel_split_state.throughput[ray_index];
-       ccl_global float *L_transparent = &kernel_split_state.L_transparent[ray_index];
 
        if(IS_STATE(ray_state, ray_index, RAY_HIT_BACKGROUND)) {
                /* eval background shader if nothing hit */
                if(kernel_data.background.transparent && (state->flag & PATH_RAY_CAMERA)) {
-                       *L_transparent = (*L_transparent) + average((*throughput));
+                       L->transparent += average((*throughput));
 #ifdef __PASSES__
                        if(!(kernel_data.film.pass_flag & PASS_BACKGROUND))
 #endif
index 83e2d539949e0c7f4a571945583f594b0e6b6d48..8315b0b2bd3c86cd6cd839c5929a3ffc1b5f56d9 100644 (file)
@@ -71,11 +71,10 @@ ccl_device void kernel_path_init(KernelGlobals *kg) {
                                &kernel_split_state.ray[ray_index]);
 
        if(kernel_split_state.ray[ray_index].t != 0.0f) {
-               /* Initialize throughput, L_transparent, Ray, PathState;
+               /* Initialize throughput, path radiance, Ray, PathState;
                 * These rays proceed with path-iteration.
                 */
                kernel_split_state.throughput[ray_index] = make_float3(1.0f, 1.0f, 1.0f);
-               kernel_split_state.L_transparent[ray_index] = 0.0f;
                path_radiance_init(&kernel_split_state.path_radiance[ray_index], kernel_data.film.use_light_pass);
                path_state_init(kg,
                                &kernel_split_state.sd_DL_shadow[ray_index],
index 688151527f60b8be4939590037ab47c74ba8caf8..4f32c68d630f2c51d423889d50d07fde96521cdc 100644 (file)
@@ -116,7 +116,6 @@ typedef ccl_global struct SplitBranchedState {
 #define SPLIT_DATA_ENTRIES \
        SPLIT_DATA_ENTRY(ccl_global RNG, rng, 1) \
        SPLIT_DATA_ENTRY(ccl_global float3, throughput, 1) \
-       SPLIT_DATA_ENTRY(ccl_global float, L_transparent, 1) \
        SPLIT_DATA_ENTRY(PathRadiance, path_radiance, 1) \
        SPLIT_DATA_ENTRY(ccl_global Ray, ray, 1) \
        SPLIT_DATA_ENTRY(ccl_global PathState, path_state, 1) \
@@ -136,7 +135,6 @@ typedef ccl_global struct SplitBranchedState {
 #define SPLIT_DATA_ENTRIES_BRANCHED_SHARED \
        SPLIT_DATA_ENTRY(ccl_global RNG, rng, 1) \
        SPLIT_DATA_ENTRY(ccl_global float3, throughput, 1) \
-       SPLIT_DATA_ENTRY(ccl_global float, L_transparent, 1) \
        SPLIT_DATA_ENTRY(PathRadiance, path_radiance, 1) \
        SPLIT_DATA_ENTRY(ccl_global Ray, ray, 1) \
        SPLIT_DATA_ENTRY(ccl_global PathState, path_state, 1) \