Commit: 24fa92f23e5fa64ef9f0535fade02248fbacbbd6
Author: Alaska
Date:   Fri Oct 7 13:44:21 2022 +0200
Branches: soc-2022-many-lights-sampling
https://developer.blender.org/rB24fa92f23e5fa64ef9f0535fade02248fbacbbd6

Fix distant lights energy calculation

We currently have an issue where distance lights are infrequently
sampled when using Many Lights Sampling.
One cause for this is that distance lights are assigned relatively
low importance compared to other light types with the same
lighting contribution to a given object/material.

This appears to be because we are using the "strength" of the distant
light as our energy when in fact we should be using the energy, which
is roughly `4pi * strength`.

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

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

M       intern/cycles/scene/light.cpp

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

diff --git a/intern/cycles/scene/light.cpp b/intern/cycles/scene/light.cpp
index 9dd2c3bb5e3..2a266e1815e 100644
--- a/intern/cycles/scene/light.cpp
+++ b/intern/cycles/scene/light.cpp
@@ -521,9 +521,9 @@ void LightManager::device_update_distribution(Device 
*device,
       /* Lights in this group are either a background or distant light. */
       light_tree_distant_group[index].prim_id = ~prim.prim_id;
 
-      float energy = 0.0f;
+      float strength = 0.0f;
       if (light->light_type == LIGHT_BACKGROUND) {
-        energy = average_background_energy(device, dscene, progress, scene, 
light);
+        strength = average_background_energy(device, dscene, progress, scene, 
light);
 
         /* We can set an arbitrary direction for the background light. */
         light_bounds.axis[0] = 0.0f;
@@ -534,7 +534,7 @@ void LightManager::device_update_distribution(Device 
*device,
         light_bounds.theta_o = M_PI_F;
       }
       else {
-        energy = prim.calculate_energy(scene);
+        strength = prim.calculate_energy(scene);
         for (int i = 0; i < 3; i++) {
           light_bounds.axis[i] = -light->dir[i];
         }
@@ -546,7 +546,10 @@ void LightManager::device_update_distribution(Device 
*device,
         light_tree_distant_group[index].direction[i] = light_bounds.axis[i];
       }
       light_tree_distant_group[index].bounding_radius = light_bounds.theta_o;
-
+      /* We multiply the strength of distance lights by 4pi so it more closely 
matches the
+       * energy output of other light types.
+       * TODO: validate if this is correct*/
+      float energy = strength * M_4PI_F;
       light_tree_distant_group[index].energy = energy;
       light_array[~prim.prim_id] = index;

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to