[Bf-blender-cvs] [b0f6fb83699] blender-v2.82-release: EEVEE: Micro optimize disk light

Clément Foucault noreply at git.blender.org
Wed Jan 29 01:02:24 CET 2020


Commit: b0f6fb83699c92b290d75bbd97776fe4c5898b58
Author: Clément Foucault
Date:   Wed Jan 29 01:01:11 2020 +0100
Branches: blender-v2.82-release
https://developer.blender.org/rBb0f6fb83699c92b290d75bbd97776fe4c5898b58

EEVEE: Micro optimize disk light

Try to never do operation twice and try to use MADD operations. Even if this
is very unlikely to make any difference, it can help compilers do some
optimization. I did not measure any difference as probes have much higher
impact on render time because of texture lookups.

Note that disk light is currently the most expensive light type so it
does not hurt to micro optimize.

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

M	source/blender/draw/engines/eevee/shaders/ltc_lib.glsl

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

diff --git a/source/blender/draw/engines/eevee/shaders/ltc_lib.glsl b/source/blender/draw/engines/eevee/shaders/ltc_lib.glsl
index 61d34e2afdc..dbfc7ad5a71 100644
--- a/source/blender/draw/engines/eevee/shaders/ltc_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/ltc_lib.glsl
@@ -47,9 +47,7 @@ vec3 solve_cubic(vec4 coefs)
   float D = coefs.x;
 
   /* Compute the Hessian and the discriminant */
-  vec3 delta = vec3(-coefs.z * coefs.z + coefs.y,
-                    -coefs.y * coefs.z + coefs.x,
-                    dot(vec2(coefs.z, -coefs.y), coefs.xy));
+  vec3 delta = vec3(-coefs.zy * coefs.zz + coefs.yx, dot(vec2(coefs.z, -coefs.y), coefs.xy));
 
   /* Discriminant */
   float discr = dot(vec2(4.0 * delta.x, -delta.y), delta.zy);
@@ -68,8 +66,9 @@ vec3 solve_cubic(vec4 coefs)
     /* Take the cubic root of a normalized complex number */
     float theta = atan(sqrt_discr, -D_a) / 3.0;
 
-    float x_1a = 2.0 * sqrt(-C_a) * cos(theta);
-    float x_3a = 2.0 * sqrt(-C_a) * cos(theta + (2.0 / 3.0) * M_PI);
+    float _2_sqrt_C_a = 2.0 * sqrt(-C_a);
+    float x_1a = _2_sqrt_C_a * cos(theta);
+    float x_3a = _2_sqrt_C_a * cos(theta + (2.0 / 3.0) * M_PI);
 
     float xl;
     if ((x_1a + x_3a) > 2.0 * B) {
@@ -91,8 +90,9 @@ vec3 solve_cubic(vec4 coefs)
     /* Take the cubic root of a normalized complex number */
     float theta = atan(D * sqrt_discr, -D_d) / 3.0;
 
-    float x_1d = 2.0 * sqrt(-C_d) * cos(theta);
-    float x_3d = 2.0 * sqrt(-C_d) * cos(theta + (2.0 / 3.0) * M_PI);
+    float _2_sqrt_C_d = 2.0 * sqrt(-C_d);
+    float x_1d = _2_sqrt_C_d * cos(theta);
+    float x_3d = _2_sqrt_C_d * cos(theta + (2.0 / 3.0) * M_PI);
 
     float xs;
     if (x_1d + x_3d < 2.0 * C) {
@@ -272,15 +272,18 @@ float ltc_evaluate_disk(vec3 N, vec3 V, mat3 Minv, vec3 disk_points[3])
   }
 
   float L = dot(V3, C);
-  float x0 = dot(V1, C) / L;
-  float y0 = dot(V2, C) / L;
+  float inv_L = 1.0 / L;
+  float x0 = dot(V1, C) * inv_L;
+  float y0 = dot(V2, C) * inv_L;
 
-  a *= L * L;
-  b *= L * L;
+  float L_sqr = L * L;
+  a *= L_sqr;
+  b *= L_sqr;
 
+  float t = 1.0 + x0 * x0;
   float c0 = a * b;
-  float c1 = a * b * (1.0 + x0 * x0 + y0 * y0) - a - b;
-  float c2 = 1.0 - a * (1.0 + x0 * x0) - b * (1.0 + y0 * y0);
+  float c1 = c0 * (t + y0 * y0) - a - b;
+  float c2 = (1.0 - a * t) - b * (1.0 + y0 * y0);
   float c3 = 1.0;
 
   vec3 roots = solve_cubic(vec4(c0, c1, c2, c3));



More information about the Bf-blender-cvs mailing list