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