[Bf-blender-cvs] [5c4b97a] soc-2016-cycles_denoising: Cycles: Add options for NLM and collaborative filtering

Lukas Stockner noreply at git.blender.org
Tue Nov 22 04:25:25 CET 2016


Commit: 5c4b97a13060b1936235e19b3707ceea853ad082
Author: Lukas Stockner
Date:   Wed Nov 16 17:18:10 2016 +0100
Branches: soc-2016-cycles_denoising
https://developer.blender.org/rB5c4b97a13060b1936235e19b3707ceea853ad082

Cycles: Add options for NLM and collaborative filtering

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

M	intern/cycles/blender/addon/ui.py
M	intern/cycles/blender/blender_session.cpp
M	intern/cycles/device/device_cpu.cpp
M	intern/cycles/device/device_cuda.cpp
M	intern/cycles/kernel/kernel_types.h
M	intern/cycles/render/integrator.cpp
M	intern/cycles/render/integrator.h
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py
index 093340d..a79def8 100644
--- a/intern/cycles/blender/addon/ui.py
+++ b/intern/cycles/blender/addon/ui.py
@@ -578,6 +578,8 @@ class CyclesRender_PT_denoising(CyclesButtonsPanel, Panel):
         sub.prop(rl, "half_window")
         sub.prop(rl, "filter_strength", slider=True)
         sub.prop(rl, "filter_weighting_adjust", slider=True)
+        sub.prop(rl, "filter_collaborative")
+        sub.prop(rl, "filter_use_nlm_weights")
 
         sub = col.column(align=True)
         row = sub.row(align=True)
diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp
index edb18bf..d629e55 100644
--- a/intern/cycles/blender/blender_session.cpp
+++ b/intern/cycles/blender/blender_session.cpp
@@ -466,6 +466,8 @@ void BlenderSession::render()
 		scene->integrator->half_window = b_layer_iter->half_window();
 		scene->integrator->filter_strength = powf(2.0f, b_layer_iter->filter_strength());
 		scene->integrator->weighting_adjust = powf(2.0f, b_layer_iter->filter_weighting_adjust());
+		scene->integrator->use_nlm_weights = b_layer_iter->filter_use_nlm_weights();
+		scene->integrator->use_collaborative_filtering = b_layer_iter->filter_collaborative();
 
 		scene->film->pass_alpha_threshold = b_layer_iter->pass_alpha_threshold();
 		scene->film->tag_passes_update(scene, passes);
diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp
index 3465a10..c2b6ea7 100644
--- a/intern/cycles/device/device_cpu.cpp
+++ b/intern/cycles/device/device_cpu.cpp
@@ -434,8 +434,8 @@ public:
 	{
 		bool old_filter = getenv("OLD_FILTER");
 		bool only_nlm_filter = getenv("ONLY_NLM_FILTER");
-		bool nlm_filter = getenv("NLM_FILTER");
 		bool use_collaborative_filtering = kg->__data.integrator.use_collaborative_filtering;
+		bool nlm_weights = kg->__data.integrator.use_nlm_weights;
 
 		FilterStorage *storage = new FilterStorage[filter_area.z*filter_area.w];
 		int hw = kg->__data.integrator.half_window;
@@ -494,7 +494,7 @@ public:
 				}
 			}
 		}
