[Bf-blender-cvs] [c986e46be70] master: Cleanup: avoid harmless but unnecessary float division by zero

Brecht Van Lommel noreply at git.blender.org
Mon Nov 30 13:40:56 CET 2020


Commit: c986e46be708f6885a9504d87f58a99259ac63c7
Author: Brecht Van Lommel
Date:   Mon Nov 30 12:21:44 2020 +0100
Branches: master
https://developer.blender.org/rBc986e46be708f6885a9504d87f58a99259ac63c7

Cleanup: avoid harmless but unnecessary float division by zero

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

M	intern/cycles/render/light.cpp

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

diff --git a/intern/cycles/render/light.cpp b/intern/cycles/render/light.cpp
index 80190dcbf82..2bde3242b26 100644
--- a/intern/cycles/render/light.cpp
+++ b/intern/cycles/render/light.cpp
@@ -551,17 +551,19 @@ static void background_cdf(
                                       cond_cdf[i * cdf_width + j - 1].x / res_x;
     }
 
-    float cdf_total = cond_cdf[i * cdf_width + res_x - 1].y +
-                      cond_cdf[i * cdf_width + res_x - 1].x / res_x;
-    float cdf_total_inv = 1.0f / cdf_total;
+    const float cdf_total = cond_cdf[i * cdf_width + res_x - 1].y +
+                            cond_cdf[i * cdf_width + res_x - 1].x / res_x;
 
     /* stuff the total into the brightness value for the last entry, because
      * we are going to normalize the CDFs to 0.0 to 1.0 afterwards */
     cond_cdf[i * cdf_width + res_x].x = cdf_total;
 
-    if (cdf_total > 0.0f)
-      for (int j = 1; j < res_x; j++)
+    if (cdf_total > 0.0f) {
+      const float cdf_total_inv = 1.0f / cdf_total;
+      for (int j = 1; j < res_x; j++) {
         cond_cdf[i * cdf_width + j].y *= cdf_total_inv;
+      }
+    }
 
     cond_cdf[i * cdf_width + res_x].y = 1.0f;
   }



More information about the Bf-blender-cvs mailing list