diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2017-11-07 05:28:10 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2017-11-08 00:35:12 +0300 |
commit | e74b2293422b91f8c8de8d76fcbb5241caaa7a6b (patch) | |
tree | 6666a088d7f62d48cfe741f335b56127178c57e7 | |
parent | 5f2be40658a29b44f66db6369409ac4460d2ea9e (diff) |
Fix incorrect MIS weights in Cycles with multiple lights.
This causes some difference in the classroom scene, where ray visibility
tricks are used and break the MIS balance. Otherwise there doesn't seem
to be much effect, but better to use the right formulas. Problem originally
identified by Lukas.
-rw-r--r-- | intern/cycles/kernel/kernel_light.h | 12 | ||||
-rw-r--r-- | intern/cycles/kernel/kernel_types.h | 5 | ||||
-rw-r--r-- | intern/cycles/render/light.cpp | 4 |
3 files changed, 9 insertions, 12 deletions
diff --git a/intern/cycles/kernel/kernel_light.h b/intern/cycles/kernel/kernel_light.h index c806deee8e7..dfa3150dc92 100644 --- a/intern/cycles/kernel/kernel_light.h +++ b/intern/cycles/kernel/kernel_light.h @@ -547,7 +547,7 @@ ccl_device_inline bool lamp_light_sample(KernelGlobals *kg, float costheta = dot(lightD, D); ls->pdf = invarea/(costheta*costheta*costheta); - ls->eval_fac = ls->pdf*kernel_data.integrator.inv_pdf_lights; + ls->eval_fac = ls->pdf; } #ifdef __BACKGROUND_MIS__ else if(type == LIGHT_BACKGROUND) { @@ -559,7 +559,6 @@ ccl_device_inline bool lamp_light_sample(KernelGlobals *kg, ls->D = -D; ls->t = FLT_MAX; ls->eval_fac = 1.0f; - ls->pdf *= kernel_data.integrator.pdf_lights; } #endif else { @@ -622,10 +621,10 @@ ccl_device_inline bool lamp_light_sample(KernelGlobals *kg, float invarea = data2.x; ls->eval_fac = 0.25f*invarea; } - - ls->eval_fac *= kernel_data.integrator.inv_pdf_lights; } + ls->pdf *= kernel_data.integrator.pdf_lights; + return (ls->pdf > 0.0f); } @@ -757,8 +756,11 @@ ccl_device bool lamp_light_eval(KernelGlobals *kg, int lamp, float3 P, float3 D, ls->pdf = area_light_sample(P, &light_P, axisu, axisv, 0, 0, false); ls->eval_fac = 0.25f*invarea; } - else + else { return false; + } + + ls->pdf *= kernel_data.integrator.pdf_lights; return true; } diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h index 6d177816a98..65cae035f29 100644 --- a/intern/cycles/kernel/kernel_types.h +++ b/intern/cycles/kernel/kernel_types.h @@ -1239,8 +1239,8 @@ typedef struct KernelIntegrator { int num_all_lights; float pdf_triangles; float pdf_lights; - float inv_pdf_lights; int pdf_background_res; + float light_inv_rr_threshold; /* light portals */ float portal_pdf; @@ -1298,9 +1298,8 @@ typedef struct KernelIntegrator { float volume_step_size; int volume_samples; - float light_inv_rr_threshold; - int start_sample; + int pad; } KernelIntegrator; static_assert_align(KernelIntegrator, 16); diff --git a/intern/cycles/render/light.cpp b/intern/cycles/render/light.cpp index d353709647d..b37a0768b53 100644 --- a/intern/cycles/render/light.cpp +++ b/intern/cycles/render/light.cpp @@ -414,7 +414,6 @@ void LightManager::device_update_distribution(Device *, DeviceScene *dscene, Sce /* precompute pdfs */ kintegrator->pdf_triangles = 0.0f; kintegrator->pdf_lights = 0.0f; - kintegrator->inv_pdf_lights = 0.0f; /* sample one, with 0.5 probability of light or triangle */ kintegrator->num_all_lights = num_lights; @@ -429,8 +428,6 @@ void LightManager::device_update_distribution(Device *, DeviceScene *dscene, Sce kintegrator->pdf_lights = 1.0f/num_lights; if(trianglearea > 0.0f) kintegrator->pdf_lights *= 0.5f; - - kintegrator->inv_pdf_lights = 1.0f/kintegrator->pdf_lights; } kintegrator->use_lamp_mis = use_lamp_mis; @@ -467,7 +464,6 @@ void LightManager::device_update_distribution(Device *, DeviceScene *dscene, Sce kintegrator->num_all_lights = 0; kintegrator->pdf_triangles = 0.0f; kintegrator->pdf_lights = 0.0f; - kintegrator->inv_pdf_lights = 0.0f; kintegrator->use_lamp_mis = false; kintegrator->num_portals = 0; kintegrator->portal_offset = 0; |