Blender  V3.3
shadow_catcher.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #pragma once
5 
9 
11 
12 /* Check whether current surface bounce is where path is to be split for the shadow catcher. */
15  const int object_flag)
16 {
17 #ifdef __SHADOW_CATCHER__
18  if (!kernel_data.integrator.has_shadow_catcher) {
19  return false;
20  }
21 
22  /* Check the flag first, avoiding fetches form global memory. */
23  if ((object_flag & SD_OBJECT_SHADOW_CATCHER) == 0) {
24  return false;
25  }
26  if (object_flag & SD_OBJECT_HOLDOUT_MASK) {
27  return false;
28  }
29 
30  const uint32_t path_flag = INTEGRATOR_STATE(state, path, flag);
31 
32  if ((path_flag & PATH_RAY_TRANSPARENT_BACKGROUND) == 0) {
33  /* Split only on primary rays, secondary bounces are to treat shadow catcher as a regular
34  * object. */
35  return false;
36  }
37 
38  if (path_flag & PATH_RAY_SHADOW_CATCHER_HIT) {
39  return false;
40  }
41 
42  return true;
43 #else
44  (void)object_flag;
45  return false;
46 #endif
47 }
48 
49 /* Check whether the current path can still split. */
52 {
54  return false;
55  }
56 
57  const uint32_t path_flag = INTEGRATOR_STATE(state, path, flag);
58 
59  if (path_flag & PATH_RAY_SHADOW_CATCHER_HIT) {
60  /* Shadow catcher was already hit and the state was split. No further split is allowed. */
61  return false;
62  }
63 
64  return (path_flag & PATH_RAY_TRANSPARENT_BACKGROUND) != 0;
65 }
66 
67 #ifdef __SHADOW_CATCHER__
68 
69 ccl_device_forceinline bool kernel_shadow_catcher_is_matte_path(const uint32_t path_flag)
70 {
71  return (path_flag & PATH_RAY_SHADOW_CATCHER_HIT) == 0;
72 }
73 
74 ccl_device_forceinline bool kernel_shadow_catcher_is_object_pass(const uint32_t path_flag)
75 {
76  return path_flag & PATH_RAY_SHADOW_CATCHER_PASS;
77 }
78 
79 /* Write shadow catcher passes on a bounce from the shadow catcher object. */
80 ccl_device_forceinline void kernel_write_shadow_catcher_bounce_data(
82 {
83  kernel_assert(kernel_data.film.pass_shadow_catcher_sample_count != PASS_UNUSED);
84  kernel_assert(kernel_data.film.pass_shadow_catcher_matte != PASS_UNUSED);
85 
87  const uint64_t render_buffer_offset = (uint64_t)render_pixel_index *
88  kernel_data.film.pass_stride;
89  ccl_global float *buffer = render_buffer + render_buffer_offset;
90 
91  /* Count sample for the shadow catcher object. */
92  kernel_write_pass_float(buffer + kernel_data.film.pass_shadow_catcher_sample_count, 1.0f);
93 
94  /* Since the split is done, the sample does not contribute to the matte, so accumulate it as
95  * transparency to the matte. */
96  const float3 throughput = INTEGRATOR_STATE(state, path, throughput);
97  kernel_write_pass_float(buffer + kernel_data.film.pass_shadow_catcher_matte + 3,
98  average(throughput));
99 }
100 
101 #endif /* __SHADOW_CATCHER__ */
102 
#define kernel_assert(cond)
Definition: cpu/compat.h:34
#define ccl_restrict
Definition: cuda/compat.h:50
#define ccl_device_forceinline
Definition: cuda/compat.h:35
#define ccl_device_inline
Definition: cuda/compat.h:34
#define ccl_global
Definition: cuda/compat.h:43
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
#define kernel_data
const KernelGlobalsCPU *ccl_restrict KernelGlobals
SyclQueue void void size_t num_bytes void
ccl_global float * buffer
ccl_gpu_kernel_postfix ccl_global KernelWorkTile const int ccl_global float * render_buffer
const uint64_t render_pixel_index
const int state
#define PASS_UNUSED
Definition: kernel/types.h:44
@ PATH_RAY_SHADOW_CATCHER_HIT
Definition: kernel/types.h:278
@ PATH_RAY_SHADOW_CATCHER_PASS
Definition: kernel/types.h:285
@ PATH_RAY_TRANSPARENT_BACKGROUND
Definition: kernel/types.h:235
@ SD_OBJECT_HOLDOUT_MASK
Definition: kernel/types.h:804
@ SD_OBJECT_SHADOW_CATCHER
Definition: kernel/types.h:818
ccl_device_inline float average(const float2 &a)
Definition: math_float2.h:170
ccl_device_inline bool kernel_shadow_catcher_path_can_split(KernelGlobals kg, ConstIntegratorState state)
CCL_NAMESPACE_BEGIN ccl_device_inline bool kernel_shadow_catcher_is_path_split_bounce(KernelGlobals kg, IntegratorState state, const int object_flag)
IntegratorStateCPU *ccl_restrict IntegratorState
Definition: state.h:147
const IntegratorStateCPU *ccl_restrict ConstIntegratorState
Definition: state.h:148
#define INTEGRATOR_STATE(state, nested_struct, member)
Definition: state.h:154
CCL_NAMESPACE_BEGIN ccl_device_forceinline bool integrator_path_is_terminated(ConstIntegratorState state)
Definition: state_flow.h:32
unsigned int uint32_t
Definition: stdint.h:80
unsigned __int64 uint64_t
Definition: stdint.h:90
CCL_NAMESPACE_BEGIN ccl_device_inline void kernel_write_pass_float(ccl_global float *ccl_restrict buffer, float value)
Definition: write_passes.h:12