diff options
author | William Leeson <leesonw> | 2021-09-06 14:08:41 +0300 |
---|---|---|
committer | William Leeson <william@blender.org> | 2021-09-06 14:14:46 +0300 |
commit | 5eed7cdc8c17b96ba9fd38647e86d412e682e137 (patch) | |
tree | 1aa64f5d26bb3e37a257f9e758fc994e1f20df05 /intern/cycles/render | |
parent | e2bbb5b07edba855b3360ecd6ecd9b6bdb0646f1 (diff) |
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
Diffstat (limited to 'intern/cycles/render')
-rw-r--r-- | intern/cycles/render/light.cpp | 53 |
1 files changed, 27 insertions, 26 deletions
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 */ |