Commit: c36977652aa834165a95f4a803313cdb61899264
Author: Stefan Werner
Date:   Wed Jul 11 00:00:48 2018 +0200
Branches: cycles_cryptomatte
https://developer.blender.org/rBc36977652aa834165a95f4a803313cdb61899264

Cycles: Initial addition of Cryptomatte ID writing.

===================================================================

M       intern/cycles/blender/addon/engine.py
M       intern/cycles/blender/addon/properties.py
M       intern/cycles/blender/addon/ui.py
M       intern/cycles/blender/blender_object.cpp
M       intern/cycles/device/device_cpu.cpp
M       intern/cycles/kernel/geom/geom_object.h
M       intern/cycles/kernel/kernel_globals.h
M       intern/cycles/kernel/kernel_passes.h
M       intern/cycles/kernel/kernel_path_branched.h
M       intern/cycles/kernel/kernel_path_state.h
M       intern/cycles/kernel/kernel_path_surface.h
M       intern/cycles/kernel/kernel_shader.h
M       intern/cycles/kernel/kernel_types.h
M       intern/cycles/render/CMakeLists.txt
A       intern/cycles/render/coverage.cpp
A       intern/cycles/render/coverage.h
M       intern/cycles/render/film.cpp
M       intern/cycles/render/film.h
M       intern/cycles/render/object.cpp
M       intern/cycles/render/object.h
M       intern/cycles/render/shader.cpp
M       intern/cycles/util/CMakeLists.txt
A       intern/cycles/util/util_murmurhash.h

===================================================================

diff --git a/intern/cycles/blender/addon/engine.py 
b/intern/cycles/blender/addon/engine.py
index 1f97eff9bd0..d621b3dbd5b 100644
--- a/intern/cycles/blender/addon/engine.py
+++ b/intern/cycles/blender/addon/engine.py
@@ -254,3 +254,13 @@ def register_passes(engine, scene, srl):
         engine.register_pass(scene, srl, "Denoising Shadow B",        3, 
"XYV", 'VECTOR')
         engine.register_pass(scene, srl, "Denoising Image",           3, 
"RGB", 'COLOR')
         engine.register_pass(scene, srl, "Denoising Image Variance",  3, 
"RGB", 'COLOR')
+
+    if(crl.use_pass_crypto_object):
+        for i in range(0, crl.pass_crypto_depth, 2):
+            engine.register_pass(scene, srl, "AOV uCryptoObject" + 
'{:02d}'.format(i), 4, "RGBA", 'COLOR')
+    if(crl.use_pass_crypto_material):
+        for i in range(0, crl.pass_crypto_depth, 2):
+            engine.register_pass(scene, srl, "AOV uCryptoMaterial" + 
'{:02d}'.format(i), 4, "RGBA", 'COLOR')
+    if(srl.cycles.use_pass_crypto_asset):
+        for i in range(0, srl.cycles.pass_crypto_depth, 2):
+            engine.register_pass(scene, srl, "AOV uCryptoAsset" + 
'{:02d}'.format(i), 4, "RGBA", 'COLOR')
diff --git a/intern/cycles/blender/addon/properties.py 
b/intern/cycles/blender/addon/properties.py
index 4484dcfbfd7..5267d5a5476 100644
--- a/intern/cycles/blender/addon/properties.py
+++ b/intern/cycles/blender/addon/properties.py
@@ -1336,7 +1336,36 @@ class CyclesRenderLayerSettings(bpy.types.PropertyGroup):
                 default=False,
                 update=update_render_passes,
         )
-
+        cls.use_pass_crypto_object = BoolProperty(
+                name="CryptoMatte Object",
+                description="CryptoMatte Object pass",
+                default=False,
+                update=update_render_passes,
+                )
+        cls.use_pass_crypto_material = BoolProperty(
+                name="CryptoMatte Material",
+                description="CryptoMatte Material pass",
+                default=False,
+                update=update_render_passes,
+                )
+        cls.use_pass_crypto_asset = BoolProperty(
+                name="CryptoMatte Asset",
+                description="CryptoMatte Asset pass",
+                default=False,
+                update=update_render_passes,
+                )
+        cls.pass_crypto_depth = IntProperty(
+                name="CryptoMatte Depth",
+                description="CryptoMatte Depth",
+                default=4, min=2, max=16, step=2,
+                update=update_render_passes,
+                )
+        cls.pass_crypto_accurate = BoolProperty(
+                name="CryptoMatte Accurate",
+                description="Gernate a more accurate CryptoMatte pass, CPU 
only, may render slower and use more memory",
+                default=True,
+                update=update_render_passes,
+                )
     @classmethod
     def unregister(cls):
         del bpy.types.SceneRenderLayer.cycles
