Commit: 38589de10c098cfe32ac7716f4d7844abf959753
Author: Patrick Mours
Date:   Tue Feb 11 16:30:01 2020 +0100
Branches: master
https://developer.blender.org/rB38589de10c098cfe32ac7716f4d7844abf959753

Cycles: Add support for denoising in the viewport

The OptiX denoiser can be a great help when rendering in the viewport, since it 
is really fast
and needs few samples to produce convincing results. This patch therefore adds 
support for
using any Cycles denoiser in the viewport also (but only the OptiX one is 
selectable because
the NLM one is too slow to be usable currently). It also adds support for 
denoising on a
different device than rendering (so one can e.g. render with the CPU but 
denoise with OptiX).

Reviewed By: #cycles, brecht

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

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

M       intern/cycles/blender/addon/properties.py
M       intern/cycles/blender/addon/ui.py
M       intern/cycles/blender/blender_camera.cpp
M       intern/cycles/blender/blender_device.cpp
M       intern/cycles/blender/blender_session.cpp
M       intern/cycles/blender/blender_sync.cpp
M       intern/cycles/blender/blender_sync.h
M       intern/cycles/blender/blender_viewport.cpp
M       intern/cycles/blender/blender_viewport.h
M       intern/cycles/device/device.cpp
M       intern/cycles/device/device.h
M       intern/cycles/device/device_cpu.cpp
M       intern/cycles/device/device_cuda.cpp
M       intern/cycles/device/device_memory.h
M       intern/cycles/device/device_multi.cpp
M       intern/cycles/device/device_optix.cpp
M       intern/cycles/device/device_task.cpp
M       intern/cycles/device/device_task.h
M       intern/cycles/device/opencl/opencl_split.cpp
M       intern/cycles/kernel/kernels/cuda/filter.cu
M       intern/cycles/render/buffers.cpp
M       intern/cycles/render/session.cpp
M       intern/cycles/render/session.h
M       intern/cycles/render/tile.cpp
M       intern/cycles/render/tile.h

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

diff --git a/intern/cycles/blender/addon/properties.py 
b/intern/cycles/blender/addon/properties.py
index 5f163c2510b..eafe37618b3 100644
--- a/intern/cycles/blender/addon/properties.py
+++ b/intern/cycles/blender/addon/properties.py
@@ -197,7 +197,12 @@ enum_aov_types = (
     ('COLOR', "Color", "Write a Color pass", 1),
 )
 
