Skip to content

Commit

Permalink
Merge remote-tracking branch 'b/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
youle31 committed Jun 22, 2023
2 parents 827180a + dc5b99f commit 24ea533
Show file tree
Hide file tree
Showing 105 changed files with 16,810 additions and 5,851 deletions.
9 changes: 4 additions & 5 deletions intern/cycles/kernel/light/area.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,13 @@ ccl_device float area_light_spread_attenuation(const float3 D,
{
/* Model a soft-box grid, computing the ratio of light not hidden by the
* slats of the grid at a given angle. (see D10594). */
const float cos_a = -dot(D, lightNg);
const float tan_a = tan_angle(-D, lightNg);

if (tan_half_spread == 0.0f) {
/* cos(0.05°) ≈ 0.9999997 */
/* The factor M_PI_F comes from integrating the radiance over the hemisphere */
return (cos_a > 0.9999997f) ? M_PI_F : 0.0f;
return (tan_a > 1e-5f) ? 0.0f : M_PI_F;
}
const float sin_a = sin_from_cos(cos_a);
const float tan_a = sin_a / cos_a;

return max((tan_half_spread - tan_a) * normalize_spread, 0.0f);
}

Expand Down
2 changes: 1 addition & 1 deletion intern/cycles/kernel/light/spot.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ccl_device float spot_light_attenuation(const ccl_global KernelSpotLight *spot,
make_float3(dot(ray, spot->axis_u), dot(ray, spot->axis_v), dot(ray, spot->dir)) /
spot->len);

return smoothstepf((scaled_ray.z - spot->cos_half_spot_angle) / spot->spot_smooth);
return smoothstepf((scaled_ray.z - spot->cos_half_spot_angle) * spot->spot_smooth);
}

template<bool in_volume_segment>
Expand Down
11 changes: 5 additions & 6 deletions intern/cycles/scene/light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1282,15 +1282,14 @@ void LightManager::device_update_lights(Device *device, DeviceScene *dscene, Sce
float invarea = (light->normalize && area != 0.0f) ? 1.0f / area : 1.0f;
float3 dir = light->dir;

/* Clamp angles in (0, 0.1) to 0.1 to prevent zero intensity due to floating-point precision
* issues, but still handles spread = 0 */
const float min_spread = 0.1f * M_PI_F / 180.0f;
const float half_spread = light->spread == 0 ? 0.0f : 0.5f * max(light->spread, min_spread);
const float half_spread = 0.5f * light->spread;
const float tan_half_spread = light->spread == M_PI_F ? FLT_MAX : tanf(half_spread);
/* Normalization computed using:
* integrate cos(x) * (1 - tan(x) / tan(a)) * sin(x) from x = 0 to a, a being half_spread.
* Divided by tan_half_spread to simplify the attenuation computation in `area.h`. */
const float normalize_spread = 1.0f / (tan_half_spread - half_spread);
/* Using third-order Taylor expansion at small angles for better accuracy. */
const float normalize_spread = half_spread > 0.05f ? 1.0f / (tan_half_spread - half_spread) :
3.0f / powf(half_spread, 3.0f);

dir = safe_normalize(dir);

Expand Down Expand Up @@ -1322,7 +1321,7 @@ void LightManager::device_update_lights(Device *device, DeviceScene *dscene, Sce
float invarea = (light->normalize && radius > 0.0f) ? 1.0f / (M_PI_F * radius * radius) :
1.0f;
float cos_half_spot_angle = cosf(light->spot_angle * 0.5f);
float spot_smooth = (1.0f - cos_half_spot_angle) * light->spot_smooth;
float spot_smooth = 1.0f / ((1.0f - cos_half_spot_angle) * light->spot_smooth);

if (light->use_mis && radius > 0.0f)
shader_id |= SHADER_USE_MIS;
Expand Down
6 changes: 6 additions & 0 deletions intern/cycles/util/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,12 @@ ccl_device_inline float precise_angle(float3 a, float3 b)
return 2.0f * atan2f(len(a - b), len(a + b));
}

/* Tangent of the angle between vectors a and b. */
ccl_device_inline float tan_angle(float3 a, float3 b)
{
return len(cross(a, b)) / dot(a, b);
}

/* Return value which is greater than the given one and is a power of two. */
ccl_device_inline uint next_power_of_two(uint x)
{
Expand Down
2 changes: 1 addition & 1 deletion locale/po/ab.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

msgid ""
msgstr ""
"Project-Id-Version: Blender 4.0.0 Alpha (b'58c6a278d3b0')\n"
"Project-Id-Version: Blender 3.6.0 Release Candidate (b'a07063e6a403')\n"
"Report-Msgid-Bugs-To: \n"
"\"POT-Creation-Date: 2019-02-25 20:41:30\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
Expand Down
Loading

0 comments on commit 24ea533

Please sign in to comment.