[Bf-blender-cvs] [f646a4f22c4] master: Cleanup: renaming `tan_spread` to `cot_half_spread` to avoid ambiguity

Weizhen Huang noreply at git.blender.org
Mon Dec 5 17:22:01 CET 2022


Commit: f646a4f22c422689cf7cc9c0e62f02e2976989ac
Author: Weizhen Huang
Date:   Mon Dec 5 17:02:52 2022 +0100
Branches: master
https://developer.blender.org/rBf646a4f22c422689cf7cc9c0e62f02e2976989ac

Cleanup: renaming `tan_spread` to `cot_half_spread` to avoid ambiguity

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

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

M	intern/cycles/kernel/light/area.h
M	intern/cycles/kernel/types.h
M	intern/cycles/scene/light.cpp

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

diff --git a/intern/cycles/kernel/light/area.h b/intern/cycles/kernel/light/area.h
index 16d2e2c7d3a..6d2d6ace344 100644
--- a/intern/cycles/kernel/light/area.h
+++ b/intern/cycles/kernel/light/area.h
@@ -91,7 +91,7 @@ ccl_device_inline float area_light_rect_sample(float3 P,
 
 ccl_device float area_light_spread_attenuation(const float3 D,
                                                const float3 lightNg,
-                                               const float tan_spread,
+                                               const float cot_half_spread,
                                                const float normalize_spread)
 {
   /* Model a soft-box grid, computing the ratio of light not hidden by the
@@ -99,7 +99,7 @@ ccl_device float area_light_spread_attenuation(const float3 D,
   const float cos_a = -dot(D, lightNg);
   const float sin_a = safe_sqrtf(1.0f - sqr(cos_a));
   const float tan_a = sin_a / cos_a;
-  return max((1.0f - (tan_spread * tan_a)) * normalize_spread, 0.0f);
+  return max((1.0f - (cot_half_spread * tan_a)) * normalize_spread, 0.0f);
 }
 
 /* Compute subset of area light that actually has an influence on the shading point, to
@@ -111,14 +111,14 @@ ccl_device bool area_light_spread_clamp_area_light(const float3 P,
                                                    ccl_private float *len_u,
                                                    const float3 axis_v,
                                                    ccl_private float *len_v,
-                                                   const float tan_spread)
+                                                   const float cot_half_spread)
 {
   /* Closest point in area light plane and distance to that plane. */
   const float3 closest_P = P - dot(lightNg, P - *lightP) * lightNg;
   const float t = len(closest_P - P);
 
   /* Radius of circle on area light that actually affects the shading point. */
-  const float radius = t / tan_spread;
+  const float radius = t / cot_half_spread;
 
   /* Local uv coordinates of closest point. */
   const float closest_u = dot(axis_u, closest_P - *lightP);
@@ -186,7 +186,7 @@ ccl_device_inline bool area_light_sample(const ccl_global KernelLight *klight,
     float sample_len_u = len_u;
     float sample_len_v = len_v;
 
-    if (!in_volume_segment && klight->area.tan_spread > 0.0f) {
+    if (!in_volume_segment && klight->area.cot_half_spread > 0.0f) {
       if (!area_light_spread_clamp_area_light(P,
                                               Ng,
                                               &ls->P,
@@ -194,7 +194,7 @@ ccl_device_inline bool area_light_sample(const ccl_global KernelLight *klight,
                                               &sample_len_u,
                                               axis_v,
                                               &sample_len_v,
-                                              klight->area.tan_spread)) {
+                                              klight->area.cot_half_spread)) {
         return false;
       }
     }
@@ -216,10 +216,10 @@ ccl_device_inline bool area_light_sample(const ccl_global KernelLight *klight,
 
   ls->eval_fac = 0.25f * invarea;
 
-  if (klight->area.tan_spread > 0.0f) {
+  if (klight->area.cot_half_spread > 0.0f) {
     /* Area Light spread angle attenuation */
     ls->eval_fac *= area_light_spread_attenuation(
-        ls->D, ls->Ng, klight->area.tan_spread, klight->area.normalize_spread);
+        ls->D, ls->Ng, klight->area.cot_half_spread, klight->area.normalize_spread);
   }
 
   if (is_round) {
@@ -237,10 +237,10 @@ ccl_device_forceinline void area_light_update_position(const ccl_global KernelLi
   ls->D = normalize_len(ls->P - P, &ls->t);
   ls->pdf = invarea;
 
-  if (klight->area.tan_spread > 0.f) {
+  if (klight->area.cot_half_spread > 0.f) {
     ls->eval_fac = 0.25f * invarea;
     ls->eval_fac *= area_light_spread_attenuation(
-        ls->D, ls->Ng, klight->area.tan_spread, klight->area.normalize_spread);
+        ls->D, ls->Ng, klight->area.cot_half_spread, klight->area.normalize_spread);
   }
 }
 
@@ -313,7 +313,7 @@ ccl_device_inline bool area_light_sample_from_intersection(
     float sample_len_u = klight->area.len_u;
     float sample_len_v = klight->area.len_v;
 
-    if (klight->area.tan_spread > 0.0f) {
+    if (klight->area.cot_half_spread > 0.0f) {
       if (!area_light_spread_clamp_area_light(ray_P,
                                               Ng,
                                               &light_P,
@@ -321,7 +321,7 @@ ccl_device_inline bool area_light_sample_from_intersection(
                                               &sample_len_u,
                                               axis_v,
                                               &sample_len_v,
-                                              klight->area.tan_spread)) {
+                                              klight->area.cot_half_spread)) {
         return false;
       }
     }
@@ -331,10 +331,10 @@ ccl_device_inline bool area_light_sample_from_intersection(
   }
   ls->eval_fac = 0.25f * invarea;
 
-  if (klight->area.tan_spread > 0.0f) {
+  if (klight->area.cot_half_spread > 0.0f) {
     /* Area Light spread angle attenuation */
     ls->eval_fac *= area_light_spread_attenuation(
-        ls->D, ls->Ng, klight->area.tan_spread, klight->area.normalize_spread);
+        ls->D, ls->Ng, klight->area.cot_half_spread, klight->area.normalize_spread);
     if (ls->eval_fac == 0.0f) {
       return false;
     }
diff --git a/intern/cycles/kernel/types.h b/intern/cycles/kernel/types.h
index 0f595697913..0dada42b909 100644
--- a/intern/cycles/kernel/types.h
+++ b/intern/cycles/kernel/types.h
@@ -1307,7 +1307,7 @@ typedef struct KernelAreaLight {
   float len_v;
   packed_float3 dir;
   float invarea;
-  float tan_spread;
+  float cot_half_spread;
   float normalize_spread;
   float pad[2];
 } KernelAreaLight;
diff --git a/intern/cycles/scene/light.cpp b/intern/cycles/scene/light.cpp
index 3459db6546c..2421a66d2b8 100644
--- a/intern/cycles/scene/light.cpp
+++ b/intern/cycles/scene/light.cpp
@@ -1038,14 +1038,14 @@ void LightManager::device_update_lights(Device *device, DeviceScene *dscene, Sce
       float invarea = (area != 0.0f) ? 1.0f / area : 1.0f;
       float3 dir = light->dir;
 
-      /* Convert from spread angle 0..180 to 90..0, clamping to a minimum
-       * angle to avoid excessive noise. */
-      const float min_spread_angle = 1.0f * M_PI_F / 180.0f;
-      const float spread_angle = 0.5f * (M_PI_F - max(light->spread, min_spread_angle));
+      /* Clamping to a minimum angle to avoid excessive noise. */
+      const float min_spread = 1.0f * M_PI_F / 180.0f;
+      const float half_spread = 0.5f * max(light->spread, min_spread);
+      /* cot_half_spread is h in D10594#269626 */
+      const float cot_half_spread = tanf(M_PI_2_F - half_spread);
       /* Normalization computed using:
-       * integrate cos(x) * (1 - tan(x) * tan(a)) * sin(x) from x = 0 to pi/2 - a. */
-      const float tan_spread = tanf(spread_angle);
-      const float normalize_spread = 2.0f / (2.0f + (2.0f * spread_angle - M_PI_F) * tan_spread);
+       * integrate cos(x) * (1 - tan(x) / tan(a)) * sin(x) from x = 0 to a, a being half_spread */
+      const float normalize_spread = 1.0f / (1.0f - half_spread * cot_half_spread);
 
       dir = safe_normalize(dir);
 
@@ -1059,7 +1059,7 @@ void LightManager::device_update_lights(Device *device, DeviceScene *dscene, Sce
       klights[light_index].area.len_v = len_v;
       klights[light_index].area.invarea = invarea;
       klights[light_index].area.dir = dir;
-      klights[light_index].area.tan_spread = tan_spread;
+      klights[light_index].area.cot_half_spread = cot_half_spread;
       klights[light_index].area.normalize_spread = normalize_spread;
     }
     else if (light->light_type == LIGHT_SPOT) {



More information about the Bf-blender-cvs mailing list