Cycles: use AO factor to let user adjust intensity of AO bounces.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Wed, 25 Oct 2017 19:07:44 +0000 (21:07 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Wed, 25 Oct 2017 19:46:23 +0000 (21:46 +0200)
We are already using the AO distance, so might as well offer this extra
control over the intensity. Useful when an interior scene is supposed to
be significantly darker than the background shader.

intern/cycles/blender/blender_shader.cpp
intern/cycles/kernel/kernel_path.h
intern/cycles/kernel/kernel_types.h
intern/cycles/render/background.cpp
intern/cycles/render/integrator.cpp

index bdbab1006c06c5e19643ccbfbfbb243fbd149c8c..cd6c9f319db96352aaf47a9dd01f244132ca3264 100644 (file)
@@ -1289,11 +1289,8 @@ void BlenderSync::sync_world(bool update_all)
                        /* AO */
                        BL::WorldLighting b_light = b_world.light_settings();
 
-                       if(b_light.use_ambient_occlusion())
-                               background->ao_factor = b_light.ao_factor();
-                       else
-                               background->ao_factor = 0.0f;
-
+                       background->use_ao = b_light.use_ambient_occlusion();
+                       background->ao_factor = b_light.ao_factor();
                        background->ao_distance = b_light.distance();
 
                        /* visibility */
@@ -1309,6 +1306,7 @@ void BlenderSync::sync_world(bool update_all)
                        background->visibility = visibility;
                }
                else {
+                       background->use_ao = false;
                        background->ao_factor = 0.0f;
                        background->ao_distance = FLT_MAX;
                }
@@ -1330,7 +1328,7 @@ void BlenderSync::sync_world(bool update_all)
                background->transparent = b_scene.render().alpha_mode() == BL::RenderSettings::alpha_mode_TRANSPARENT;
 
        background->use_shader = render_layer.use_background_shader;
-       background->use_ao = render_layer.use_background_ao;
+       background->use_ao = background->use_ao && render_layer.use_background_ao;
 
        if(background->modified(prevbackground))
                background->tag_update(scene);
index 652777a77a095d271272758e1a112604d6f15bab..e664a2e9dbd4fa93fa215e94144655ded862fe3e 100644 (file)
@@ -145,6 +145,12 @@ ccl_device_forceinline void kernel_path_background(
                        return;
        }
 
+       /* When using the ao bounces approximation, adjust background
+        * shader intensity with ao factor. */
+       if(path_state_ao_bounce(kg, state)) {
+               throughput *= kernel_data.background.ao_bounces_factor;
+       }
+
 #ifdef __BACKGROUND__
        /* sample background shader */
        float3 L_background = indirect_background(kg, emission_sd, state, ray);
index 2ae003227dccafd248fbd610cb1426c1b88ee6d5..49ec6d97f28efbc5766e514792346c4729a915de 100644 (file)
@@ -1214,7 +1214,8 @@ typedef struct KernelBackground {
        /* ambient occlusion */
        float ao_factor;
        float ao_distance;
-       float ao_pad1, ao_pad2;
+       float ao_bounces_factor;
+       float ao_pad;
 } KernelBackground;
 static_assert_align(KernelBackground, 16);
 
index 930debe1e335eaed2a4126b8355a3352a64e0d23..3ed96732b1445c64476896b128d6da9d684bbfdf 100644 (file)
@@ -74,14 +74,9 @@ void Background::device_update(Device *device, DeviceScene *dscene, Scene *scene
        /* set shader index and transparent option */
        KernelBackground *kbackground = &dscene->data.background;
 
-       if(use_ao) {
-               kbackground->ao_factor = ao_factor;
-               kbackground->ao_distance = ao_distance;
-       }
-       else {
-               kbackground->ao_factor = 0.0f;
-               kbackground->ao_distance = FLT_MAX;
-       }
+       kbackground->ao_factor = (use_ao)? ao_factor: 0.0f;
+       kbackground->ao_bounces_factor = ao_factor;
+       kbackground->ao_distance = ao_distance;
 
        kbackground->transparent = transparent;
        kbackground->surface_shader = scene->shader_manager->get_shader_id(bg_shader);
index 33c3dac9e81560568a1d1965cd992b90edee502c..0dc1a9aa0533f45d1691d6b4b1b217dda8fc29f6 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include "device/device.h"
+#include "render/background.h"
 #include "render/integrator.h"
 #include "render/film.h"
 #include "render/light.h"