Cycles: Add debug pass showing average number of ray bounces per pixel
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 11 Jun 2015 08:42:38 +0000 (10:42 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 11 Jun 2015 12:53:15 +0000 (14:53 +0200)
Quite straightforward implementation, but still needs some work for the split
kernel. Includes both regular and split kernel implementation for that.

The pass is not exposed to the interface yet because it's currently not really
easy to have same pass listed in the menu multiple times.

intern/cycles/blender/blender_session.cpp
intern/cycles/kernel/kernel_debug.h
intern/cycles/kernel/kernel_path.h
intern/cycles/kernel/kernel_types.h
intern/cycles/kernel/split/kernel_scene_intersect.h
intern/cycles/render/buffers.cpp
intern/cycles/render/film.cpp
source/blender/makesrna/intern/rna_render.c
source/blender/render/extern/include/RE_pipeline.h
source/blender/render/intern/source/render_result.c

index bb345e2b3cfa3ccf7c506c9c966aedfbf65f6c36..47ede7d9b88bdd57bfd4603538b74c8919f7b240 100644 (file)
@@ -271,6 +271,8 @@ static PassType get_pass_type(BL::RenderPass b_pass)
                {
                        if(b_pass.debug_type() == BL::RenderPass::debug_type_BVH_TRAVERSAL_STEPS)
                                return PASS_BVH_TRAVERSAL_STEPS;
+                       if(b_pass.debug_type() == BL::RenderPass::debug_type_RAY_BOUNCES)
+                               return PASS_RAY_BOUNCES;
                        break;
                }
 #endif
@@ -439,6 +441,7 @@ void BlenderSession::render()
                Pass::add(PASS_COMBINED, passes);
 #ifdef WITH_CYCLES_DEBUG
                Pass::add(PASS_BVH_TRAVERSAL_STEPS, passes);
+               /* Pass::add(PASS_RAY_BOUNCES, passes); */
 #endif
 
                if(session_params.device.advanced_shading) {
index 94ede397848ae6ea9686aceb5cddb9af44830d7d..da9a48a11f986d836c70f1737fce51dd998bff71 100644 (file)
@@ -19,6 +19,7 @@ CCL_NAMESPACE_BEGIN
 ccl_device_inline void debug_data_init(DebugData *debug_data)
 {
        debug_data->num_bvh_traversal_steps = 0;
+       debug_data->num_ray_bounces = 0;
 }
 
 ccl_device_inline void kernel_write_debug_passes(KernelGlobals *kg,
@@ -33,6 +34,11 @@ ccl_device_inline void kernel_write_debug_passes(KernelGlobals *kg,
                                        sample,
                                        debug_data->num_bvh_traversal_steps);
        }
+       if(flag & PASS_RAY_BOUNCES) {
+               kernel_write_pass_float(buffer + kernel_data.film.pass_ray_bounces,
+                                       sample,
+                                       debug_data->num_ray_bounces);
+       }
 }
 
 CCL_NAMESPACE_END
index e2dbf6e22f7d935296787308aedb79a4ba6b7721..857d97329b69c1fc2c5ab97cede26eaa88c103e5 100644 (file)
@@ -477,6 +477,7 @@ ccl_device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int sample,
                if(state.flag & PATH_RAY_CAMERA) {
                        debug_data.num_bvh_traversal_steps += isect.num_traversal_steps;
                }
+               debug_data.num_ray_bounces++;
 #endif
 
 #ifdef __LAMP_MIS__
@@ -878,6 +879,7 @@ ccl_device float4 kernel_branched_path_integrate(KernelGlobals *kg, RNG *rng, in
                if(state.flag & PATH_RAY_CAMERA) {
                        debug_data.num_bvh_traversal_steps += isect.num_traversal_steps;
                }
+               debug_data.num_ray_bounces++;
 #endif
 
 #ifdef __VOLUME__
index 1ef07629a3e931cac5741a584aa38f6ee861e7ef..67e41a5ee8124293bc69b8e86bfbc9eb4fd7f6f4 100644 (file)
@@ -337,6 +337,7 @@ typedef enum PassType {
        PASS_LIGHT = (1 << 25), /* no real pass, used to force use_light_pass */
 #ifdef __KERNEL_DEBUG__
        PASS_BVH_TRAVERSAL_STEPS = (1 << 26),
+       PASS_RAY_BOUNCES = (1 << 27),
 #endif
 } PassType;
 
@@ -848,7 +849,8 @@ typedef struct KernelFilm {
 
 #ifdef __KERNEL_DEBUG__
        int pass_bvh_traversal_steps;
-       int pass_pad3, pass_pad4, pass_pad5;
+       int pass_ray_bounces;
+       int pass_pad3, pass_pad4;
 #endif
 } KernelFilm;
 
@@ -987,6 +989,7 @@ typedef ccl_addr_space struct DebugData {
        // Total number of BVH node traversal steps and primitives intersections
        // for the camera rays.
        int num_bvh_traversal_steps;
+       int num_ray_bounces;
 } DebugData;
 #endif
 
index 09e3e5ddd7e141b9911ec44e58afd57cd9fd1f5b..c1e82c7a21b0ed4e2739204eb1fb35f68f55b7c1 100644 (file)
@@ -124,6 +124,7 @@ ccl_device void kernel_scene_intersect(
        if(state.flag & PATH_RAY_CAMERA) {
                debug_data->num_bvh_traversal_steps += isect->num_traversal_steps;
        }
+       debug_data->num_ray_bounces++;
 #endif
 
        if(!hit) {
index 011c722c000a8921df05868a7781b578ebdde489..fab3f701757e3d320ec98d8433ae4f530ed2aeb5 100644 (file)
@@ -197,6 +197,12 @@ bool RenderBuffers::get_pass_rect(PassType type, float exposure, int sample, int
                                        pixels[0] = f;
                                }
                        }
+                       else if(type == PASS_RAY_BOUNCES) {
+                               for(int i = 0; i < size; i++, in += pass_stride, pixels++) {
+                                       float f = *in;
+                                       pixels[0] = f;
+                               }
+                       }
 #endif
                        else {
                                for(int i = 0; i < size; i++, in += pass_stride, pixels++) {
index b23678dea4426496c18527f744e369c91e1bf009..93b29ed90a9ea8b961471401c4a0f91815e39f36 100644 (file)
@@ -151,6 +151,10 @@ void Pass::add(PassType type, vector<Pass>& passes)
                        pass.components = 1;
                        pass.exposure = false;
                        break;
+               case PASS_RAY_BOUNCES:
+                       pass.components = 1;
+                       pass.exposure = false;
+                       break;
 #endif
        }
 
@@ -399,6 +403,9 @@ void Film::device_update(Device *device, DeviceScene *dscene, Scene *scene)
                        case PASS_BVH_TRAVERSAL_STEPS:
                                kfilm->pass_bvh_traversal_steps = kfilm->pass_stride;
                                break;
+                       case PASS_RAY_BOUNCES:
+                               kfilm->pass_ray_bounces = kfilm->pass_stride;
+                               break;
 #endif
 
                        case PASS_NONE:
index ee51dcf2acfe6e280a3af6d2d2be2d4d7142d93a..7ec2619d2df0f622c8a31ffd41d03ec64e1bdc64 100644 (file)
@@ -769,6 +769,7 @@ static void rna_def_render_pass(BlenderRNA *brna)
 
        static EnumPropertyItem render_pass_debug_type_items[] = {
                {RENDER_PASS_DEBUG_BVH_TRAVERSAL_STEPS, "BVH_TRAVERSAL_STEPS", 0, "BVH Traversal Steps", ""},
+               {RENDER_PASS_DEBUG_RAY_BOUNCES, "RAY_BOUNCES", 0, "Ray Steps", ""},
                {0, NULL, 0, NULL, NULL}
        };
 
index 9331c45237d9061c97f449cfd41d9d1b30f53bb9..98abae26488179cb73cc40b2c6e5eb20283a31af 100644 (file)
@@ -99,6 +99,7 @@ typedef struct RenderPass {
 
 enum {
        RENDER_PASS_DEBUG_BVH_TRAVERSAL_STEPS = 0,
+       RENDER_PASS_DEBUG_RAY_BOUNCES = 1,
 };
 
 /* a renderlayer is a full image, but with all passes and samples */
index 1bcde896e82860676bc2f73943b2f335a189b4b0..ea7b32d2da9a31a96dc2844d9f8c936bae409dd3 100644 (file)
@@ -531,6 +531,8 @@ static const char *debug_pass_type_name_get(int debug_type)
        switch (debug_type) {
                case RENDER_PASS_DEBUG_BVH_TRAVERSAL_STEPS:
                        return "BVH Traversal Steps";
+               case RENDER_PASS_DEBUG_RAY_BOUNCES:
+                       return "Ray Bounces";
        }
        return "Unknown";
 }