diff --git a/intern/cycles/blender/addon/ui.py 
b/intern/cycles/blender/addon/ui.py
index 2b11a2eefb0..92a466812ef 100644
--- a/intern/cycles/blender/addon/ui.py
+++ b/intern/cycles/blender/addon/ui.py
@@ -562,6 +562,17 @@ class CYCLES_RENDER_PT_layer_passes(CyclesButtonsPanel, 
Panel):
             col.prop(crl, "pass_debug_bvh_intersections")
             col.prop(crl, "pass_debug_ray_bounces")
 
+        crl = rl.cycles
+        layout.label("Cryptomatte:")
+        row = layout.row(align=True)
+        row.prop(crl, "use_pass_crypto_object", text="Object", toggle=True)
+        row.prop(crl, "use_pass_crypto_material", text="Material", toggle=True)
+        row.prop(crl, "use_pass_crypto_asset", text="Asset", toggle=True)
+        row = layout.row(align=True)
+        row.active = use_cpu(context)
+        row.prop(crl, "pass_crypto_accurate", text="Accurate Mode")
+        row = layout.row(align=True)
+        row.prop(crl, "pass_crypto_depth")
 
 class CYCLES_RENDER_PT_views(CyclesButtonsPanel, Panel):
     bl_label = "Views"
diff --git a/intern/cycles/blender/blender_object.cpp 
b/intern/cycles/blender/blender_object.cpp
index 35bf7beda41..d229f1098f3 100644
--- a/intern/cycles/blender/blender_object.cpp
+++ b/intern/cycles/blender/blender_object.cpp
@@ -384,6 +384,23 @@ Object *BlenderSync::sync_object(BL::Object& b_parent,
                object_updated = true;
        }
 
+       /* sync the asset name for Cryptomatte */
+       BL::Object parent = b_ob.parent();
+       ustring parent_name;
+       if(parent) {
+               while(parent.parent()) {
+                       parent = parent.parent();
+               }
+               parent_name = parent.name();
+       }
+       else {
+               parent_name = b_ob.name();
+       }
+       if(object->asset_name != parent_name) {
+               object->asset_name = parent_name;
+               object_updated = true;
+       }
+
        /* object sync
         * transform comparison should not be needed, but duplis don't work 
perfect
         * in the depsgraph and may not signal changes, so this is a workaround 
*/
diff --git a/intern/cycles/device/device_cpu.cpp 
b/intern/cycles/device/device_cpu.cpp
index be0dcc20755..e70c3e0d78c 100644
--- a/intern/cycles/device/device_cpu.cpp
+++ b/intern/cycles/device/device_cpu.cpp
@@ -53,6 +53,8 @@
 #include "util/util_system.h"
 #include "util/util_thread.h"
 
+#include "render/coverage.h"
+
 CCL_NAMESPACE_BEGIN
 
 class CPUDevice;
@@ -672,9 +674,25 @@ public:
                return true;
        }
 
