[Bf-blender-cvs] [bcefb202a22] master: Cycles: Save a few instructions in area light sampling

Lukas Stockner noreply at git.blender.org
Fri Jul 27 23:43:25 CEST 2018


Commit: bcefb202a2278188c0c780a6e4a3603d4d727c91
Author: Lukas Stockner
Date:   Fri Jul 27 23:30:20 2018 +0200
Branches: master
https://developer.blender.org/rBbcefb202a2278188c0c780a6e4a3603d4d727c91

Cycles: Save a few instructions in area light sampling

Just basic algebra - because all vectors have the same z coordinate, a lot of terms end up cancelling out.

Not exactly a massive improvement, but it's measurable with Branched PT and a high sample count on the lamp.

Reviewers: brecht, sergey

Reviewed By: brecht

Subscribers: swerner

Differential Revision: https://developer.blender.org/D3540

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

M	intern/cycles/kernel/kernel_light.h

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

diff --git a/intern/cycles/kernel/kernel_light.h b/intern/cycles/kernel/kernel_light.h
index a25a7e3842b..b5a777efa78 100644
--- a/intern/cycles/kernel/kernel_light.h
+++ b/intern/cycles/kernel/kernel_light.h
@@ -72,24 +72,17 @@ ccl_device_inline float area_light_sample(float3 P,
 	float y0 = dot(dir, y);
 	float x1 = x0 + axisu_len;
 	float y1 = y0 + axisv_len;
-	/* Create vectors to four vertices. */
-	float3 v00 = make_float3(x0, y0, z0);
-	float3 v01 = make_float3(x0, y1, z0);
-	float3 v10 = make_float3(x1, y0, z0);
-	float3 v11 = make_float3(x1, y1, z0);
-	/* Compute normals to edges. */
-	float3 n0 = normalize(cross(v00, v10));
-	float3 n1 = normalize(cross(v10, v11));
-	float3 n2 = normalize(cross(v11, v01));
-	float3 n3 = normalize(cross(v01, v00));
 	/* Compute internal angles (gamma_i). */
-	float g0 = safe_acosf(-dot(n0, n1));
-	float g1 = safe_acosf(-dot(n1, n2));
-	float g2 = safe_acosf(-dot(n2, n3));
-	float g3 = safe_acosf(-dot(n3, n0));
+	float4 diff = make_float4(x0, y1, x1, y0) - make_float4(x1, y0, x0, y1);
+	float4 nz = make_float4(y0, x1, y1, x0) * diff;
+	nz = nz / sqrt(sqr(z0 * diff) + sqr(nz));
+	float g0 = safe_acosf(-nz.x * nz.y);
+	float g1 = safe_acosf(-nz.y * nz.z);
+	float g2 = safe_acosf(-nz.z * nz.w);
+	float g3 = safe_acosf(-nz.w * nz.x);
 	/* Compute predefined constants. */
-	float b0 = n0.z;
-	float b1 = n2.z;
+	float b0 = nz.x;
+	float b1 = nz.z;
 	float b0sq = b0 * b0;
 	float k = M_2PI_F - g2 - g3;
 	/* Compute solid angle from internal angles. */



More information about the Bf-blender-cvs mailing list