Fix #106293: Cycles importance sampling with multiple suns works poorly

Keep sun in importance map in this case, as we do not use special sun
importance sampling in this case.
This commit is contained in:
Brecht Van Lommel 2023-04-17 15:57:02 +02:00 • committed by Thomas Dinges
parent aa11cc3a48
commit 4450ec873e
4 changed files with 10 additions and 3 deletions

View file

@ -20,6 +20,7 @@ KERNEL_STRUCT_BEGIN(KernelBackground, background)
/* xyz store direction, w the angle. float4 instead of float3 is used
* to ensure consistent padding/alignment across devices. */
KERNEL_STRUCT_MEMBER(background, float4, sun)
KERNEL_STRUCT_MEMBER(background, int, use_sun_guiding)
/* Only shader index. */
KERNEL_STRUCT_MEMBER(background, int, surface_shader)
KERNEL_STRUCT_MEMBER(background, int, volume_shader)
@ -39,6 +40,10 @@ KERNEL_STRUCT_MEMBER(background, int, use_mis)
KERNEL_STRUCT_MEMBER(background, int, lightgroup)
/* Light Index. */
KERNEL_STRUCT_MEMBER(background, int, light_index)
/* Padding. */
KERNEL_STRUCT_MEMBER(integrator, int, pad1)
KERNEL_STRUCT_MEMBER(integrator, int, pad2)
KERNEL_STRUCT_MEMBER(integrator, int, pad3)
KERNEL_STRUCT_END(KernelBackground)
/* BVH: own BVH2 if no native device acceleration struct used. */

View file

@ -132,7 +132,7 @@ color sky_radiance_nishita(vector dir, float nishita_data[10], string filename)
/* definitions */
vector sun_dir = geographical_to_direction(sun_elevation, sun_rotation + M_PI_2);
float sun_dir_angle = precise_angle(dir, sun_dir);
float half_angular = angular_diameter * 0.5f;
float half_angular = angular_diameter * 0.5;
float dir_elevation = M_PI_2 - direction[0];
/* If the ray is inside the sun disc, render it, otherwise render the sky.

View file

@ -143,7 +143,8 @@ ccl_device float3 sky_radiance_nishita(KernelGlobals kg,
/* If the ray is inside the sun disc, render it, otherwise render the sky.
* Alternatively, ignore the sun if we're evaluating the background texture. */
if (sun_disc && sun_dir_angle < half_angular && !(path_flag & PATH_RAY_IMPORTANCE_BAKE)) {
if (sun_disc && sun_dir_angle < half_angular &&
!((path_flag & PATH_RAY_IMPORTANCE_BAKE) && kernel_data.background.use_sun_guiding)) {
/* get 2 pixels data */
float y;

View file

@ -772,7 +772,8 @@ void LightManager::device_update_background(Device *device,
}
/* If there's more than one sun, fall back to map sampling instead. */
if (num_suns != 1) {
kbackground->use_sun_guiding = (num_suns == 1);
if (!kbackground->use_sun_guiding) {
kbackground->sun_weight = 0.0f;
environment_res.x = max(environment_res.x, 4096);
environment_res.y = max(environment_res.y, 2048);