Cleanup: renaming `tan_spread` to `cot_half_spread` to avoid ambiguity
Differential Revision: https://developer.blender.org/D16695
This commit is contained in:
parent
ee89f213de
commit
f646a4f22c
|
@ -91,7 +91,7 @@ ccl_device_inline float area_light_rect_sample(float3 P,
|
||||||
|
|
||||||
ccl_device float area_light_spread_attenuation(const float3 D,
|
ccl_device float area_light_spread_attenuation(const float3 D,
|
||||||
const float3 lightNg,
|
const float3 lightNg,
|
||||||
const float tan_spread,
|
const float cot_half_spread,
|
||||||
const float normalize_spread)
|
const float normalize_spread)
|
||||||
{
|
{
|
||||||
/* Model a soft-box grid, computing the ratio of light not hidden by the
|
/* 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 cos_a = -dot(D, lightNg);
|
||||||
const float sin_a = safe_sqrtf(1.0f - sqr(cos_a));
|
const float sin_a = safe_sqrtf(1.0f - sqr(cos_a));
|
||||||
const float tan_a = sin_a / 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
|
/* 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,
|
ccl_private float *len_u,
|
||||||
const float3 axis_v,
|
const float3 axis_v,
|
||||||
ccl_private float *len_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. */
|
/* Closest point in area light plane and distance to that plane. */
|
||||||
const float3 closest_P = P - dot(lightNg, P - *lightP) * lightNg;
|
const float3 closest_P = P - dot(lightNg, P - *lightP) * lightNg;
|
||||||
const float t = len(closest_P - P);
|
const float t = len(closest_P - P);
|
||||||
|
|
||||||
/* Radius of circle on area light that actually affects the shading point. */
|
/* 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. */
|
/* Local uv coordinates of closest point. */
|
||||||
const float closest_u = dot(axis_u, closest_P - *lightP);
|
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_u = len_u;
|
||||||
float sample_len_v = len_v;
|
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,
|
if (!area_light_spread_clamp_area_light(P,
|
||||||
Ng,
|
Ng,
|
||||||
&ls->P,
|
&ls->P,
|
||||||
|
@ -194,7 +194,7 @@ ccl_device_inline bool area_light_sample(const ccl_global KernelLight *klight,
|
||||||
&sample_len_u,
|
&sample_len_u,
|
||||||
axis_v,
|
axis_v,
|
||||||
&sample_len_v,
|
&sample_len_v,
|
||||||
klight->area.tan_spread)) {
|
klight->area.cot_half_spread)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -216,10 +216,10 @@ ccl_device_inline bool area_light_sample(const ccl_global KernelLight *klight,
|
||||||
|
|
||||||
ls->eval_fac = 0.25f * invarea;
|
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 */
|
/* Area Light spread angle attenuation */
|
||||||
ls->eval_fac *= area_light_spread_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) {
|
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->D = normalize_len(ls->P - P, &ls->t);
|
||||||
ls->pdf = invarea;
|
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 = 0.25f * invarea;
|
||||||
ls->eval_fac *= area_light_spread_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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,7 +313,7 @@ ccl_device_inline bool area_light_sample_from_intersection(
|
||||||
float sample_len_u = klight->area.len_u;
|
float sample_len_u = klight->area.len_u;
|
||||||
float sample_len_v = klight->area.len_v;
|
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,
|
if (!area_light_spread_clamp_area_light(ray_P,
|
||||||
Ng,
|
Ng,
|
||||||
&light_P,
|
&light_P,
|
||||||
|
@ -321,7 +321,7 @@ ccl_device_inline bool area_light_sample_from_intersection(
|
||||||
&sample_len_u,
|
&sample_len_u,
|
||||||
axis_v,
|
axis_v,
|
||||||
&sample_len_v,
|
&sample_len_v,
|
||||||
klight->area.tan_spread)) {
|
klight->area.cot_half_spread)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,10 +331,10 @@ ccl_device_inline bool area_light_sample_from_intersection(
|
||||||
}
|
}
|
||||||
ls->eval_fac = 0.25f * invarea;
|
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 */
|
/* Area Light spread angle attenuation */
|
||||||
ls->eval_fac *= area_light_spread_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) {
|
if (ls->eval_fac == 0.0f) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1307,7 +1307,7 @@ typedef struct KernelAreaLight {
|
||||||
float len_v;
|
float len_v;
|
||||||
packed_float3 dir;
|
packed_float3 dir;
|
||||||
float invarea;
|
float invarea;
|
||||||
float tan_spread;
|
float cot_half_spread;
|
||||||
float normalize_spread;
|
float normalize_spread;
|
||||||
float pad[2];
|
float pad[2];
|
||||||
} KernelAreaLight;
|
} KernelAreaLight;
|
||||||
|
|
|
@ -1038,14 +1038,14 @@ void LightManager::device_update_lights(Device *device, DeviceScene *dscene, Sce
|
||||||
float invarea = (area != 0.0f) ? 1.0f / area : 1.0f;
|
float invarea = (area != 0.0f) ? 1.0f / area : 1.0f;
|
||||||
float3 dir = light->dir;
|
float3 dir = light->dir;
|
||||||
|
|
||||||
/* Convert from spread angle 0..180 to 90..0, clamping to a minimum
|
/* Clamping to a minimum angle to avoid excessive noise. */
|
||||||
* angle to avoid excessive noise. */
|
const float min_spread = 1.0f * M_PI_F / 180.0f;
|
||||||
const float min_spread_angle = 1.0f * M_PI_F / 180.0f;
|
const float half_spread = 0.5f * max(light->spread, min_spread);
|
||||||
const float spread_angle = 0.5f * (M_PI_F - max(light->spread, min_spread_angle));
|
/* cot_half_spread is h in D10594#269626 */
|
||||||
|
const float cot_half_spread = tanf(M_PI_2_F - half_spread);
|
||||||
/* Normalization computed using:
|
/* Normalization computed using:
|
||||||
* integrate cos(x) * (1 - tan(x) * tan(a)) * sin(x) from x = 0 to pi/2 - a. */
|
* integrate cos(x) * (1 - tan(x) / tan(a)) * sin(x) from x = 0 to a, a being half_spread */
|
||||||
const float tan_spread = tanf(spread_angle);
|
const float normalize_spread = 1.0f / (1.0f - half_spread * cot_half_spread);
|
||||||
const float normalize_spread = 2.0f / (2.0f + (2.0f * spread_angle - M_PI_F) * tan_spread);
|
|
||||||
|
|
||||||
dir = safe_normalize(dir);
|
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.len_v = len_v;
|
||||||
klights[light_index].area.invarea = invarea;
|
klights[light_index].area.invarea = invarea;
|
||||||
klights[light_index].area.dir = dir;
|
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;
|
klights[light_index].area.normalize_spread = normalize_spread;
|
||||||
}
|
}
|
||||||
else if (light->light_type == LIGHT_SPOT) {
|
else if (light->light_type == LIGHT_SPOT) {
|
||||||
|
|
Loading…
Reference in New Issue