Blender V4.3
shadow_linking.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2023 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
9
11
12#ifdef __SHADOW_LINKING__
13
14/* Check whether special shadow rays for shadow linking are needed in the current scene
15 * configuration. */
16ccl_device_forceinline bool shadow_linking_scene_need_shadow_ray(KernelGlobals kg)
17{
18 if (!(kernel_data.kernel_features & KERNEL_FEATURE_SHADOW_LINKING)) {
19 /* No shadow linking in the scene, so no need to trace any extra rays. */
20 return false;
21 }
22
23 /* The distant lights might be using shadow linking, and they are not counted as
24 * kernel_data.integrator.use_light_mis.
25 * So there is a potential to avoid extra rays from being traced, but it requires more granular
26 * flags set in the integrator. */
27
28 return true;
29}
30
31/* Shadow linking re-used the main path intersection to store information about the light to which
32 * the extra ray is to be traced (this intersection communicates light between the shadow blocker
33 * intersection and shading kernels).
34 * These utilities makes a copy of the fields from the main intersection which are needed by the
35 * intersect_closest kernel after the surface bounce. */
36
37ccl_device_forceinline void shadow_linking_store_last_primitives(IntegratorState state)
38{
39 INTEGRATOR_STATE_WRITE(state, shadow_link, last_isect_prim) = INTEGRATOR_STATE(
40 state, isect, prim);
41 INTEGRATOR_STATE_WRITE(state, shadow_link, last_isect_object) = INTEGRATOR_STATE(
42 state, isect, object);
43}
44
45ccl_device_forceinline void shadow_linking_restore_last_primitives(IntegratorState state)
46{
48 state, shadow_link, last_isect_prim);
50 state, shadow_link, last_isect_object);
51}
52
53/* Schedule shadow linking intersection kernel if it is needed.
54 * Returns true if the shadow linking specific kernel has been scheduled, false otherwise. */
55template<DeviceKernel current_kernel>
56ccl_device_inline bool shadow_linking_schedule_intersection_kernel(KernelGlobals kg,
58{
59 if (!shadow_linking_scene_need_shadow_ray(kg)) {
60 return false;
61 }
62
65
66 return true;
67}
68
69#endif /* __SHADOW_LINKING__ */
70
#define kernel_data
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define ccl_device_forceinline
#define ccl_device_inline
#define CCL_NAMESPACE_END
#define KERNEL_FEATURE_SHADOW_LINKING
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_DEDICATED_LIGHT
static ulong state[N]
IntegratorStateCPU *ccl_restrict IntegratorState
Definition state.h:228
#define INTEGRATOR_STATE_WRITE(state, nested_struct, member)
Definition state.h:236
#define INTEGRATOR_STATE(state, nested_struct, member)
Definition state.h:235
ccl_device_forceinline void integrator_path_next(KernelGlobals kg, IntegratorState state, const DeviceKernel current_kernel, const DeviceKernel next_kernel)
Definition state_flow.h:169