[Bf-blender-cvs] [a8fe3a1] master: Fix T47461: Different results on CPU and GPU when using Branched Path Tracing

Lukas Stockner noreply at git.blender.org
Thu Feb 18 01:24:13 CET 2016


Commit: a8fe3a1ceef31ca39a455fee25bc1e361e1048ff
Author: Lukas Stockner
Date:   Thu Feb 18 01:13:07 2016 +0100
Branches: master
https://developer.blender.org/rBa8fe3a1ceef31ca39a455fee25bc1e361e1048ff

Fix T47461: Different results on CPU and GPU when using Branched Path Tracing

The issue here was actually somewhere else - the attached scene from the report used a light falloff node in a sunlamp (aka distant light).
However, since distant lamps set the ray length to FLT_MAX and the light falloff node squares this value, it overflows and produces a NaN
weight, which propagates and leads to a NaN intensity, which is then clamped to zero and produces the black pixels.

To fix that issue, the smoothing part of the light falloff is just ignored if the smoothing term isn't finite (which makes sense since
the term should converge to 1 as the distance increases).
The reason for the different results on CPUs and GPUs is not perfectly clear, but probably can be explained with different handling of
Inf/NaN edge cases.

Also, to notice issues like these faster in the future, kernel_asserts were added that evaluate as false as soon as a non-finite intensity is produced.

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

M	intern/cycles/kernel/kernel_accumulate.h
M	intern/cycles/kernel/svm/svm_light_path.h

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

diff --git a/intern/cycles/kernel/kernel_accumulate.h b/intern/cycles/kernel/kernel_accumulate.h
index 29eca86..5f5a360 100644
--- a/intern/cycles/kernel/kernel_accumulate.h
+++ b/intern/cycles/kernel/kernel_accumulate.h
@@ -378,6 +378,7 @@ ccl_device_inline float3 path_radiance_clamp_and_sum(KernelGlobals *kg, PathRadi
 
 		/* Reject invalid value */
 		if(!isfinite(sum)) {
+			kernel_assert(!"Non-finite sum in path_radiance_clamp_and_sum!");
 			L_sum = make_float3(0.0f, 0.0f, 0.0f);
 
 			L->direct_diffuse = make_float3(0.0f, 0.0f, 0.0f);
@@ -445,8 +446,10 @@ ccl_device_inline float3 path_radiance_clamp_and_sum(KernelGlobals *kg, PathRadi
 
 	/* Reject invalid value */
 	float sum = fabsf((L_sum).x) + fabsf((L_sum).y) + fabsf((L_sum).z);
-	if(!isfinite(sum))
+	if(!isfinite(sum)) {
+		kernel_assert(!"Non-finite final sum in path_radiance_clamp_and_sum!");
 		L_sum = make_float3(0.0f, 0.0f, 0.0f);
+	}
 
 	return L_sum;
 }
diff --git a/intern/cycles/kernel/svm/svm_light_path.h b/intern/cycles/kernel/svm/svm_light_path.h
index 94c9fdd..f35ea05 100644
--- a/intern/cycles/kernel/svm/svm_light_path.h
+++ b/intern/cycles/kernel/svm/svm_light_path.h
@@ -62,7 +62,10 @@ ccl_device void svm_node_light_falloff(ShaderData *sd, float *stack, uint4 node)
 
 	if(smooth > 0.0f) {
 		float squared = ccl_fetch(sd, ray_length)*ccl_fetch(sd, ray_length);
-		strength *= squared/(smooth + squared);
+		/* Distant lamps set the ray length to FLT_MAX, which causes squared to overflow. */
+		if(isfinite(squared)) {
+			strength *= squared/(smooth + squared);
+		}
 	}
 
 	stack_store_float(stack, out_offset, strength);




More information about the Bf-blender-cvs mailing list