Cycles: Add option to change which sample to start viewport denoising at

This patch adds a new user-configurable option to change at which sample viewport
denoising should kick in. Setting it to zero retains previous behavior (start immediately), while
other values will defer denoising until the particular sample has been reached. Default is now
at one, to avoid the weirdness that is AI denoising at small resolutions.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D6906
This commit is contained in:
Patrick Mours 2020-02-25 13:31:08 +01:00
parent a4a1074f3d
commit 0c09700f20
6 changed files with 37 additions and 9 deletions

View File

@ -569,6 +569,12 @@ class CyclesRenderSettings(bpy.types.PropertyGroup):
default=64,
subtype='PIXEL'
)
preview_denoising_start_sample: IntProperty(
name="Start Denoising",
description="Sample to start denoising the preview at",
min=0, max=(1 << 24),
default=1,
)
debug_reset_timeout: FloatProperty(
name="Reset timeout",

View File

@ -710,6 +710,11 @@ class CYCLES_RENDER_PT_performance_viewport(CyclesButtonsPanel, Panel):
col.prop(rd, "preview_pixel_size", text="Pixel Size")
col.prop(cscene, "preview_start_resolution", text="Start Pixels")
if show_optix_denoising(context):
sub = col.row(align=True)
sub.active = cscene.preview_denoising != 'NONE'
sub.prop(cscene, "preview_denoising_start_sample", text="Denoising Start Sample")
class CYCLES_RENDER_PT_filter(CyclesButtonsPanel, Panel):
bl_label = "Filter"

View File

@ -849,6 +849,7 @@ void BlenderSession::synchronize(BL::Depsgraph &b_depsgraph_)
/* increase samples, but never decrease */
session->set_samples(session_params.samples);
session->set_denoising_start_sample(session_params.denoising_start_sample);
session->set_pause(session_pause);
/* copy recalc flags, outside of mutex so we can decide to do the real

View File

@ -832,6 +832,7 @@ SessionParams BlenderSync::get_session_params(BL::RenderEngine &b_engine,
/* other parameters */
params.start_resolution = get_int(cscene, "preview_start_resolution");
params.denoising_start_sample = get_int(cscene, "preview_denoising_start_sample");
params.pixel_size = b_engine.get_preview_pixel_size(b_scene);
/* other parameters */

View File

@ -908,9 +908,6 @@ void Session::set_samples(int samples)
params.samples = samples;
tile_manager.set_samples(samples);
{
thread_scoped_lock pause_lock(pause_mutex);
}
pause_cond.notify_all();
}
}
@ -946,6 +943,15 @@ void Session::set_denoising(bool denoising, bool optix_denoising)
tile_manager.schedule_denoising = denoising && !buffers;
}
void Session::set_denoising_start_sample(int sample)
{
if (sample != params.denoising_start_sample) {
params.denoising_start_sample = sample;
pause_cond.notify_all();
}
}
void Session::wait()
{
if (session_thread) {
@ -1110,8 +1116,8 @@ void Session::denoise()
return;
}
/* It can happen that denoising was already enabled, but the scene still needs an update. */
if (scene->film->need_update || !scene->film->denoising_data_offset) {
/* Do not denoise viewport until the sample at which denoising should start is reached. */
if (!params.background && tile_manager.state.sample < params.denoising_start_sample) {
return;
}
@ -1122,6 +1128,11 @@ void Session::denoise()
return;
}
/* It can happen that denoising was already enabled, but the scene still needs an update. */
if (scene->film->need_update || !scene->film->denoising_data_offset) {
return;
}
/* Add separate denoising task. */
DeviceTask task(DeviceTask::DENOISE);

View File

@ -53,6 +53,7 @@ class SessionParams {
int2 tile_size;
TileOrder tile_order;
int start_resolution;
int denoising_start_sample;
int pixel_size;
int threads;
@ -85,6 +86,7 @@ class SessionParams {
samples = 1024;
tile_size = make_int2(64, 64);
start_resolution = INT_MAX;
denoising_start_sample = 0;
pixel_size = 1;
threads = 0;
@ -109,9 +111,10 @@ class SessionParams {
bool modified(const SessionParams &params)
{
return !(device == params.device && background == params.background &&
progressive_refine == params.progressive_refine
/* && samples == params.samples */
&& progressive == params.progressive && experimental == params.experimental &&
progressive_refine == params.progressive_refine &&
/* samples == params.samples && denoising_start_sample ==
params.denoising_start_sample && */
progressive == params.progressive && experimental == params.experimental &&
tile_size == params.tile_size && start_resolution == params.start_resolution &&
pixel_size == params.pixel_size && threads == params.threads &&
use_profiling == params.use_profiling &&
@ -152,9 +155,10 @@ class Session {
bool ready_to_reset();
void reset(BufferParams &params, int samples);
void set_samples(int samples);
void set_pause(bool pause);
void set_samples(int samples);
void set_denoising(bool denoising, bool optix_denoising);
void set_denoising_start_sample(int sample);
bool update_scene();
bool load_kernels(bool lock_scene = true);