[Bf-blender-cvs] [5eed7cdc8c1] master: Division by zero when there are no lights and only emissive surfaces

William Leeson noreply at git.blender.org
Mon Sep 6 13:20:28 CEST 2021


Commit: 5eed7cdc8c17b96ba9fd38647e86d412e682e137
Author: William Leeson
Date:   Mon Sep 6 13:08:41 2021 +0200
Branches: master
https://developer.blender.org/rB5eed7cdc8c17b96ba9fd38647e86d412e682e137

Division by zero when there are no lights and only emissive surfaces

When rendering the test scene in T79190 which has only emissive surfaces a division by zero occurs. This is a simple patch to remove this.

Reviewed By: brecht

Maniphest Tasks: T79190

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

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

M	intern/cycles/render/light.cpp

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

diff --git a/intern/cycles/render/light.cpp b/intern/cycles/render/light.cpp
index 5290d68e75a..5f9764cd1cc 100644
--- a/intern/cycles/render/light.cpp
+++ b/intern/cycles/render/light.cpp
@@ -410,38 +410,39 @@ void LightManager::device_update_distribution(Device *,
   }
 
   float trianglearea = totarea;
-
   /* point lights */
-  float lightarea = (totarea > 0.0f) ? totarea / num_lights : 1.0f;
   bool use_lamp_mis = false;
-
   int light_index = 0;
-  foreach (Light *light, scene->lights) {
-    if (!light->is_enabled)
-      continue;
+  
+  if (num_lights > 0) {
+    float lightarea = (totarea > 0.0f) ? totarea / num_lights : 1.0f;
+    foreach (Light *light, scene->lights) {
+      if (!light->is_enabled)
+        continue;
 
-    distribution[offset].totarea = totarea;
-    distribution[offset].prim = ~light_index;
-    distribution[offset].lamp.pad = 1.0f;
-    distribution[offset].lamp.size = light->size;
-    totarea += lightarea;
+      distribution[offset].totarea = totarea;
+      distribution[offset].prim = ~light_index;
+      distribution[offset].lamp.pad = 1.0f;
+      distribution[offset].lamp.size = light->size;
+      totarea += lightarea;
 
-    if (light->light_type == LIGHT_DISTANT) {
-      use_lamp_mis |= (light->angle > 0.0f && light->use_mis);
-    }
-    else if (light->light_type == LIGHT_POINT || light->light_type == LIGHT_SPOT) {
-      use_lamp_mis |= (light->size > 0.0f && light->use_mis);
-    }
-    else if (light->light_type == LIGHT_AREA) {
-      use_lamp_mis |= light->use_mis;
-    }
-    else if (light->light_type == LIGHT_BACKGROUND) {
-      num_background_lights++;
-      background_mis |= light->use_mis;
-    }
+      if (light->light_type == LIGHT_DISTANT) {
+        use_lamp_mis |= (light->angle > 0.0f && light->use_mis);
+      }
+      else if (light->light_type == LIGHT_POINT || light->light_type == LIGHT_SPOT) {
+        use_lamp_mis |= (light->size > 0.0f && light->use_mis);
+      }
+      else if (light->light_type == LIGHT_AREA) {
+        use_lamp_mis |= light->use_mis;
+      }
+      else if (light->light_type == LIGHT_BACKGROUND) {
+        num_background_lights++;
+        background_mis |= light->use_mis;
+      }
 
-    light_index++;
-    offset++;
+      light_index++;
+      offset++;
+    }
   }
 
   /* normalize cumulative distribution functions */



More information about the Bf-blender-cvs mailing list