Cycles: Add Volume Direct and Volume Indirect passes for volume-scattered light
authorLukas Stockner <lukas.stockner@freenet.de>
Tue, 14 Nov 2017 06:21:07 +0000 (07:21 +0100)
committerLukas Stockner <lukas.stockner@freenet.de>
Fri, 17 Nov 2017 15:39:45 +0000 (16:39 +0100)
No color pass because it's hard to define what to use as color in a volume.

Reviewers: sergey, brecht

Differential Revision: https://developer.blender.org/D2903

intern/cycles/blender/addon/engine.py
intern/cycles/blender/addon/properties.py
intern/cycles/blender/addon/ui.py
intern/cycles/blender/blender_sync.cpp
intern/cycles/kernel/kernel_accumulate.h
intern/cycles/kernel/kernel_passes.h
intern/cycles/kernel/kernel_types.h
intern/cycles/render/film.cpp

index 3018fd5..bc71a1b 100644 (file)
@@ -234,10 +234,12 @@ def register_passes(engine, scene, srl):
     if srl.use_pass_environment:           engine.register_pass(scene, srl, "Env",           3, "RGB",  'COLOR')
 
     crl = srl.cycles
-    if crl.pass_debug_bvh_traversed_nodes:     engine.register_pass(scene, srl, "Debug BVH Traversed Nodes",     1, "X", 'VALUE')
-    if crl.pass_debug_bvh_traversed_instances: engine.register_pass(scene, srl, "Debug BVH Traversed Instances", 1, "X", 'VALUE')
-    if crl.pass_debug_bvh_intersections:       engine.register_pass(scene, srl, "Debug BVH Intersections",       1, "X", 'VALUE')
-    if crl.pass_debug_ray_bounces:             engine.register_pass(scene, srl, "Debug Ray Bounces",             1, "X", 'VALUE')
+    if crl.pass_debug_bvh_traversed_nodes:     engine.register_pass(scene, srl, "Debug BVH Traversed Nodes",     1, "X",   'VALUE')
+    if crl.pass_debug_bvh_traversed_instances: engine.register_pass(scene, srl, "Debug BVH Traversed Instances", 1, "X",   'VALUE')
+    if crl.pass_debug_bvh_intersections:       engine.register_pass(scene, srl, "Debug BVH Intersections",       1, "X",   'VALUE')
+    if crl.pass_debug_ray_bounces:             engine.register_pass(scene, srl, "Debug Ray Bounces",             1, "X",   'VALUE')
+    if crl.use_pass_volume_direct:             engine.register_pass(scene, srl, "VolumeDir",                     3, "RGB", 'COLOR')
+    if crl.use_pass_volume_indirect:           engine.register_pass(scene, srl, "VolumeInd",                     3, "RGB", 'COLOR')
 
     cscene = scene.cycles
     if crl.use_denoising and crl.denoising_store_passes and not cscene.use_progressive_refine:
index 2e14952..e20e0b7 100644 (file)
@@ -1189,6 +1189,18 @@ class CyclesRenderLayerSettings(bpy.types.PropertyGroup):
                 default=False,
                 update=update_render_passes,
                 )
