Blender V5.3
light_path.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
8#include "kernel/svm/util.h"
9
11
12/* Light Path Node */
13
14template<uint64_t node_feature_mask, typename ConstIntegratorGenericState>
16 ConstIntegratorGenericState state,
17 const ccl_private ShaderData *sd,
18 ccl_private float *ccl_restrict stack,
20 const PathRayVisibility path_visibility,
21 const uint32_t path_flag)
22{
23 float info = 0.0f;
24
25 switch (node.path_type) {
26 case NODE_LP_camera:
27 info = (path_visibility & PATH_RAY_VISIBILITY_CAMERA) ? 1.0f : 0.0f;
28 break;
29 case NODE_LP_shadow:
30 info = (path_visibility & PATH_RAY_VISIBILITY_SHADOW) ? 1.0f : 0.0f;
31 break;
32 case NODE_LP_diffuse:
33 info = (path_visibility & PATH_RAY_VISIBILITY_DIFFUSE) ? 1.0f : 0.0f;
34 break;
35 case NODE_LP_glossy:
36 info = (path_visibility & PATH_RAY_VISIBILITY_GLOSSY) ? 1.0f : 0.0f;
37 break;
39 info = (path_flag & PATH_RAY_SINGULAR) ? 1.0f : 0.0f;
40 break;
42 info = (path_flag & PATH_RAY_REFLECT) ? 1.0f : 0.0f;
43 break;
45 info = (path_visibility & PATH_RAY_VISIBILITY_TRANSMIT) ? 1.0f : 0.0f;
46 break;
48 info = (path_visibility & PATH_RAY_VISIBILITY_VOLUME_SCATTER) ? 1.0f : 0.0f;
49 break;
51 info = (sd->runtime_flag & SR_BACKFACING) ? 1.0f : 0.0f;
52 break;
54 info = sd->ray_length;
55 break;
56 case NODE_LP_ray_depth: {
57 /* Read bounce from different locations depending on if this is a shadow
58 * path. It's a bit dubious to have integrate state details leak into
59 * this function but hard to avoid currently. */
60 IF_KERNEL_NODES_FEATURE (LIGHT_PATH) {
61 info = (float)integrator_state_bounce(state, path_flag);
62 }
63
64 /* For background, light emission and shadow evaluation from a
65 * surface or volume we are effectively one bounce further. */
66 if ((path_visibility & PATH_RAY_VISIBILITY_SHADOW) || (path_flag & PATH_RAY_EMISSION)) {
67 info += 1.0f;
68 }
69 break;
70 }
72 IF_KERNEL_NODES_FEATURE (LIGHT_PATH) {
74 }
75 break;
76 }
78 IF_KERNEL_NODES_FEATURE (LIGHT_PATH) {
80 }
81 break;
83 IF_KERNEL_NODES_FEATURE (LIGHT_PATH) {
84 info = (float)integrator_state_glossy_bounce(state, path_flag);
85 }
86 break;
88 IF_KERNEL_NODES_FEATURE (LIGHT_PATH) {
90 }
91 break;
93 IF_KERNEL_NODES_FEATURE (LIGHT_PATH) {
94 info = (float)integrator_state_portal_bounce(kg, state, path_flag);
95 }
96 break;
97 }
98
99 stack_store_float(stack, node.out_offset, info);
100}
101
102/* Light Falloff Node */
103
105 ccl_private float *ccl_restrict stack,
107 node)
108{
109 float strength = stack_load(stack, node.strength);
110 if (sd->ray_length == FLT_MAX) {
111 /* Distant lights (which have a ray_length of FLT_MAX) overflow when using most outputs of
112 * the light falloff node. So just ignore the node in that case. */
113 stack_store_float(stack, node.out_offset, strength);
114 return;
115 }
116
117 switch (node.falloff_type) {
119 break;
121 strength *= sd->ray_length;
122 break;
124 strength *= sd->ray_length * sd->ray_length;
125 break;
126 }
127
128 const float smooth = stack_load(stack, node.smooth);
129
130 if (smooth > 0.0f) {
131 const float squared = sd->ray_length * sd->ray_length;
132 strength *= squared / (smooth + squared);
133 }
134
135 stack_store_float(stack, node.out_offset, strength);
136}
137
ccl_device_inline void stack_store_float(ccl_private float *stack, const uint a, const float f)
ccl_device_inline T stack_load(const ccl_private float *stack, const uint a)
#define ccl_restrict
#define IF_KERNEL_NODES_FEATURE(feature)
#define ccl_private
#define ccl_global
#define ccl_device_noinline
#define CCL_NAMESPACE_END
#define FLT_MAX
#define smooth
const int state
@ NODE_LIGHT_FALLOFF_QUADRATIC
@ NODE_LIGHT_FALLOFF_LINEAR
@ NODE_LIGHT_FALLOFF_CONSTANT
@ NODE_LP_ray_depth
@ NODE_LP_shadow
@ NODE_LP_backfacing
@ NODE_LP_ray_glossy
@ NODE_LP_camera
@ NODE_LP_glossy
@ NODE_LP_transmission
@ NODE_LP_singular
@ NODE_LP_diffuse
@ NODE_LP_ray_diffuse
@ NODE_LP_volume_scatter
@ NODE_LP_ray_transmission
@ NODE_LP_ray_length
@ NODE_LP_ray_transparent
@ NODE_LP_reflection
@ NODE_LP_ray_portal
uint32_t PathRayVisibility
@ SR_BACKFACING
@ PATH_RAY_SINGULAR
@ PATH_RAY_REFLECT
@ PATH_RAY_EMISSION
@ PATH_RAY_VISIBILITY_VOLUME_SCATTER
@ PATH_RAY_VISIBILITY_CAMERA
@ PATH_RAY_VISIBILITY_TRANSMIT
@ PATH_RAY_VISIBILITY_SHADOW
@ PATH_RAY_VISIBILITY_DIFFUSE
@ PATH_RAY_VISIBILITY_GLOSSY
ccl_device_noinline void svm_node_light_falloff(ccl_private ShaderData *sd, ccl_private float *ccl_restrict stack, const ccl_global SVMNodeLightFalloff &ccl_restrict node)
Definition light_path.h:104
CCL_NAMESPACE_BEGIN ccl_device_noinline void svm_node_light_path(KernelGlobals kg, ConstIntegratorGenericState state, const ccl_private ShaderData *sd, ccl_private float *ccl_restrict stack, const ccl_global SVMNodeLightPath &ccl_restrict node, const PathRayVisibility path_visibility, const uint32_t path_flag)
Definition light_path.h:15
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ccl_device_inline int integrator_state_transmission_bounce(ConstIntegratorState state, const uint32_t)
Definition state_util.h:693
ccl_device_inline int integrator_state_diffuse_bounce(ConstIntegratorState state, const uint32_t)
Definition state_util.h:669
ccl_device_inline int integrator_state_bounce(ConstIntegratorState state, const uint32_t)
Definition state_util.h:657
ccl_device_inline int integrator_state_portal_bounce(KernelGlobals kg, ConstIntegratorState state, const uint32_t)
Definition state_util.h:717
ccl_device_inline int integrator_state_glossy_bounce(ConstIntegratorState state, const uint32_t)
Definition state_util.h:681
ccl_device_inline int integrator_state_transparent_bounce(ConstIntegratorState state, const uint32_t)
Definition state_util.h:705