[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58086] trunk/blender/intern/cycles: Fix #36064: cycles direct/ indirect light passes with materials that have zero

Brecht Van Lommel brechtvanlommel at pandora.be
Tue Jul 9 01:31:46 CEST 2013


Revision: 58086
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58086
Author:   blendix
Date:     2013-07-08 23:31:45 +0000 (Mon, 08 Jul 2013)
Log Message:
-----------
Fix #36064: cycles direct/indirect light passes with materials that have zero
RGB color components gave non-grey results when you might no expect it.

What happens is that some of the color channels are zero in the direct light
pass because their channel is zero in the color pass. The direct light pass is
defined as lighting divided by the color pass, and we can't divide by zero. We
do a division after all samples are added together to ensure that multiplication
in the compositor gives the exact combined pass even with antialiasing, DoF, ..

Found a simple tweak here, instead of setting such channels to zero it will set
it to the average of other non-zero color channels, which makes the results look
like the expected grey.

Modified Paths:
--------------
    trunk/blender/intern/cycles/render/buffers.cpp
    trunk/blender/intern/cycles/util/util_math.h

Modified: trunk/blender/intern/cycles/render/buffers.cpp
===================================================================
--- trunk/blender/intern/cycles/render/buffers.cpp	2013-07-08 22:57:51 UTC (rev 58085)
+++ trunk/blender/intern/cycles/render/buffers.cpp	2013-07-08 23:31:45 UTC (rev 58086)
@@ -223,7 +223,7 @@
 					float3 f = make_float3(in[0], in[1], in[2]);
 					float3 f_divide = make_float3(in_divide[0], in_divide[1], in_divide[2]);
 
-					f = safe_divide_color(f*exposure, f_divide);
+					f = safe_divide_even_color(f*exposure, f_divide);
 
 					pixels[0] = f.x;
 					pixels[1] = f.y;

Modified: trunk/blender/intern/cycles/util/util_math.h
===================================================================
--- trunk/blender/intern/cycles/util/util_math.h	2013-07-08 22:57:51 UTC (rev 58085)
+++ trunk/blender/intern/cycles/util/util_math.h	2013-07-08 23:31:45 UTC (rev 58086)
@@ -1100,6 +1100,42 @@
 	return make_float3(x, y, z);
 }
 
+__device_inline float3 safe_divide_even_color(float3 a, float3 b)
+{
+	float x, y, z;
+
+	x = (b.x != 0.0f)? a.x/b.x: 0.0f;
+	y = (b.y != 0.0f)? a.y/b.y: 0.0f;
+	z = (b.z != 0.0f)? a.z/b.z: 0.0f;
+
+	/* try to get grey even if b is zero */
+	if(b.x == 0.0f) {
+		if(b.y == 0.0f) {
+			x = z;
+			y = z;
+		}
+		else if(b.z == 0.0f) {
+			x = y;
+			z = y;
+		}
+		else
+			x = 0.5f*(y + z);
+	}
+	else if(b.y == 0.0f) {
+		if(b.z == 0.0f) {
+			y = x;
+			z = x;
+		}
+		else
+			y = 0.5f*(x + z);
+	}
+	else if(b.z == 0.0f) {
+		z = 0.5f*(x + y);
+	}
+
+	return make_float3(x, y, z);
+}
+
 /* Rotation of point around axis and angle */
 
 __device_inline float3 rotate_around_axis(float3 p, float3 axis, float angle)




More information about the Bf-blender-cvs mailing list