+        cls.use_pass_volume_direct = BoolProperty(
+                name="Volume Direct",
+                description="Deliver direct volumetric scattering pass",
+                default=False,
+                update=update_render_passes,
+                )
+        cls.use_pass_volume_indirect = BoolProperty(
+                name="Volume Indirect",
+                description="Deliver indirect volumetric scattering pass",
+                default=False,
+                update=update_render_passes,
+                )
 
         cls.use_denoising = BoolProperty(
                 name="Use Denoising",
index 67f1029..ff36e2a 100644 (file)
@@ -526,6 +526,10 @@ class CYCLES_RENDER_PT_layer_passes(CyclesButtonsPanel, Panel):
         row.prop(rl, "use_pass_subsurface_direct", text="Direct", toggle=True)
         row.prop(rl, "use_pass_subsurface_indirect", text="Indirect", toggle=True)
         row.prop(rl, "use_pass_subsurface_color", text="Color", toggle=True)
+        col.label(text="Volume:")
+        row = col.row(align=True)
+        row.prop(crl, "use_pass_volume_direct", text="Direct", toggle=True)
+        row.prop(crl, "use_pass_volume_indirect", text="Indirect", toggle=True)
 
         col.separator()
         col.prop(rl, "use_pass_emit", text="Emission")
index 142fd5e..dbc559e 100644 (file)
@@ -496,11 +496,13 @@ PassType BlenderSync::get_pass_type(BL::RenderPass& b_pass)
        MAP_PASS("GlossDir", PASS_GLOSSY_DIRECT);
        MAP_PASS("TransDir", PASS_TRANSMISSION_DIRECT);
        MAP_PASS("SubsurfaceDir", PASS_SUBSURFACE_DIRECT);
+       MAP_PASS("VolumeDir", PASS_VOLUME_DIRECT);
 
        MAP_PASS("DiffInd", PASS_DIFFUSE_INDIRECT);
        MAP_PASS("GlossInd", PASS_GLOSSY_INDIRECT);
        MAP_PASS("TransInd", PASS_TRANSMISSION_INDIRECT);
        MAP_PASS("SubsurfaceInd", PASS_SUBSURFACE_INDIRECT);
+       MAP_PASS("VolumeInd", PASS_VOLUME_INDIRECT);
 
        MAP_PASS("DiffCol", PASS_DIFFUSE_COLOR);
        MAP_PASS("GlossCol", PASS_GLOSSY_COLOR);
@@ -604,6 +606,14 @@ array<Pass> BlenderSync::sync_render_passes(BL::RenderLayer& b_rlay,
                Pass::add(PASS_RAY_BOUNCES, passes);
        }
 #endif
+       if(get_boolean(crp, "use_pass_volume_direct")) {
+               b_engine.add_pass("VolumeDir", 3, "RGB", b_srlay.name().c_str());
+               Pass::add(PASS_VOLUME_DIRECT, passes);
+       }
+       if(get_boolean(crp, "use_pass_volume_indirect")) {
+               b_engine.add_pass("VolumeInd", 3, "RGB", b_srlay.name().c_str());
+               Pass::add(PASS_VOLUME_INDIRECT, passes);
+       }
 
        return passes;
 }
index 366f254..7c1b2a0 100644 (file)
@@ -187,7 +187,6 @@ ccl_device_inline void path_radiance_init(PathRadiance *L, int use_light_pass)
                L->color_glossy = make_float3(0.0f, 0.0f, 0.0f);
                L->color_transmission = make_float3(0.0f, 0.0f, 0.0f);
                L->color_subsurface = make_float3(0.0f, 0.0f, 0.0f);
-               L->color_scatter = make_float3(0.0f, 0.0f, 0.0f);
 
                L->direct_diffuse = make_float3(0.0f, 0.0f, 0.0f);
                L->direct_glossy = make_float3(0.0f, 0.0f, 0.0f);