-       void path_trace(DeviceTask &task, RenderTile &tile, KernelGlobals *kg)
+       void path_trace(DeviceTask &task, RenderTile &tile, KernelGlobals *kg, 
vector<map<float, float> >& coverage_object, vector<map<float, float> >& 
coverage_material, vector<map<float, float > >& coverage_asset)
        {
                scoped_timer timer(&tile.buffers->render_time);
+               kg->coverage_object = kg->coverage_material = NULL;
+
+               if(kg->__data.film.use_cryptomatte & CRYPT_ACCURATE) {
+                       if(kg->__data.film.use_cryptomatte & CRYPT_OBJECT) {
+                               coverage_object.clear();
+                               coverage_object.resize(tile.w * tile.h);
+                       }
+                       if(kg->__data.film.use_cryptomatte & CRYPT_MATERIAL) {
+                               coverage_material.clear();
+                               coverage_material.resize(tile.w * tile.h);
+                       }
+                       if(kg->__data.film.use_cryptomatte & CRYPT_ASSET) {
+                               coverage_asset.clear();
+                               coverage_asset.resize(tile.w * tile.h);
+                       }
+               }
 
                float *render_buffer = (float*)tile.buffer;
                int start_sample = tile.start_sample;
@@ -688,6 +706,17 @@ public:
 
                        for(int y = tile.y; y < tile.y + tile.h; y++) {
                                for(int x = tile.x; x < tile.x + tile.w; x++) {
+                                       if(kg->__data.film.use_cryptomatte & 
CRYPT_ACCURATE) {
+                                               
if(kg->__data.film.use_cryptomatte & CRYPT_OBJECT) {
+                                                       kg->coverage_object = 
&coverage_object[tile.w * (y - tile.y) + x - tile.x];
+                                               }
+                                               
if(kg->__data.film.use_cryptomatte & CRYPT_MATERIAL) {
+                                                       kg->coverage_material = 
&coverage_material[tile.w * (y - tile.y) + x - tile.x];
+                                               }
+                                               
if(kg->__data.film.use_cryptomatte & CRYPT_ASSET) {
+                                                       kg->coverage_asset = 
&coverage_asset[tile.w * (y - tile.y) + x - tile.x];
+                                               }
+                                       }
                                        path_trace_kernel()(kg, render_buffer,
                                                            sample, x, y, 
tile.offset, tile.stride);
                                }
@@ -746,17 +775,33 @@ public:
 
                while(task.acquire_tile(this, tile)) {
                        if(tile.task == RenderTile::PATH_TRACE) {
+                               /* cryptomatte data. This needs a better place 
than here. */
+                               vector<map<float, float> >coverage_object;
+                               vector<map<float, float> >coverage_material;
+                               vector<map<float, float> >coverage_asset;
+
                                if(use_split_kernel) {
                                        device_only_memory<uchar> 
void_buffer(this, "void_buffer");
                                        split_kernel->path_trace(&task, tile, 
kgbuffer, void_buffer);
                                }
                                else {
-                                       path_trace(task, tile, kg);
+                                       path_trace(task, tile, kg, 
coverage_object, coverage_material, coverage_asset);
+                               }
+                               if(kg->__data.film.use_cryptomatte & 
CRYPT_ACCURATE) {
+                                       int aov_index = 0;
+                                       if(kg->__data.film.use_cryptomatte & 
CRYPT_OBJECT) {
+                                               aov_index += 
flatten_coverage(kg, coverage_object, tile, aov_index);
+                                       }
+                                       if(kg->__data.film.use_cryptomatte & 
CRYPT_MATERIAL) {
+                                               aov_index += 
flatten_coverage(kg, coverage_material, tile, aov_index);
+                                       }
+                                       if(kg->__data.film.use_cryptomatte & 
CRYPT_ASSET) {
+                                               aov_index += 
flatten_coverage(kg, coverage_asset, tile, aov_index);
+                                       }
                                }
                        }
                        else if(tile.task == RenderTile::DENOISE) {
                                denoise(denoising, tile);
-
                                task.update_progress(&tile, tile.w*tile.h);
                        }
 
diff --git a/intern/cycles/kernel/geom/geom_object.h 
b/intern/cycles/kernel/geom/geom_object.h
index cfe17e63627..0eb8ce2cf8b 100644
--- a/intern/cycles/kernel/geom/geom_object.h
+++ b/intern/cycles/kernel/geom/geom_object.h
@@ -304,6 +304,24 @@ ccl_device int shader_pass_id(KernelGlobals *kg, const 
ShaderData *sd)
        return kernel_tex_fetch(__shaders, (sd->shader & SHADER_MASK)).pass_id;
 }
 
+/* Cryptomatte ID */
+
+ccl_device_inline float object_cryptomatte_id(KernelGlobals *kg, int object)
+{
+       if(object == OBJECT_NONE)
+               return 0.0f;
+
+       return kernel_tex_fetch(__objects, object).cryptomatte_object;
+}
+
+ccl_device_inline float object_cryptomatte_asset_id(KernelGlobals *kg, int 
object)
+{
+       if(object == OBJECT_NONE)
+               return 0;
+
+       return kernel_tex_fetch(__objects, object).cryptomatte_asset;
+}
+
 /* Particle data from which object was instanced */
 
 ccl_device_inline uint particle_index(KernelGlobals *kg, int particle)
diff --git a/intern/cycles/kernel/kernel_globals.h 
b/intern/cycles/kernel/kernel_globals.h
index 74cfacb5bc1..5276ea4b08b 100644
--- a/intern/cycles/kernel/kernel_globals.h
+++ b/intern/cycles/kernel/kernel_globals.h
@@ -20,7 +20,9 @@
 #define __KERNEL_GLOBALS_H__
 
 #ifdef __KERNEL_CPU__
+#include <vector>
 #  include "util/util_vector.h"
+#include "util/util_map.h"
 #endif
 
 #ifdef __KERNEL_OPENCL__
@@ -68,6 +70,11 @@ typedef struct KernelGlobals {
        VolumeStep *decoupled_volume_steps[2];
        int decoupled_volume_steps_index;
 
+       /* A buffer for storing per-pixel coverage for Cryptomatte. */
+       map<float, float> *coverage_object;
+       map<float, float> *coverage_material;
+       map<float, float> *coverage_asset;
+
        /* split kernel */
        SplitData split_data;
        SplitParams split_param_data;
diff --git a/intern/cycles/kernel/kernel_passes.h 
b/intern/cycles/kernel/kernel_passes.h
index 458aa6c2a97..ebad5410ddb

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to