From 70424195a8a68f5d08f91b5947008825af7b4ee8 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 23 Nov 2021 15:11:00 +0100 Subject: Cycles: Fix possible access to non-initialized light sample in volume Happened in barbershop file where number of bounces to the light was reached. Differential Revision: https://developer.blender.org/D13336 --- intern/cycles/kernel/integrator/shade_volume.h | 6 ++++-- intern/cycles/kernel/light/light.h | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/intern/cycles/kernel/integrator/shade_volume.h b/intern/cycles/kernel/integrator/shade_volume.h index 3a2bf04d533..cc47557d580 100644 --- a/intern/cycles/kernel/integrator/shade_volume.h +++ b/intern/cycles/kernel/integrator/shade_volume.h @@ -703,8 +703,10 @@ ccl_device_forceinline bool integrate_volume_sample_light( float light_u, light_v; path_state_rng_2D(kg, rng_state, PRNG_LIGHT_U, &light_u, &light_v); - light_distribution_sample_from_volume_segment( - kg, light_u, light_v, sd->time, sd->P, bounce, path_flag, ls); + if (!light_distribution_sample_from_volume_segment( + kg, light_u, light_v, sd->time, sd->P, bounce, path_flag, ls)) { + return false; + } if (ls->shader & SHADER_EXCLUDE_SCATTER) { return false; diff --git a/intern/cycles/kernel/light/light.h b/intern/cycles/kernel/light/light.h index 2e7f862a715..97dca936552 100644 --- a/intern/cycles/kernel/light/light.h +++ b/intern/cycles/kernel/light/light.h @@ -73,7 +73,7 @@ ccl_device_inline bool light_sample(KernelGlobals kg, ls->P = zero_float3(); ls->Ng = zero_float3(); ls->D = zero_float3(); - ls->pdf = true; + ls->pdf = 1.0f; ls->t = FLT_MAX; return true; } @@ -131,7 +131,7 @@ ccl_device_inline bool light_sample(KernelGlobals kg, float3 dir = make_float3(klight->spot.dir[0], klight->spot.dir[1], klight->spot.dir[2]); ls->eval_fac *= spot_light_attenuation( dir, klight->spot.spot_angle, klight->spot.spot_smooth, ls->Ng); - if (ls->eval_fac == 0.0f) { + if (!in_volume_segment && ls->eval_fac == 0.0f) { return false; } } @@ -170,7 +170,7 @@ ccl_device_inline bool light_sample(KernelGlobals kg, float3 sample_axisu = axisu; float3 sample_axisv = axisv; - if (klight->area.tan_spread > 0.0f) { + if (!in_volume_segment && klight->area.tan_spread > 0.0f) { if (!light_spread_clamp_area_light( P, Ng, &ls->P, &sample_axisu, &sample_axisv, klight->area.tan_spread)) { return false; @@ -203,7 +203,7 @@ ccl_device_inline bool light_sample(KernelGlobals kg, ls->pdf *= kernel_data.integrator.pdf_lights; - return (ls->pdf > 0.0f); + return in_volume_segment || (ls->pdf > 0.0f); } ccl_device bool lights_intersect(KernelGlobals kg, -- cgit v1.2.3