[Bf-blender-cvs] [75704091fcc] master: Cycles: add additive AO support through Fast GI settings

Brecht Van Lommel noreply at git.blender.org
Tue Oct 26 14:57:05 CEST 2021


Commit: 75704091fccb92774790f6451efe4e1d00174dad
Author: Brecht Van Lommel
Date:   Thu Oct 21 17:42:15 2021 +0200
Branches: master
https://developer.blender.org/rB75704091fccb92774790f6451efe4e1d00174dad

Cycles: add additive AO support through Fast GI settings

Add a Fast GI Method, either Replace for the existing behavior, or Add
to add ambient occlusion like the old world settings.

This replaces the old Ambient Occlusion settings in the world properties.

===================================================================

M	intern/cycles/blender/addon/properties.py
M	intern/cycles/blender/addon/ui.py
M	intern/cycles/blender/blender_shader.cpp
M	intern/cycles/integrator/path_trace_work_gpu.cpp
M	intern/cycles/kernel/integrator/integrator_shade_surface.h
M	intern/cycles/kernel/integrator/integrator_shadow_state_template.h
M	intern/cycles/kernel/kernel_accumulate.h
M	intern/cycles/kernel/kernel_shader.h
M	intern/cycles/kernel/kernel_types.h
M	intern/cycles/render/film.cpp
M	intern/cycles/render/integrator.cpp
M	intern/cycles/render/integrator.h
M	intern/cycles/render/scene.cpp
M	source/blender/makesrna/intern/rna_world.c

===================================================================

diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py
index 2a51e0be2a4..0f92238015d 100644
--- a/intern/cycles/blender/addon/properties.py
+++ b/intern/cycles/blender/addon/properties.py
@@ -125,6 +125,11 @@ enum_texture_limit = (
     ('8192', "8192", "Limit texture size to 8192 pixels", 7),
 )
 
+enum_fast_gi_method = (
+    ('REPLACE', "Replace", "Replace global illumination with ambient occlusion after a specified number of bounces"),
+    ('ADD', "Add", "Add ambient occlusion to diffuse surfaces"),
+)
+
 # NOTE: Identifiers are expected to be an upper case version of identifiers from  `Pass::get_type_enum()`
 enum_view3d_shading_render_pass = (
     ('', "General", ""),
@@ -724,6 +729,14 @@ class CyclesRenderSettings(bpy.types.PropertyGroup):
         description="Approximate diffuse indirect light with background tinted ambient occlusion. This provides fast alternative to full global illumination, for interactive viewport rendering or final renders with reduced quality",
         default=False,
     )
