Cycles: Support per-render layer world AO settings
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 24 Nov 2015 08:21:40 +0000 (13:21 +0500)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 24 Nov 2015 08:21:40 +0000 (13:21 +0500)
This is sort of extension of existing Use Environment option which now allows to
disable AO on the render layer basis.

Useful in cases like disabling AO for the background because it might make it
too flat and so.

Reviewers: juicyfruit, dingto, brecht

Reviewed By: brecht

Subscribers: eyecandy, venomgfx

Differential Revision: https://developer.blender.org/D1633

intern/cycles/blender/addon/ui.py
intern/cycles/blender/blender_shader.cpp
intern/cycles/blender/blender_sync.cpp
intern/cycles/blender/blender_sync.h
intern/cycles/render/background.cpp
intern/cycles/render/background.h
source/blender/makesdna/DNA_scene_types.h
source/blender/makesrna/intern/rna_scene.c

index 3678391ccd5223e5347d0d548d000b3654115617..e2aa266d53b62c539901c69da658fe26649d7965 100644 (file)
@@ -387,6 +387,7 @@ class CyclesRender_PT_layer_options(CyclesButtonsPanel, Panel):
 
         col = split.column()
         col.prop(rl, "use_sky", "Use Environment")
+        col.prop(rl, "use_ao", "Use AO")
         col.prop(rl, "use_solid", "Use Surfaces")
         col.prop(rl, "use_strand", "Use Hair")
 
index 81204aaa13a6aba209f6ac9c54e9da50cfbb1d20..5bbdeb6061bf85b4cb96dc2ddef810ba053a5536 100644 (file)
@@ -1188,7 +1188,8 @@ void BlenderSync::sync_world(bool update_all)
        else
                background->transparent = b_scene.render().alpha_mode() == BL::RenderSettings::alpha_mode_TRANSPARENT;
 
-       background->use = render_layer.use_background;
+       background->use_shader = render_layer.use_background_shader;
+       background->use_ao = render_layer.use_background_ao;
 
        if(background->modified(prevbackground))
                background->tag_update(scene);
index 986e90c59f77f70b6a7704dc295c1ef95a1340cf..4b2fa61e01cff0b82b5c889e701a997d7909c77d 100644 (file)
@@ -327,7 +327,8 @@ void BlenderSync::sync_render_layers(BL::SpaceView3D b_v3d, const char *layer)
                        render_layer.exclude_layer = 0;
                        render_layer.holdout_layer = 0;
                        render_layer.material_override = PointerRNA_NULL;
-                       render_layer.use_background = true;
+                       render_layer.use_background_shader = true;
+                       render_layer.use_background_ao = true;
                        render_layer.use_hair = true;
                        render_layer.use_surfaces = true;
                        render_layer.use_viewport_visibility = true;
@@ -359,7 +360,8 @@ void BlenderSync::sync_render_layers(BL::SpaceView3D b_v3d, const char *layer)
                        render_layer.layer |= render_layer.holdout_layer;
 
                        render_layer.material_override = b_rlay->material_override();
-                       render_layer.use_background = b_rlay->use_sky();
+                       render_layer.use_background_shader = b_rlay->use_sky();
+                       render_layer.use_background_ao = b_rlay->use_ao();
                        render_layer.use_surfaces = b_rlay->use_solid();
                        render_layer.use_hair = b_rlay->use_strand();
                        render_layer.use_viewport_visibility = false;
index efc6ae94542f4e632aebbd86d042f95bf4d03ba7..2eb153a6f74d1f1b30043aa4b2c38393811bf06d 100644 (file)
@@ -150,7 +150,8 @@ private:
                : scene_layer(0), layer(0),
                  holdout_layer(0), exclude_layer(0),
                  material_override(PointerRNA_NULL),
-                 use_background(true),
+                 use_background_shader(true),
+                 use_background_ao(true),
                  use_surfaces(true),
                  use_hair(true),
                  use_viewport_visibility(false),
@@ -164,7 +165,8 @@ private:
                uint holdout_layer;
                uint exclude_layer;
                BL::Material material_override;
-               bool use_background;
+               bool use_background_shader;
+               bool use_background_ao;
                bool use_surfaces;
                bool use_hair;
                bool use_viewport_visibility;
index 5fd7bd8f16f80f50fea6d38d60cd60b0ea582f6d..0cd164dc03ec3e28579fa64a944a8a060190526c 100644 (file)
@@ -33,7 +33,8 @@ Background::Background()
        ao_factor = 0.0f;
        ao_distance = FLT_MAX;
 
-       use = true;
+       use_shader = true;
+       use_ao = false;
 
        visibility = PATH_RAY_ALL_VISIBILITY;
        shader = 0;
@@ -53,7 +54,7 @@ void Background::device_update(Device *device, DeviceScene *dscene, Scene *scene
        
        device_free(device, dscene);
 
-       if(use)
+       if(use_shader)
                shader = scene->default_background;
        else
                shader = scene->default_empty;
@@ -61,8 +62,14 @@ void Background::device_update(Device *device, DeviceScene *dscene, Scene *scene
        /* set shader index and transparent option */
        KernelBackground *kbackground = &dscene->data.background;
 
-       kbackground->ao_factor = ao_factor;
-       kbackground->ao_distance = ao_distance;
+       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->transparent = transparent;
        kbackground->surface_shader = scene->shader_manager->get_shader_id(shader);
@@ -100,7 +107,8 @@ void Background::device_free(Device * /*device*/, DeviceScene * /*dscene*/)
 bool Background::modified(const Background& background)
 {
        return !(transparent == background.transparent &&
-               use == background.use &&
+               use_shader == background.use_shader &&
+               use_ao == background.use_ao &&
                ao_factor == background.ao_factor &&
                ao_distance == background.ao_distance &&
                visibility == background.visibility);
index 26a727291ee529e323e47506ed5b6ee015e82291..8bf97f5d6f7c3f029224ee50c3411b16aad8ff81 100644 (file)
@@ -30,7 +30,8 @@ public:
        float ao_factor;
        float ao_distance;
 
-       bool use;
+       bool use_shader;
+       bool use_ao;
 
        uint visibility;
        uint shader;
index 02a68aa84edaf5ce84de0d4d2bdfaf7903c745da..2d0a4820a516cd27b1d223d8ce14d6443ade2e78 100644 (file)
@@ -204,7 +204,8 @@ typedef struct SceneRenderLayer {
 #define SCE_LAY_SKY            16
 #define SCE_LAY_STRAND 32
 #define SCE_LAY_FRS            64
-       /* flags between 128 and 0x8000 are set to 1 already, for future options */
+#define SCE_LAY_AO             128
+       /* flags between 256 and 0x8000 are set to 1 already, for future options */
 
 #define SCE_LAY_ALL_Z          0x8000
 #define SCE_LAY_XOR                    0x10000
index d959fd08009447963eaf7cf9aca5d918d8b48328..30112885b33c3baa9fcf709958ad7f78155ac1a5 100644 (file)
@@ -2782,6 +2782,12 @@ void rna_def_render_layer_common(StructRNA *srna, int scene)
        if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
        else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 
+       prop = RNA_def_property(srna, "use_ao", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "layflag", SCE_LAY_AO);
+       RNA_def_property_ui_text(prop, "AO", "Render AO in this Layer");
+       if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
+       else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
        prop = RNA_def_property(srna, "use_edge_enhance", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "layflag", SCE_LAY_EDGE);
        RNA_def_property_ui_text(prop, "Edge", "Render Edge-enhance in this Layer (only works for Solid faces)");