[Bf-blender-cvs] [525cda0972a] soc-2022-many-lights-sampling: Fix: many lights oversamples subdivided surfaces

Jeffrey Liu noreply at git.blender.org
Sat Jul 23 19:06:38 CEST 2022


Commit: 525cda0972ac2ebe97d7ec46d74805687225a707
Author: Jeffrey Liu
Date:   Sat Jul 23 12:45:02 2022 -0400
Branches: soc-2022-many-lights-sampling
https://developer.blender.org/rB525cda0972ac2ebe97d7ec46d74805687225a707

Fix: many lights oversamples subdivided surfaces

This issue is resolved by accounting for area in the energy calculation.
This way subdivided surfaces will have the same total energy as a
regular surface.

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

M	intern/cycles/scene/light_tree.cpp

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

diff --git a/intern/cycles/scene/light_tree.cpp b/intern/cycles/scene/light_tree.cpp
index 2db19912f50..e05b1ca029f 100644
--- a/intern/cycles/scene/light_tree.cpp
+++ b/intern/cycles/scene/light_tree.cpp
@@ -204,20 +204,22 @@ float LightTreePrimitive::calculate_energy(Scene *scene) const
       strength = make_float3(1.0f);
     }
 
-    const Transform &tfm = object->get_tfm();
-    float3 p[3] = {mesh->get_verts()[triangle.v[0]],
+     float3 p[3] = {mesh->get_verts()[triangle.v[0]],
                    mesh->get_verts()[triangle.v[1]],
                    mesh->get_verts()[triangle.v[2]]};
 
-    for (int i = 0; i < 3; i++) {
-      p[i] = transform_point(&tfm, p[i]);
+    /* instanced mesh lights have not applied their transform at this point.
+     * in this case, these points have to be transformed to get the proper
+     * spatial bound. */
+    if (!mesh->transform_applied) {
+      const Transform &tfm = object->get_tfm();
+      for (int i = 0; i < 3; i++) {
+        p[i] = transform_point(&tfm, p[i]);
+      }
     }
 
-    // float area = triangle_area(p[0], p[1], p[2]);
-
-    /* to-do: Past GSoC work also multiplies this by 4, but not sure why. Further investigation
-     * required. */
-    // strength *= area * 4;
+    float area = triangle_area(p[0], p[1], p[2]);
+    strength *= area;
   }
   else {
     Light *lamp = scene->lights[lamp_id];



More information about the Bf-blender-cvs mailing list