Fix #34226: cycles shadow pass got incorrectly influenced by world multiple
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 13 Feb 2013 16:46:18 +0000 (16:46 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 13 Feb 2013 16:46:18 +0000 (16:46 +0000)
importance sampleing.

intern/cycles/device/device_cuda.cpp
intern/cycles/kernel/kernel_emission.h
intern/cycles/kernel/kernel_passes.h
intern/cycles/kernel/kernel_types.h
intern/cycles/render/light.cpp

index 0c59064..399414d 100644 (file)
@@ -109,11 +109,11 @@ public:
                }
        }
 
-#ifdef NDEBUG
+/*#ifdef NDEBUG
 #define cuda_abort()
 #else
 #define cuda_abort() abort()
-#endif
+#endif*/
 
 #define cuda_assert(stmt) \
        { \
index 3b27a1f..9787af5 100644 (file)
@@ -141,7 +141,7 @@ __device_noinline bool direct_emission(KernelGlobals *kg, ShaderData *sd, int li
        }
 
        /* return if it's a lamp for shadow pass */
-       *is_lamp = (ls.prim == ~0);
+       *is_lamp = (ls.prim == ~0 && ls.type != LIGHT_BACKGROUND);
 
        return true;
 }
index 7276393..57dbdc2 100644 (file)
@@ -125,14 +125,7 @@ __device_inline void kernel_write_light_passes(KernelGlobals *kg, __global float
                kernel_write_pass_float3(buffer + kernel_data.film.pass_transmission_color, sample, L->color_transmission);
        if(flag & PASS_SHADOW) {
                float4 shadow = L->shadow;
-
-               /* bit of an ugly hack to compensate for emitting triangles influencing
-                * amount of samples we get for this pass */
-               if(kernel_data.integrator.progressive && kernel_data.integrator.pdf_triangles != 0.0f)
-                       shadow.w = 0.5f;
-               else
-                       shadow.w = 1.0f;
-
+               shadow.w = kernel_data.film.pass_shadow_scale;
                kernel_write_pass_float4(buffer + kernel_data.film.pass_shadow, sample, shadow);
        }
 #endif
index 773ea0c..ddbda92 100644 (file)
@@ -610,9 +610,9 @@ typedef struct KernelFilm {
        int pass_ao;
 
        int pass_shadow;
+       float pass_shadow_scale;
        int pass_pad1;
        int pass_pad2;
-       int pass_pad3;
 } KernelFilm;
 
 typedef struct KernelBackground {
index e7fb951..ccc6c51 100644 (file)
@@ -143,6 +143,7 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen
 
        /* count */
        size_t num_lights = scene->lights.size();
+       size_t num_background_lights = 0;
        size_t num_triangles = 0;
        size_t num_curve_segments = 0;
 
@@ -306,6 +307,8 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen
 
                if(light->size > 0.0f && light->use_mis)
                        use_lamp_mis = true;
+               if(light->type == LIGHT_BACKGROUND)
+                       num_background_lights++;
        }
 
        /* normalize cumulative distribution functions */
@@ -324,6 +327,7 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen
 
        /* update device */
        KernelIntegrator *kintegrator = &dscene->data.integrator;
+       KernelFilm *kfilm = &dscene->data.film;
        kintegrator->use_direct_light = (totarea > 0.0f);
 
        if(kintegrator->use_direct_light) {
@@ -354,6 +358,16 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen
 
                kintegrator->use_lamp_mis = use_lamp_mis;
 
+               /* bit of an ugly hack to compensate for emitting triangles influencing
+                * amount of samples we get for this pass */
+               if(scene->integrator->progressive && kintegrator->pdf_triangles != 0.0f)
+                       kfilm->pass_shadow_scale = 0.5f;
+               else
+                       kfilm->pass_shadow_scale = 1.0f;
+
+               if(num_background_lights < num_lights)
+                       kfilm->pass_shadow_scale *= (float)(num_lights - num_background_lights)/(float)num_lights;
+
                /* CDF */
                device->tex_alloc("__light_distribution", dscene->light_distribution);
        }
@@ -366,6 +380,7 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen
                kintegrator->pdf_lights = 0.0f;
                kintegrator->inv_pdf_lights = 0.0f;
                kintegrator->use_lamp_mis = false;
+               kfilm->pass_shadow_scale = 1.0f;
        }
 }