[Bf-blender-cvs] [3668258] soc-2016-cycles_denoising: Cycles: Tweak feature pass heuristic

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


Commit: 36682585db2005b6208c2943126c8df84e9c4099
Author: Lukas Stockner
Date:   Sat Nov 19 19:18:30 2016 +0100
Branches: soc-2016-cycles_denoising
https://developer.blender.org/rB36682585db2005b6208c2943126c8df84e9c4099

Cycles: Tweak feature pass heuristic

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

M	intern/cycles/kernel/kernel_passes.h

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

diff --git a/intern/cycles/kernel/kernel_passes.h b/intern/cycles/kernel/kernel_passes.h
index cb61976..422de5e 100644
--- a/intern/cycles/kernel/kernel_passes.h
+++ b/intern/cycles/kernel/kernel_passes.h
@@ -160,23 +160,30 @@ ccl_device_inline bool kernel_write_denoising_passes(KernelGlobals *kg, ccl_glob
 
 		float3 normal = make_float3(0.0f, 0.0f, 0.0f);
 		float3 albedo = make_float3(0.0f, 0.0f, 0.0f);
-		float sum_weight = 0.0f, max_weight = 0.0f;
-		int max_weight_closure = -1;
+		float sum_weight = 0.0f, sum_nonspecular_weight = 0.0f;
 
-		/* Average normal and albedo, determine the closure with the highest weight for the roughness decision. */
 		for(int i = 0; i < ccl_fetch(sd, num_closure); i++) {
 			ShaderClosure *sc = ccl_fetch_array(sd, closure, i);
 
 			if(!CLOSURE_IS_BSDF_OR_BSSRDF(sc->type))
 				continue;
 
+			/* Classify closures into diffuse-like and specular-like closures.
+			 * This is pretty arbitrary, but some distinction has to be made. */
+			bool is_specular = (sc->type == CLOSURE_BSDF_TRANSPARENT_ID);
+			if(CLOSURE_IS_BSDF_MICROFACET(sc->type)) {
+				MicrofacetBsdf *bsdf = (MicrofacetBsdf*) sc;
+				if(bsdf->alpha_x*bsdf->alpha_y <= 0.075f*0.075f) {
+					is_specular = true;
+				}
+			}
+
+			/* All closures contribute to the normal feature, but only diffuse-like ones to the albedo. */
 			normal += sc->N * sc->sample_weight;
-			albedo += sc->weight;
 			sum_weight += sc->sample_weight;
-
-			if(sc->sample_weight > max_weight) {
-				max_weight = sc->sample_weight;
-				max_weight_closure = i;
+			if(!is_specular) {
+				albedo += sc->weight;
+				sum_nonspecular_weight += sc->sample_weight;
 			}
 		}
 
@@ -186,17 +193,10 @@ ccl_device_inline bool kernel_write_denoising_passes(KernelGlobals *kg, ccl_glob
 			kernel_write_pass_float_var(buffer + 12, sample, 0.0f);
 		}
 		else {
-			ShaderClosure *max_sc = ccl_fetch_array(sd, closure, max_weight_closure);
-			if(max_sc->type == CLOSURE_BSDF_TRANSPARENT_ID) {
+			/* Wait for next bounce if 75% or more sample weight belongs to specular-like closures. */
+			if(sum_nonspecular_weight*4.0f <= sum_weight) {
 				return false;
 			}
-			if(CLOSURE_IS_BSDF_MICROFACET(max_sc->type)) {
-				/* Check for roughness, almost specular surfaces don't write data. */
-				MicrofacetBsdf *bsdf = (MicrofacetBsdf*) max_sc;
-				if(bsdf->alpha_x*bsdf->alpha_y <= 0.075f*0.075f) {
-					return false;
-				}
-			}
 			kernel_write_pass_float3_var(buffer, sample, ensure_finite3(normal/sum_weight));
 			kernel_write_pass_float3_var(buffer + 6, sample, ensure_finite3(albedo));
 			kernel_write_pass_float_var(buffer + 12, sample, ensure_finite(state->path_length));




More information about the Bf-blender-cvs mailing list