-enum_denoising_optix_input_passes= (
+enum_viewport_denoising = (
+    ('NONE', "None", "Disable viewport denoising", 0),
+    ('OPTIX', "OptiX AI-Accelerated", "Use the OptiX denoiser running on the 
GPU (requires at least one compatible OptiX device)", 1),
+)
+
+enum_denoising_optix_input_passes = (
     ('RGB', "Color", "Use only color as input", 1),
     ('RGB_ALBEDO', "Color + Albedo", "Use color and albedo data as input", 2),
     ('RGB_ALBEDO_NORMAL', "Color + Albedo + Normal", "Use color, albedo and 
normal data as input", 3),
@@ -229,6 +234,18 @@ class CyclesRenderSettings(bpy.types.PropertyGroup):
         default='PATH',
     )
 
+    preview_pause: BoolProperty(
+        name="Pause Preview",
+        description="Pause all viewport preview renders",
+        default=False,
+    )
+    preview_denoising: EnumProperty(
+        name="Viewport Denoising",
+        description="Denoise the image after each preview update with the 
selected denoiser engine",
+        items=enum_viewport_denoising,
+        default='NONE',
+    )
+
     use_square_samples: BoolProperty(
         name="Square Samples",
         description="Square sampling values for easier artist control",
@@ -247,11 +264,6 @@ class CyclesRenderSettings(bpy.types.PropertyGroup):
         min=0, max=(1 << 24),
         default=32,
     )
-    preview_pause: BoolProperty(
-        name="Pause Preview",
-        description="Pause all viewport preview renders",
-        default=False,
-    )
     aa_samples: IntProperty(
         name="AA Samples",
         description="Number of antialiasing samples to render for each pixel",
@@ -264,6 +276,7 @@ class CyclesRenderSettings(bpy.types.PropertyGroup):
         min=0, max=2097151,
         default=32,
     )
+
     diffuse_samples: IntProperty(
         name="Diffuse Samples",
         description="Number of diffuse bounce samples to render for each AA 
sample",
@@ -294,14 +307,12 @@ class CyclesRenderSettings(bpy.types.PropertyGroup):
         min=1, max=1024,
         default=1,
     )
-
     subsurface_samples: IntProperty(
         name="Subsurface Samples",
         description="Number of subsurface scattering samples to render for 
each AA sample",
         min=1, max=1024,
         default=1,
     )
-
     volume_samples: IntProperty(
         name="Volume Samples",
         description="Number of volume scattering samples to render for each AA 
sample",
@@ -1305,12 +1316,6 @@ class CyclesRenderLayerSettings(bpy.types.PropertyGroup):
         default=False,
         update=update_render_passes,
     )
-    use_optix_denoising: BoolProperty(
-        name="Use OptiX AI Denoising",
-        description="Denoise the rendered image with the OptiX AI denoiser",
-        default=False,
-        update=update_render_passes,
-    )
     denoising_diffuse_direct: BoolProperty(
         name="Diffuse Direct",
         description="Denoise the direct diffuse lighting",
@@ -1387,11 +1392,18 @@ class 
CyclesRenderLayerSettings(bpy.types.PropertyGroup):
         min=0, max=7,
         default=0,
     )
+
+    use_optix_denoising: BoolProperty(
+        name="OptiX AI-Accelerated",
+        description="Use the OptiX denoiser to denoise the rendered image",
+        default=False,
+        update=update_render_passes,
+    )
     denoising_optix_input_passes: EnumProperty(
         name="Input Passes",
-        description="Controls which passes the OptiX AI denoiser should use as 
input, which can have different effects on the denoised image",
+        description="Passes handed over to the OptiX denoiser (this can have 
different effects on the denoised image)",
         items=enum_denoising_optix_input_passes,
-        default='RGB',
+        default='RGB_ALBEDO',
     )
 
     use_pass_crypto_object: BoolProperty(
diff --git a/intern/cycles/blender/addon/ui.py 
b/intern/cycles/blender/addon/ui.py
index 35d5d3801d2..f23d141e3da 100644
--- a/intern/cycles/blender/addon/ui.py
+++ b/intern/cycles/blender/addon/ui.py
@@ -112,6 +112,10 @@ def show_device_active(context):
         return True
     return 
context.preferences.addons[__package__].preferences.has_active_device()
 
+def show_optix_denoising(context):
+    # OptiX AI denoiser can be used when at least one device supports OptiX
+    return 
bool(context.preferences.addons[__package__].preferences.get_devices_for_type('OPTIX'))
+
 
 def draw_samples_info(layout, context):
     cscene = context.scene.cycles
@@ -177,17 +181,23 @@ class CYCLES_RENDER_PT_sampling(CyclesButtonsPanel, 
Panel):
         if not use_optix(context):
             layout.prop(cscene, "progressive")
 
-        if cscene.progressive == 'PATH' or use_branched_path(context) is False:
+        if not use_branched_path(context):
             col = layout.column(align=True)
             col.prop(cscene, "samples", text="Render")
             col.prop(cscene, "preview_samples", text="Viewport")
-
-            draw_samples_info(layout, context)
         else:
             col = layout.column(align=True)
             col.prop(cscene, "aa_samples", text="Render")
             col.prop(cscene, "preview_aa_samples", text="Viewport")
 
+        # Viewport denoising is currently only supported with OptiX
+        if show_optix_denoising(context):
+            col = layout.column()
+            col.prop(cscene, "preview_denoising")
+
+        if not use_branched_path(context):
+            draw_samples_info(layout, context)
+
 
 class CYCLES_RENDER_PT_sampling_sub_samples(CyclesButtonsPanel, Panel):
     bl_label = "Sub Samples"
@@ -195,9 +205,7 @@ class 
CYCLES_RENDER_PT_sampling_sub_samples(CyclesButtonsPanel, Panel):
 
     @classmethod
     def poll(cls, context):
-        scene = context.scene
-        cscene = scene.cycles
-        return cscene.progressive != 'PATH' and use_branched_path(context)
+        return use_branched_path(context)
 
     def draw(self, context):
         layout = self.layout
@@ -635,9 +643,6 @@ class 
CYCLES_RENDER_PT_performance_tiles(CyclesButtonsPanel, Panel):
 
         sub = col.column()
         sub.active = not rd.use_save_buffers
-        for view_layer in scene.view_layers:
-            if view_layer.cycles.use_denoising:
-                sub.active = False
         sub.prop(cscene, "use_progressive_refine")
 
 
@@ -981,15 +986,14 @@ class CYCLES_RENDER_PT_denoising(CyclesButtonsPanel, 
Panel):
 
         col = split.column(align=True)
 
-        if use_optix(context):
-            col.prop(cycles_view_layer, "use_optix_denoising", text="OptiX AI 
Denoising")
+        if show_optix_denoising(context):
+            col.prop(cycles_view_layer, "use_optix_denoising")
+            col.separator(factor=2.0)
 
             if cycles_view_layer.use_optix_denoising:
                 col.prop(cycles_view_layer, "denoising_optix_input_passes")
                 return
 
-            col.separator(factor=2.0)
-
         col.prop(cycles_view_layer, "denoising_radius", text="Radius")
         col.prop(cycles_view_layer, "denoising_strength", slider=True, 
text="Strength")
         col.prop(cycles_view_layer, "denoising_feature_strength", slider=True, 
text="Feature Strength")
@@ -2192,8 +2196,6 @@ def draw_device(self, context):
         col = layout.column()
         col.prop(cscene, "feature_set")
 
-        scene = context.scene
-
         col = layout.column()
         col.active = show_device_active(context)
         col.prop(cscene, "device")
diff --git a/intern/cycles/blender/blender_camera.cpp 
b/intern/cycles/blender/blender_camera.cpp
index c84d6e1572b..990061dd9f1 100644
--- a/intern/cycles/blender/blender_camera.cpp
+++ b/intern/cycles/blender/blender_camera.cpp
@@ -863,7 +863,8 @@ void BlenderSync::sync_view(BL::SpaceView3D &b_v3d,
   }
 }
 
-BufferParams BlenderSync::get_buffer_params(BL::RenderSettings &b_render,
+BufferParams BlenderSync::get_buffer_params(BL::Scene &b_scene,
+                                            BL::RenderSettings &b_render,
                                             BL::SpaceView3D &b_v3d,
                                             BL::RegionView3D &b_rv3d,
                                             Camera *cam,
@@ -899,7 +900,11 @@ BufferParams 
BlenderSync::get_buffer_params(BL::RenderSettings &b_render,
     params.height = height;
   }
 
-  update_viewport_display_passes(b_v3d, params.passes);
+  PassType display_pass = update_viewport_display_passes(b_v3d, params.passes);
+
+  /* Can only denoise the combined image pass */
+  params.denoising_data_pass = display_pass == PASS_COMBINED &&
+                               update_viewport_display_denoising(b_v3d, 
b_scene);
 
   return params;
 }
diff --git a/intern/cycles/blender/blender_device.cpp 
b/intern/cycles/blender/blender_device.cpp
index 111fc8d5192..c3c307318a8 100644
--- a/intern/cycles/blender/blender_device.cpp
+++ b/intern/cycles/blender/blender_device.cpp
@@ -19,6 +19,22 @@
 
 CCL_NAMESPACE_BEGIN
 
+enum DenoiserType {
+  DENOISER_NONE = 0,
+  DENOISER_OPTIX = 1,
+
+  DENOISER_NUM
+};
+
+enum ComputeDevice {
+  COMPUTE_DEVICE_CPU = 0,
+  COMPUTE_DEVICE_CUDA = 1,
+  COMPUTE_DEVICE_OPENCL = 2,
+  COMPUTE_DEVICE_OPTIX = 3,
+
+  COMPUTE_DEVICE_NUM
+};
+
 int blender_device_threads(BL::Scene &b_scene)
 {
   BL::RenderSettings b_r = b_scene.render();
@@ -40,7 +56,7 @@ DeviceInfo blender_device_info(BL::Preferences 
&b_preferences, BL::Scene &b_scen
     /* Find network device. */
     vector<DeviceInfo> devices = 
Device::available_devices(DEVICE_MASK_NETWORK);
     if (!devices.empty()) {
-      device = devices.front();
+      return devices.front();
     }
   }
   else if (get_enum(cscene, "device") == 1) {
@@ -57,14 +73,6 @@ DeviceInfo blender_device_info(BL::Preferences 
&b_preferences, BL::Scene &b_scen
     }
 
     /* Test if we are using GPU devices. */
-    enum ComputeDevice {
-      COMPUTE_DEVICE_CPU = 0,
-      COMPUTE_DEVICE_CUDA = 1,
-      COMPUTE_DEVICE_OPENCL = 2,
-      C

@@ 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