[Bf-blender-cvs] [3d41d0b1b57] blender-v3.4-release: Fix T100537: gaps in Cycles depth pass with transparency

Brecht Van Lommel noreply at git.blender.org
Fri Nov 18 15:57:45 CET 2022


Commit: 3d41d0b1b5779631ea3e1d6edbfd29f791ab27b1
Author: Brecht Van Lommel
Date:   Fri Nov 18 15:52:34 2022 +0100
Branches: blender-v3.4-release
https://developer.blender.org/rB3d41d0b1b5779631ea3e1d6edbfd29f791ab27b1

Fix T100537: gaps in Cycles depth pass with transparency

For some pixels with transparent surfaces, no depth value would be written
when sampling chooses a reflection/refraction BSDF instead of transparent
BSDF. Now ensure we always write at some some depth value to the pass.

This is still not ideal as the resulting depth values are noisy same as they
are for depth of field and motion blur, but at least there should be no gaps.

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

M	intern/cycles/kernel/film/data_passes.h
M	intern/cycles/kernel/film/write.h

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

diff --git a/intern/cycles/kernel/film/data_passes.h b/intern/cycles/kernel/film/data_passes.h
index efdf616749f..4a63d6f8e7f 100644
--- a/intern/cycles/kernel/film/data_passes.h
+++ b/intern/cycles/kernel/film/data_passes.h
@@ -42,27 +42,27 @@ ccl_device_inline void film_write_data_passes(KernelGlobals kg,
   ccl_global float *buffer = film_pass_pixel_render_buffer(kg, state, render_buffer);
 
   if (!(path_flag & PATH_RAY_SINGLE_PASS_DONE)) {
-    if (!(sd->flag & SD_TRANSPARENT) || kernel_data.film.pass_alpha_threshold == 0.0f ||
-        average(surface_shader_alpha(kg, sd)) >= kernel_data.film.pass_alpha_threshold) {
-      if (INTEGRATOR_STATE(state, path, sample) == 0) {
-        if (flag & PASSMASK(DEPTH)) {
-          const float depth = camera_z_depth(kg, sd->P);
-          film_write_pass_float(buffer + kernel_data.film.pass_depth, depth);
-        }
-        if (flag & PASSMASK(OBJECT_ID)) {
-          const float id = object_pass_id(kg, sd->object);
-          film_write_pass_float(buffer + kernel_data.film.pass_object_id, id);
-        }
-        if (flag & PASSMASK(MATERIAL_ID)) {
-          const float id = shader_pass_id(kg, sd);
-          film_write_pass_float(buffer + kernel_data.film.pass_material_id, id);
-        }
-        if (flag & PASSMASK(POSITION)) {
-          const float3 position = sd->P;
-          film_write_pass_float3(buffer + kernel_data.film.pass_position, position);
-        }
+    if (INTEGRATOR_STATE(state, path, sample) == 0) {
+      if (flag & PASSMASK(DEPTH)) {
+        const float depth = camera_z_depth(kg, sd->P);
+        film_overwrite_pass_float(buffer + kernel_data.film.pass_depth, depth);
+      }
+      if (flag & PASSMASK(OBJECT_ID)) {
+        const float id = object_pass_id(kg, sd->object);
+        film_overwrite_pass_float(buffer + kernel_data.film.pass_object_id, id);
+      }
+      if (flag & PASSMASK(MATERIAL_ID)) {
+        const float id = shader_pass_id(kg, sd);
+        film_overwrite_pass_float(buffer + kernel_data.film.pass_material_id, id);
       }
+      if (flag & PASSMASK(POSITION)) {
+        const float3 position = sd->P;
+        film_overwrite_pass_float3(buffer + kernel_data.film.pass_position, position);
+      }
+    }
 
+    if (!(sd->flag & SD_TRANSPARENT) || kernel_data.film.pass_alpha_threshold == 0.0f ||
+        average(surface_shader_alpha(kg, sd)) >= kernel_data.film.pass_alpha_threshold) {
       if (flag & PASSMASK(NORMAL)) {
         const float3 normal = surface_shader_average_normal(kg, sd);
         film_write_pass_float3(buffer + kernel_data.film.pass_normal, normal);
diff --git a/intern/cycles/kernel/film/write.h b/intern/cycles/kernel/film/write.h
index c630a522ee3..f1b8eeb5c13 100644
--- a/intern/cycles/kernel/film/write.h
+++ b/intern/cycles/kernel/film/write.h
@@ -12,6 +12,7 @@
 CCL_NAMESPACE_BEGIN
 
 /* Get pointer to pixel in render buffer. */
+
 ccl_device_forceinline ccl_global float *film_pass_pixel_render_buffer(
     KernelGlobals kg, ConstIntegratorState state, ccl_global float *ccl_restrict render_buffer)
 {
@@ -21,7 +22,8 @@ ccl_device_forceinline ccl_global float *film_pass_pixel_render_buffer(
   return render_buffer + render_buffer_offset;
 }
 
-/* Write to pixel. */
+/* Accumulate in passes. */
+
 ccl_device_inline void film_write_pass_float(ccl_global float *ccl_restrict buffer, float value)
 {
 #ifdef __ATOMIC_PASS_WRITE__
@@ -74,6 +76,25 @@ ccl_device_inline void film_write_pass_float4(ccl_global float *ccl_restrict buf
 #endif
 }
 
+/* Overwrite for passes that only write on sample 0. This assumes only a single thread will write
+ * to this pixel and no atomics are needed. */
+
+ccl_device_inline void film_overwrite_pass_float(ccl_global float *ccl_restrict buffer,
+                                                 float value)
+{
+  *buffer = value;
+}
+
+ccl_device_inline void film_overwrite_pass_float3(ccl_global float *ccl_restrict buffer,
+                                                  float3 value)
+{
+  buffer[0] = value.x;
+  buffer[1] = value.y;
+  buffer[2] = value.z;
+}
+
+/* Read back from passes. */
+
 ccl_device_inline float kernel_read_pass_float(ccl_global float *ccl_restrict buffer)
 {
   return *buffer;



More information about the Bf-blender-cvs mailing list