-		else if(nlm_filter) {
+		else if(nlm_weights) {
 			for(int y = 0; y < filter_area.w; y++) {
 				for(int x = 0; x < filter_area.z; x++) {
 					filter_construct_transform_kernel()(kg, sample, filter_buffer, x + filter_area.x, y + filter_area.y, storage + y*filter_area.z + x, &rect.x);
diff --git a/intern/cycles/device/device_cuda.cpp b/intern/cycles/device/device_cuda.cpp
index e721118..1f2cfdc 100644
--- a/intern/cycles/device/device_cuda.cpp
+++ b/intern/cycles/device/device_cuda.cpp
@@ -1116,7 +1116,7 @@ public:
 		                           xthreads, ythreads, 1, /* threads */
 		                           0, 0, transform_args, 0));
 
-		if(getenv("NLM_FILTER")) {
+		if(kernel_globals.integrator.use_nlm_weights) {
 			void *final_args[] = {&sample,
 			                      &d_denoise_buffers,
 			                      &rtile.offset,
diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index 904598f..4ffa03d 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -1164,8 +1164,7 @@ typedef struct KernelIntegrator {
 	float filter_strength;
 	float weighting_adjust;
 	int use_collaborative_filtering;
-
-	int pad1;
+	int use_nlm_weights;
 } KernelIntegrator;
 static_assert_align(KernelIntegrator, 16);
 
diff --git a/intern/cycles/render/integrator.cpp b/intern/cycles/render/integrator.cpp
index 7af07f0..f1e84e6 100644
--- a/intern/cycles/render/integrator.cpp
+++ b/intern/cycles/render/integrator.cpp
@@ -80,6 +80,8 @@ NODE_DEFINE(Integrator)
 	SOCKET_INT(half_window, "Half Window", 8);
 	SOCKET_FLOAT(filter_strength, "Filter Strength", 0.0f);
 	SOCKET_FLOAT(weighting_adjust, "Weighting Adjust", 1.0f);
+	SOCKET_BOOLEAN(use_nlm_weights, "Use NLM weights", true);
+	SOCKET_BOOLEAN(use_collaborative_filtering, "Use Collaborative Filtering", true);
 
 	return type;
 }
@@ -210,7 +212,8 @@ void Integrator::device_update(Device *device, DeviceScene *dscene, Scene *scene
 	kintegrator->half_window = half_window;
 	kintegrator->filter_strength = filter_strength;
 	kintegrator->weighting_adjust = weighting_adjust;
-	kintegrator->use_collaborative_filtering = false;
+	kintegrator->use_collaborative_filtering = use_collaborative_filtering;
+	kintegrator->use_nlm_weights = use_nlm_weights;
 
 	need_update = false;
 }
diff --git a/intern/cycles/render/integrator.h b/intern/cycles/render/integrator.h
index 7561dbd..444b0ed 100644
--- a/intern/cycles/render/integrator.h
+++ b/intern/cycles/render/integrator.h
@@ -85,6 +85,8 @@ public:
 	int half_window;
 	float filter_strength;
 	float weighting_adjust;
+	bool use_nlm_weights;
+	bool use_collaborative_filtering;
 
 	Integrator();
 	~Integrator();
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index 103c4d1..71bee61 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -266,6 +266,8 @@ typedef enum SceneDenoiseFlag {
 	SCE_DENOISE_TRANSIND              = (1 << 7),
 	SCE_DENOISE_SUBDIR                = (1 << 8),
 	SCE_DENOISE_SUBIND                = (1 << 9),
+	SCE_DENOISE_NLM_WEIGHTS           = (1 << 10),
+	SCE_DENOISE_COLLABORATIVE         = (1 << 11),
 } SceneDenoiseFlag;
 
 /* srl->passflag */
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 0d272d1..90a7ad0 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -5018,6 +5018,16 @@ static void rna_def_scene_render_layer(BlenderRNA *brna)
 	RNA_def_property_range(prop, 1, 50);
 	RNA_def_property_ui_text(prop, "Half window", "Size of the filter window (the pixel area used for denoising one pixel). Higher values get rid of more noise, but might lose detail and are slower");
 	RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
+
+	prop = RNA_def_property(srna, "filter_use_nlm_weights", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "denoiseflag", SCE_DENOISE_NLM_WEIGHTS);
+	RNA_def_property_ui_text(prop, "Use NLM weights", "Use Non-Local means for weighting the pixels");
+	RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
+
+	prop = RNA_def_property(srna, "filter_collaborative", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "denoiseflag", SCE_DENOISE_COLLABORATIVE);
+	RNA_def_property_ui_text(prop, "Use collaborative denoising", "Use aditional predictions of neighboring pixels to get a cleaner result. Might cause visible tile borders.");
+	RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
 }
 
 /* Render Layers */




More information about the Bf-blender-cvs mailing list