2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2022-11-30 20:17:45 +01:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "kernel/geom/geom.h"
|
|
|
|
|
|
|
|
|
|
#include "kernel/light/common.h"
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
2023-07-10 12:20:47 +02:00
|
|
|
ccl_device_inline void distant_light_uv(const ccl_global KernelLight *klight,
|
|
|
|
|
const float3 D,
|
|
|
|
|
ccl_private float *u,
|
|
|
|
|
ccl_private float *v)
|
|
|
|
|
{
|
|
|
|
|
/* Map direction (x, y, z) to disk [-0.5, 0.5]^2:
|
|
|
|
|
* r^2 = (1 - z) / (1 - cos(klight->distant.angle))
|
|
|
|
|
* u_ = 0.5 * x * r / sin_angle(D, -klight->co)
|
|
|
|
|
* v_ = 0.5 * y * r / sin_angle(D, -klight->co) */
|
|
|
|
|
const float fac = klight->distant.half_inv_sin_half_angle / len(D - klight->co);
|
|
|
|
|
|
|
|
|
|
/* Get u axis and v axis. */
|
|
|
|
|
const Transform itfm = klight->itfm;
|
|
|
|
|
const float u_ = dot(D, float4_to_float3(itfm.x)) * fac;
|
|
|
|
|
const float v_ = dot(D, float4_to_float3(itfm.y)) * fac;
|
|
|
|
|
|
|
|
|
|
/* NOTE: Return barycentric coordinates in the same notation as Embree and OptiX. */
|
|
|
|
|
*u = v_ + 0.5f;
|
|
|
|
|
*v = -u_ - v_;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 20:17:45 +01:00
|
|
|
ccl_device_inline bool distant_light_sample(const ccl_global KernelLight *klight,
|
2023-05-24 18:56:58 +02:00
|
|
|
const float2 rand,
|
2022-11-30 20:17:45 +01:00
|
|
|
ccl_private LightSample *ls)
|
|
|
|
|
{
|
Cycles: Change sun lamp to have uniform intensity at high angles
This fixes the issue described in https://projects.blender.org/blender/blender/issues/108957.
Instead of modeling distant lights like a disk light at infinity, it models them as cones. This way, the radiance is constant across the entire range of directions that it covers.
For smaller angles, the difference is very subtle, but for very large angles it becomes obvious (here's the file from #108957, the angle is 179°):
| Old | New |
| - | - |
|  |  |
One notable detail is the sampling method: Using `sample_uniform_cone` can increase noise, since the sampling method no longer preserves the stratification of the samples. This is visible in the "light tree multi distant" test scene.
Turns out we can do better, and after a bit of testing I found a way to adapt the concentric Shirley mapping to uniform cone sampling. I hope the comment explains the logic behind it reasonably well.
Here's the result, note that even the noise distribution is the same when using the new sampling:
| Method | Old | New, basic sampling | New, concentric sampling |
| - | - |- | - |
| Image |  |  |  |
| Render time (at higher spp)| 9.03sec | 8.79sec | 8.96sec |
I'm not sure if I got the `light->normalized` handling right, since I don't really know what the expectation from Hydra is here.
Co-authored-by: Weizhen Huang <weizhen@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/108996
2023-07-07 17:20:19 +02:00
|
|
|
float unused;
|
2023-08-23 17:25:27 +02:00
|
|
|
ls->Ng = sample_uniform_cone(
|
|
|
|
|
klight->co, klight->distant.one_minus_cosangle, rand, &unused, &ls->pdf);
|
2022-11-30 20:17:45 +01:00
|
|
|
|
Cycles: Change sun lamp to have uniform intensity at high angles
This fixes the issue described in https://projects.blender.org/blender/blender/issues/108957.
Instead of modeling distant lights like a disk light at infinity, it models them as cones. This way, the radiance is constant across the entire range of directions that it covers.
For smaller angles, the difference is very subtle, but for very large angles it becomes obvious (here's the file from #108957, the angle is 179°):
| Old | New |
| - | - |
|  |  |
One notable detail is the sampling method: Using `sample_uniform_cone` can increase noise, since the sampling method no longer preserves the stratification of the samples. This is visible in the "light tree multi distant" test scene.
Turns out we can do better, and after a bit of testing I found a way to adapt the concentric Shirley mapping to uniform cone sampling. I hope the comment explains the logic behind it reasonably well.
Here's the result, note that even the noise distribution is the same when using the new sampling:
| Method | Old | New, basic sampling | New, concentric sampling |
| - | - |- | - |
| Image |  |  |  |
| Render time (at higher spp)| 9.03sec | 8.79sec | 8.96sec |
I'm not sure if I got the `light->normalized` handling right, since I don't really know what the expectation from Hydra is here.
Co-authored-by: Weizhen Huang <weizhen@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/108996
2023-07-07 17:20:19 +02:00
|
|
|
ls->P = ls->Ng;
|
|
|
|
|
ls->D = -ls->Ng;
|
2022-11-30 20:17:45 +01:00
|
|
|
ls->t = FLT_MAX;
|
|
|
|
|
|
Cycles: Change sun lamp to have uniform intensity at high angles
This fixes the issue described in https://projects.blender.org/blender/blender/issues/108957.
Instead of modeling distant lights like a disk light at infinity, it models them as cones. This way, the radiance is constant across the entire range of directions that it covers.
For smaller angles, the difference is very subtle, but for very large angles it becomes obvious (here's the file from #108957, the angle is 179°):
| Old | New |
| - | - |
|  |  |
One notable detail is the sampling method: Using `sample_uniform_cone` can increase noise, since the sampling method no longer preserves the stratification of the samples. This is visible in the "light tree multi distant" test scene.
Turns out we can do better, and after a bit of testing I found a way to adapt the concentric Shirley mapping to uniform cone sampling. I hope the comment explains the logic behind it reasonably well.
Here's the result, note that even the noise distribution is the same when using the new sampling:
| Method | Old | New, basic sampling | New, concentric sampling |
| - | - |- | - |
| Image |  |  |  |
| Render time (at higher spp)| 9.03sec | 8.79sec | 8.96sec |
I'm not sure if I got the `light->normalized` handling right, since I don't really know what the expectation from Hydra is here.
Co-authored-by: Weizhen Huang <weizhen@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/108996
2023-07-07 17:20:19 +02:00
|
|
|
ls->eval_fac = klight->distant.eval_fac;
|
2022-11-30 20:17:45 +01:00
|
|
|
|
2023-07-10 12:20:47 +02:00
|
|
|
distant_light_uv(klight, ls->D, &ls->u, &ls->v);
|
|
|
|
|
|
2022-11-30 20:17:45 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-24 13:36:13 +02:00
|
|
|
/* Special intersection check.
|
|
|
|
|
* Returns true if the distant_light_sample_from_intersection() for this light would return true.
|
|
|
|
|
*
|
|
|
|
|
* The intersection parameters t, u, v are optimized for the shadow ray towards a dedicated light:
|
|
|
|
|
* u = v = 0, t = FLT_MAX.
|
|
|
|
|
*/
|
|
|
|
|
ccl_device bool distant_light_intersect(const ccl_global KernelLight *klight,
|
|
|
|
|
const ccl_private Ray *ccl_restrict ray,
|
|
|
|
|
ccl_private float *t,
|
|
|
|
|
ccl_private float *u,
|
|
|
|
|
ccl_private float *v)
|
|
|
|
|
{
|
|
|
|
|
kernel_assert(klight->type == LIGHT_DISTANT);
|
|
|
|
|
|
Cycles: Change sun lamp to have uniform intensity at high angles
This fixes the issue described in https://projects.blender.org/blender/blender/issues/108957.
Instead of modeling distant lights like a disk light at infinity, it models them as cones. This way, the radiance is constant across the entire range of directions that it covers.
For smaller angles, the difference is very subtle, but for very large angles it becomes obvious (here's the file from #108957, the angle is 179°):
| Old | New |
| - | - |
|  |  |
One notable detail is the sampling method: Using `sample_uniform_cone` can increase noise, since the sampling method no longer preserves the stratification of the samples. This is visible in the "light tree multi distant" test scene.
Turns out we can do better, and after a bit of testing I found a way to adapt the concentric Shirley mapping to uniform cone sampling. I hope the comment explains the logic behind it reasonably well.
Here's the result, note that even the noise distribution is the same when using the new sampling:
| Method | Old | New, basic sampling | New, concentric sampling |
| - | - |- | - |
| Image |  |  |  |
| Render time (at higher spp)| 9.03sec | 8.79sec | 8.96sec |
I'm not sure if I got the `light->normalized` handling right, since I don't really know what the expectation from Hydra is here.
Co-authored-by: Weizhen Huang <weizhen@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/108996
2023-07-07 17:20:19 +02:00
|
|
|
if (klight->distant.angle == 0.0f) {
|
2023-05-24 13:36:13 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
Cycles: Change sun lamp to have uniform intensity at high angles
This fixes the issue described in https://projects.blender.org/blender/blender/issues/108957.
Instead of modeling distant lights like a disk light at infinity, it models them as cones. This way, the radiance is constant across the entire range of directions that it covers.
For smaller angles, the difference is very subtle, but for very large angles it becomes obvious (here's the file from #108957, the angle is 179°):
| Old | New |
| - | - |
|  |  |
One notable detail is the sampling method: Using `sample_uniform_cone` can increase noise, since the sampling method no longer preserves the stratification of the samples. This is visible in the "light tree multi distant" test scene.
Turns out we can do better, and after a bit of testing I found a way to adapt the concentric Shirley mapping to uniform cone sampling. I hope the comment explains the logic behind it reasonably well.
Here's the result, note that even the noise distribution is the same when using the new sampling:
| Method | Old | New, basic sampling | New, concentric sampling |
| - | - |- | - |
| Image |  |  |  |
| Render time (at higher spp)| 9.03sec | 8.79sec | 8.96sec |
I'm not sure if I got the `light->normalized` handling right, since I don't really know what the expectation from Hydra is here.
Co-authored-by: Weizhen Huang <weizhen@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/108996
2023-07-07 17:20:19 +02:00
|
|
|
if (vector_angle(-klight->co, ray->D) > klight->distant.angle) {
|
2023-05-24 13:36:13 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*t = FLT_MAX;
|
|
|
|
|
*u = 0.0f;
|
|
|
|
|
*v = 0.0f;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 20:17:45 +01:00
|
|
|
ccl_device bool distant_light_sample_from_intersection(KernelGlobals kg,
|
|
|
|
|
const float3 ray_D,
|
|
|
|
|
const int lamp,
|
|
|
|
|
ccl_private LightSample *ccl_restrict ls)
|
|
|
|
|
{
|
|
|
|
|
ccl_global const KernelLight *klight = &kernel_data_fetch(lights, lamp);
|
|
|
|
|
const int shader = klight->shader_id;
|
|
|
|
|
const LightType type = (LightType)klight->type;
|
|
|
|
|
|
|
|
|
|
if (type != LIGHT_DISTANT) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!(shader & SHADER_USE_MIS)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
Cycles: Change sun lamp to have uniform intensity at high angles
This fixes the issue described in https://projects.blender.org/blender/blender/issues/108957.
Instead of modeling distant lights like a disk light at infinity, it models them as cones. This way, the radiance is constant across the entire range of directions that it covers.
For smaller angles, the difference is very subtle, but for very large angles it becomes obvious (here's the file from #108957, the angle is 179°):
| Old | New |
| - | - |
|  |  |
One notable detail is the sampling method: Using `sample_uniform_cone` can increase noise, since the sampling method no longer preserves the stratification of the samples. This is visible in the "light tree multi distant" test scene.
Turns out we can do better, and after a bit of testing I found a way to adapt the concentric Shirley mapping to uniform cone sampling. I hope the comment explains the logic behind it reasonably well.
Here's the result, note that even the noise distribution is the same when using the new sampling:
| Method | Old | New, basic sampling | New, concentric sampling |
| - | - |- | - |
| Image |  |  |  |
| Render time (at higher spp)| 9.03sec | 8.79sec | 8.96sec |
I'm not sure if I got the `light->normalized` handling right, since I don't really know what the expectation from Hydra is here.
Co-authored-by: Weizhen Huang <weizhen@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/108996
2023-07-07 17:20:19 +02:00
|
|
|
if (klight->distant.angle == 0.0f) {
|
2022-11-30 20:17:45 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Workaround to prevent a hang in the classroom scene with AMD HIP drivers 22.10,
|
|
|
|
|
* Remove when a compiler fix is available. */
|
|
|
|
|
#ifdef __HIP__
|
|
|
|
|
ls->shader = klight->shader_id;
|
|
|
|
|
#endif
|
|
|
|
|
|
Cycles: Change sun lamp to have uniform intensity at high angles
This fixes the issue described in https://projects.blender.org/blender/blender/issues/108957.
Instead of modeling distant lights like a disk light at infinity, it models them as cones. This way, the radiance is constant across the entire range of directions that it covers.
For smaller angles, the difference is very subtle, but for very large angles it becomes obvious (here's the file from #108957, the angle is 179°):
| Old | New |
| - | - |
|  |  |
One notable detail is the sampling method: Using `sample_uniform_cone` can increase noise, since the sampling method no longer preserves the stratification of the samples. This is visible in the "light tree multi distant" test scene.
Turns out we can do better, and after a bit of testing I found a way to adapt the concentric Shirley mapping to uniform cone sampling. I hope the comment explains the logic behind it reasonably well.
Here's the result, note that even the noise distribution is the same when using the new sampling:
| Method | Old | New, basic sampling | New, concentric sampling |
| - | - |- | - |
| Image |  |  |  |
| Render time (at higher spp)| 9.03sec | 8.79sec | 8.96sec |
I'm not sure if I got the `light->normalized` handling right, since I don't really know what the expectation from Hydra is here.
Co-authored-by: Weizhen Huang <weizhen@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/108996
2023-07-07 17:20:19 +02:00
|
|
|
if (vector_angle(-klight->co, ray_D) > klight->distant.angle) {
|
2022-11-30 20:17:45 +01:00
|
|
|
return false;
|
Cycles: Change sun lamp to have uniform intensity at high angles
This fixes the issue described in https://projects.blender.org/blender/blender/issues/108957.
Instead of modeling distant lights like a disk light at infinity, it models them as cones. This way, the radiance is constant across the entire range of directions that it covers.
For smaller angles, the difference is very subtle, but for very large angles it becomes obvious (here's the file from #108957, the angle is 179°):
| Old | New |
| - | - |
|  |  |
One notable detail is the sampling method: Using `sample_uniform_cone` can increase noise, since the sampling method no longer preserves the stratification of the samples. This is visible in the "light tree multi distant" test scene.
Turns out we can do better, and after a bit of testing I found a way to adapt the concentric Shirley mapping to uniform cone sampling. I hope the comment explains the logic behind it reasonably well.
Here's the result, note that even the noise distribution is the same when using the new sampling:
| Method | Old | New, basic sampling | New, concentric sampling |
| - | - |- | - |
| Image |  |  |  |
| Render time (at higher spp)| 9.03sec | 8.79sec | 8.96sec |
I'm not sure if I got the `light->normalized` handling right, since I don't really know what the expectation from Hydra is here.
Co-authored-by: Weizhen Huang <weizhen@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/108996
2023-07-07 17:20:19 +02:00
|
|
|
}
|
2022-11-30 20:17:45 +01:00
|
|
|
|
|
|
|
|
ls->type = type;
|
|
|
|
|
#ifndef __HIP__
|
|
|
|
|
ls->shader = klight->shader_id;
|
|
|
|
|
#endif
|
|
|
|
|
ls->object = PRIM_NONE;
|
|
|
|
|
ls->prim = PRIM_NONE;
|
|
|
|
|
ls->lamp = lamp;
|
|
|
|
|
ls->t = FLT_MAX;
|
|
|
|
|
ls->P = -ray_D;
|
|
|
|
|
ls->Ng = -ray_D;
|
|
|
|
|
ls->D = ray_D;
|
|
|
|
|
ls->group = lamp_lightgroup(kg, lamp);
|
|
|
|
|
|
Cycles: Change sun lamp to have uniform intensity at high angles
This fixes the issue described in https://projects.blender.org/blender/blender/issues/108957.
Instead of modeling distant lights like a disk light at infinity, it models them as cones. This way, the radiance is constant across the entire range of directions that it covers.
For smaller angles, the difference is very subtle, but for very large angles it becomes obvious (here's the file from #108957, the angle is 179°):
| Old | New |
| - | - |
|  |  |
One notable detail is the sampling method: Using `sample_uniform_cone` can increase noise, since the sampling method no longer preserves the stratification of the samples. This is visible in the "light tree multi distant" test scene.
Turns out we can do better, and after a bit of testing I found a way to adapt the concentric Shirley mapping to uniform cone sampling. I hope the comment explains the logic behind it reasonably well.
Here's the result, note that even the noise distribution is the same when using the new sampling:
| Method | Old | New, basic sampling | New, concentric sampling |
| - | - |- | - |
| Image |  |  |  |
| Render time (at higher spp)| 9.03sec | 8.79sec | 8.96sec |
I'm not sure if I got the `light->normalized` handling right, since I don't really know what the expectation from Hydra is here.
Co-authored-by: Weizhen Huang <weizhen@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/108996
2023-07-07 17:20:19 +02:00
|
|
|
ls->pdf = klight->distant.pdf;
|
|
|
|
|
ls->eval_fac = klight->distant.eval_fac;
|
2022-11-30 20:17:45 +01:00
|
|
|
|
2023-07-10 12:20:47 +02:00
|
|
|
distant_light_uv(klight, ray_D, &ls->u, &ls->v);
|
|
|
|
|
|
2022-11-30 20:17:45 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2022-12-02 19:04:00 +01:00
|
|
|
|
|
|
|
|
ccl_device_forceinline bool distant_light_tree_parameters(const float3 centroid,
|
|
|
|
|
const float theta_e,
|
|
|
|
|
ccl_private float &cos_theta_u,
|
|
|
|
|
ccl_private float2 &distance,
|
|
|
|
|
ccl_private float3 &point_to_centroid)
|
|
|
|
|
{
|
|
|
|
|
/* Treating it as a disk light 1 unit away */
|
|
|
|
|
cos_theta_u = fast_cosf(theta_e);
|
|
|
|
|
|
|
|
|
|
distance = make_float2(1.0f / cos_theta_u, 1.0f);
|
|
|
|
|
|
|
|
|
|
point_to_centroid = -centroid;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 20:17:45 +01:00
|
|
|
CCL_NAMESPACE_END
|