+
+    fast_gi_method: EnumProperty(
+        name="Fast GI Method",
+        default='REPLACE',
+        description="Fast GI approximation method",
+        items=enum_fast_gi_method
+    )
+
     ao_bounces: IntProperty(
         name="AO Bounces",
         default=1,
diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py
index 0ed2dd24f2e..facf1b08676 100644
--- a/intern/cycles/blender/addon/ui.py
+++ b/intern/cycles/blender/addon/ui.py
@@ -465,8 +465,7 @@ class CYCLES_RENDER_PT_light_paths_fast_gi(CyclesButtonsPanel, Panel):
         layout.active = cscene.use_fast_gi
 
         col = layout.column(align=True)
-        col.prop(cscene, "ao_bounces", text="Viewport Bounces")
-        col.prop(cscene, "ao_bounces_render", text="Render Bounces")
+        col.prop(cscene, "fast_gi_method", text="Method")
 
         if world:
           light = world.light_settings
@@ -474,6 +473,11 @@ class CYCLES_RENDER_PT_light_paths_fast_gi(CyclesButtonsPanel, Panel):
           col.prop(light, "ao_factor", text="AO Factor")
           col.prop(light, "distance", text="AO Distance")
 
+        if cscene.fast_gi_method == 'REPLACE':
+            col = layout.column(align=True)
+            col.prop(cscene, "ao_bounces", text="Viewport Bounces")
+            col.prop(cscene, "ao_bounces_render", text="Render Bounces")
+
 
 class CYCLES_RENDER_PT_motion_blur(CyclesButtonsPanel, Panel):
     bl_label = "Motion Blur"
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index db5eadeed56..25e7ec71577 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -1375,6 +1375,7 @@ void BlenderSync::sync_world(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d,
 {
   Background *background = scene->background;
   Integrator *integrator = scene->integrator;
+  PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
 
   BL::World b_world = b_scene.world();
 
@@ -1466,14 +1467,8 @@ void BlenderSync::sync_world(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d,
       graph->connect(background->output("Background"), out->input("Surface"));
     }
 
+    /* Visibility */
     if (b_world) {
-      /* AO */
-      BL::WorldLighting b_light = b_world.light_settings();
-
-      integrator->set_ao_factor(b_light.ao_factor());
-      integrator->set_ao_distance(b_light.distance());
-
-      /* visibility */
       PointerRNA cvisibility = RNA_pointer_get(&b_world.ptr, "cycles_visibility");
       uint visibility = 0;
 
@@ -1485,16 +1480,38 @@ void BlenderSync::sync_world(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d,
 
       background->set_visibility(visibility);
     }
-    else {
-      integrator->set_ao_factor(1.0f);
-      integrator->set_ao_distance(10.0f);
-    }
 
     shader->set_graph(graph);
     shader->tag_update(scene);
   }
 
-  PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
+  /* Fast GI */
+  if (b_world) {
+    BL::WorldLighting b_light = b_world.light_settings();
+    enum { FAST_GI_METHOD_REPLACE = 0, FAST_GI_METHOD_ADD = 1, FAST_GI_METHOD_NUM };
+
+    const bool use_fast_gi = get_boolean(cscene, "use_fast_gi");
+    if (use_fast_gi) {
+      const int fast_gi_method = get_enum(
+          cscene, "fast_gi_method", FAST_GI_METHOD_NUM, FAST_GI_METHOD_REPLACE);
+      integrator->set_ao_factor((fast_gi_method == FAST_GI_METHOD_REPLACE) ? b_light.ao_factor() :
+                                                                             0.0f);
+      integrator->set_ao_additive_factor(
+          (fast_gi_method == FAST_GI_METHOD_ADD) ? b_light.ao_factor() : 0.0f);
+    }
+    else {
+      integrator->set_ao_factor(0.0f);
+      integrator->set_ao_additive_factor(0.0f);
+    }
+
+    integrator->set_ao_distance(b_light.distance());
+  }
+  else {
+    integrator->set_ao_factor(0.0f);
+    integrator->set_ao_additive_factor(0.0f);
+    integrator->set_ao_distance(10.0f);
+  }
+
   background->set_transparent(b_scene.render().film_transparent());
 
   if (background->get_transparent()) {
diff --git a/intern/cycles/integrator/path_trace_work_gpu.cpp b/intern/cycles/integrator/path_trace_work_gpu.cpp
index 36f275e1075..605c1efca0f 100644
--- a/intern/cycles/integrator/path_trace_work_gpu.cpp
+++ b/intern/cycles/integrator/path_trace_work_gpu.cpp
@@ -1082,7 +1082,7 @@ bool PathTraceWorkGPU::kernel_creates_shadow_paths(DeviceKernel kernel)
 
 bool PathTraceWorkGPU::kernel_creates_ao_paths(DeviceKernel kernel)
 {
-  return (device_scene_->data.film.pass_ao != PASS_UNUSED) &&
+  return (device_scene_->data.kernel_features & KERNEL_FEATURE_AO) &&
          (kernel == DEVICE_KERNEL_INTEGRATOR_SHADE_SURFACE ||
           kernel == DEVICE_KERNEL_INTEGRATOR_SHADE_SURFACE_RAYTRACE);
 }
diff --git a/intern/cycles/kernel/integrator/integrator_shade_surface.h b/intern/cycles/kernel/integrator/integrator_shade_surface.h
index 3724b05c6b0..2a0bf4a3046 100644
--- a/intern/cycles/kernel/integrator/integrator_shade_surface.h
+++ b/intern/cycles/kernel/integrator/integrator_shade_surface.h
@@ -325,17 +325,25 @@ ccl_device_forceinline bool integrate_surface_volume_only_bounce(IntegratorState
 #endif
 
 #if defined(__AO__)
-ccl_device_forceinline void integrate_surface_ao_pass(
-    KernelGlobals kg,
-    IntegratorState state,
-    ccl_private const ShaderData *ccl_restrict sd,
-    ccl_private const RNGState *ccl_restrict rng_state,
-    ccl_global float *ccl_restrict render_buffer)
+ccl_device_forceinline void integrate_surface_ao(KernelGlobals kg,
+                                                 IntegratorState state,
+                                                 ccl_private const ShaderData *ccl_restrict sd,
+                                                 ccl_private const RNGState *ccl_restrict
+                                                     rng_state,
+                                                 ccl_global float *ccl_restrict render_buffer)
 {
+  if (!(kernel_data.kernel_features & KERNEL_FEATURE_AO_ADDITIVE) &&
+      !(INTEGRATOR_STATE(state, path, flag) & PATH_RAY_CAMERA)) {
+    return;
+  }
+
   float bsdf_u, bsdf_v;
   path_state_rng_2D(kg, rng_state, PRNG_BSDF_U, &bsdf_u, &bsdf_v);
 
-  const float3 ao_N = shader_bsdf_ao_normal(kg, sd);
+  float3 ao_N;
+  const float3 ao_weight = shader_bsdf_ao(
+      kg, sd, kernel_data.integrator.ao_additive_factor, &ao_N);
+
   float3 ao_D;
   float ao_pdf;
   sample_cos_hemisphere(ao_N, bsdf_u, bsdf_v, &ao_D, &ao_pdf);
@@ -379,6 +387,10 @@ ccl_device_forceinline void integrate_surface_ao_pass(
   INTEGRATOR_STATE_WRITE(shadow_state, shadow_path, bounce) = bounce;
   INTEGRATOR_STATE_WRITE(shadow_state, shadow_path, transparent_bounce) = transparent_bounce;
   INTEGRATOR_STATE_WRITE(shadow_state, shadow_path, throughput) = throughput;
+
+  if (kernel_data.kernel_features & KERNEL_FEATURE_AO_ADDITIVE) {
+    INTEGRATOR_STATE_WRITE(shadow_state, shadow_path, unshadowed_throughput) = ao_weight;
+  }
 }
 #endif /* defined(__AO__) */
 
@@ -487,10 +499,9 @@ ccl_device bool integrate_surface(KernelGlobals kg,
 
 #if defined(__AO__)
     /* Ambient occlusion pass. */
-    if ((kernel_data.film.pass_ao != PASS_UNUSED) &&
-        (INTEGRATOR_STATE(state, path, flag) & PATH_RAY_CAMERA)) {
+    if (kernel_data.kernel_features & KERNEL_FEATURE_AO) {
       PROFILING_EVENT(PROFILING_SHADE_SURFACE_AO);
-      integrate_surface_ao_pass(kg, state, &sd, &rng_state, render_buffer);
+      integrate_surface_ao(kg, state, &sd, &rng_state, render_buffer);
     }
 #endif
 
diff --git a/intern/cycles/kernel/integrator/integrator_shadow_state_template.h b/intern/cycles/kernel/integrator/integrator_shadow_state_template.h
index bc35b644ee1..1fbadde2642 100644
--- a/intern/cycles/kernel/integrator/integrator_shadow_state_template.h
+++ b/intern/cycles/kernel/integrator/integrator_shadow_state_template.h
@@ -42,7 +42,10 @@ KERNEL_STRUCT_MEMBER(shadow_path, uint32_t, flag, KERNEL_FEATURE_PATH_TRACING)
 /* Throughput. */
 KERNEL_STRUCT_MEMBER(shadow_path, float3, throughput, KERNEL_FEATURE_PATH_TRACING)
 /* Throughput for shadow pass. */
-KERNEL_STRUCT_MEMBER(shadow_path, float3, unshadowed_throughput, KERNEL_FEATURE_SHADOW_PASS)
+KERNEL_STRUCT_MEMBER(shadow_path,
+                     float3,
+                     unshadowed_throughput,
+                     KERNEL_FEATURE_SHADOW_PASS | KERNEL_FEATURE_AO_ADDITIVE)
 /* Ratio of throughput to distinguish diffuse and glossy render passes. */
 KERNEL_STRUCT_MEMBER(shadow_path, float3, diffuse_glossy_ratio, KERNEL_FEATURE_LIGHT_PASSES)
 /* Number of intersections found by ray-tracing. */
diff --git a/intern/cycles/kernel/kernel_accumulate.h b/intern/cycles/kernel/kernel_accumulate.h
index 54492bef974..c494cb4e189 100644
--- a/intern/cycles/kernel/kernel_accumulate.h
+++ b/intern/cycles/kernel/kernel_accumulate.h
@@ -410,7 +410,13 @@ ccl_device_inline void kernel_accum_light(KernelGlobals kg,
 
   /* Ambient occlusion. */
   if (path_flag & PATH_RAY_SHADOW_FOR_AO) {
-    kernel_write_pass_float3(buffer + kernel_data.film.pass_ao, contribution);
+    if ((kernel_data.kernel_features & KERNEL_FEATURE_AO_PASS) 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list