index 4236e2c..29451b6 100644 (file)
@@ -294,6 +294,8 @@ ccl_device_inline void kernel_write_light_passes(KernelGlobals *kg, ccl_global f
                kernel_write_pass_float3(buffer + kernel_data.film.pass_transmission_indirect, L->indirect_transmission);
        if(light_flag & PASSMASK(SUBSURFACE_INDIRECT))
                kernel_write_pass_float3(buffer + kernel_data.film.pass_subsurface_indirect, L->indirect_subsurface);
+       if(light_flag & PASSMASK(VOLUME_INDIRECT))
+               kernel_write_pass_float3(buffer + kernel_data.film.pass_volume_indirect, L->indirect_scatter);
        if(light_flag & PASSMASK(DIFFUSE_DIRECT))
                kernel_write_pass_float3(buffer + kernel_data.film.pass_diffuse_direct, L->direct_diffuse);
        if(light_flag & PASSMASK(GLOSSY_DIRECT))
@@ -302,6 +304,8 @@ ccl_device_inline void kernel_write_light_passes(KernelGlobals *kg, ccl_global f
                kernel_write_pass_float3(buffer + kernel_data.film.pass_transmission_direct, L->direct_transmission);
        if(light_flag & PASSMASK(SUBSURFACE_DIRECT))
                kernel_write_pass_float3(buffer + kernel_data.film.pass_subsurface_direct, L->direct_subsurface);
+       if(light_flag & PASSMASK(VOLUME_DIRECT))
+               kernel_write_pass_float3(buffer + kernel_data.film.pass_volume_direct, L->direct_scatter);
 
        if(light_flag & PASSMASK(EMISSION))
                kernel_write_pass_float3(buffer + kernel_data.film.pass_emission, L->emission);
index 1761ab2..b6a9cf5 100644 (file)
@@ -413,6 +413,9 @@ typedef enum PassType {
        PASS_SUBSURFACE_DIRECT,
        PASS_SUBSURFACE_INDIRECT,
        PASS_SUBSURFACE_COLOR,
+       PASS_VOLUME_DIRECT,
+       PASS_VOLUME_INDIRECT,
+       /* No Scatter color since it's tricky to define what it would even mean. */
        PASS_CATEGORY_LIGHT_END = 63,
 } PassType;
 
@@ -521,7 +524,6 @@ typedef ccl_addr_space struct PathRadiance {
        float3 color_glossy;
        float3 color_transmission;
        float3 color_subsurface;
-       float3 color_scatter;
 
        float3 direct_diffuse;
        float3 direct_glossy;
@@ -1214,11 +1216,13 @@ typedef struct KernelFilm {
        int pass_glossy_indirect;
        int pass_transmission_indirect;
        int pass_subsurface_indirect;
+       int pass_volume_indirect;
        
        int pass_diffuse_direct;
        int pass_glossy_direct;
        int pass_transmission_direct;
        int pass_subsurface_direct;
+       int pass_volume_direct;
        
        int pass_emission;
        int pass_background;
@@ -1237,7 +1241,8 @@ typedef struct KernelFilm {
        int pass_denoising_data;
        int pass_denoising_clean;
        int denoising_flags;
-       int pad;
+
+       int pad1, pad2, pad3;
 
 #ifdef __KERNEL_DEBUG__
        int pass_bvh_traversed_nodes;
index 5acc6a9..82fea67 100644 (file)
@@ -147,6 +147,11 @@ void Pass::add(PassType type, array<Pass>& passes)
                        pass.exposure = true;
                        pass.divide_type = PASS_SUBSURFACE_COLOR;
                        break;
+               case PASS_VOLUME_DIRECT:
+               case PASS_VOLUME_INDIRECT:
+                       pass.components = 4;
+                       pass.exposure = true;
+                       break;
 
                default:
                        assert(false);
@@ -390,6 +395,9 @@ void Film::device_update(Device *device, DeviceScene *dscene, Scene *scene)
                        case PASS_SUBSURFACE_INDIRECT:
                                kfilm->pass_subsurface_indirect = kfilm->pass_stride;
                                break;
+                       case PASS_VOLUME_INDIRECT:
+                               kfilm->pass_volume_indirect = kfilm->pass_stride;
+                               break;
                        case PASS_DIFFUSE_DIRECT:
                                kfilm->pass_diffuse_direct = kfilm->pass_stride;
                                break;
@@ -402,6 +410,9 @@ void Film::device_update(Device *device, DeviceScene *dscene, Scene *scene)
                        case PASS_SUBSURFACE_DIRECT:
                                kfilm->pass_subsurface_direct = kfilm->pass_stride;
                                break;
+                       case PASS_VOLUME_DIRECT:
+                               kfilm->pass_volume_direct = kfilm->pass_stride;
+                               break;
 
 #ifdef WITH_CYCLES_DEBUG
                        case PASS_BVH_TRAVERSED_NODES: