Blender V4.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
9/* Light Path Node */
10
11template<uint node_feature_mask, typename ConstIntegratorGenericState>
13 ConstIntegratorGenericState state,
14 ccl_private const ShaderData *sd,
15 ccl_private float *stack,
16 uint type,
17 uint out_offset,
18 uint32_t path_flag)
19{
20 float info = 0.0f;
21
22 switch (type) {
23 case NODE_LP_camera:
24 info = (path_flag & PATH_RAY_CAMERA) ? 1.0f : 0.0f;
25 break;
26 case NODE_LP_shadow:
27 info = (path_flag & PATH_RAY_SHADOW) ? 1.0f : 0.0f;
28 break;
29 case NODE_LP_diffuse:
30 info = (path_flag & PATH_RAY_DIFFUSE) ? 1.0f : 0.0f;
31 break;
32 case NODE_LP_glossy:
33 info = (path_flag & PATH_RAY_GLOSSY) ? 1.0f : 0.0f;
34 break;
36 info = (path_flag & PATH_RAY_SINGULAR) ? 1.0f : 0.0f;
37 break;
39 info = (path_flag & PATH_RAY_REFLECT) ? 1.0f : 0.0f;
40 break;
42 info = (path_flag & PATH_RAY_TRANSMIT) ? 1.0f : 0.0f;
43 break;
45 info = (path_flag & PATH_RAY_VOLUME_SCATTER) ? 1.0f : 0.0f;
46 break;
48 info = (sd->flag & SD_BACKFACING) ? 1.0f : 0.0f;
49 break;
51 info = sd->ray_length;
52 break;
53 case NODE_LP_ray_depth: {
54 /* Read bounce from difference location depending if this is a shadow
55 * path. It's a bit dubious to have integrate state details leak into
56 * this function but hard to avoid currently. */
57 IF_KERNEL_NODES_FEATURE(LIGHT_PATH)
58 {
59 info = (float)integrator_state_bounce(state, path_flag);
60 }
61
62 /* For background, light emission and shadow evaluation from a
63 * surface or volume we are effectively one bounce further. */
64 if (path_flag & (PATH_RAY_SHADOW | PATH_RAY_EMISSION)) {
65 info += 1.0f;
66 }
67 break;
68 }
70 IF_KERNEL_NODES_FEATURE(LIGHT_PATH)
71 {
73 }
74 break;
75 }
77 IF_KERNEL_NODES_FEATURE(LIGHT_PATH)
78 {
80 }
81 break;
83 IF_KERNEL_NODES_FEATURE(LIGHT_PATH)
84 {
85 info = (float)integrator_state_glossy_bounce(state, path_flag);
86 }
87 break;
89 IF_KERNEL_NODES_FEATURE(LIGHT_PATH)
90 {
92 }
93 break;
94 }
95
96 stack_store_float(stack, out_offset, info);
97}
98
99/* Light Falloff Node */
100
102 ccl_private float *stack,
103 uint4 node)
104{
105 uint strength_offset, out_offset, smooth_offset;
106
107 svm_unpack_node_uchar3(node.z, &strength_offset, &smooth_offset, &out_offset);
108
109 float strength = stack_load_float(stack, strength_offset);
110 uint type = node.y;
111
112 switch (type) {
114 break;
116 strength *= sd->ray_length;
117 break;
119 strength *= sd->ray_length * sd->ray_length;
120 break;
121 }
122
123 float smooth = stack_load_float(stack, smooth_offset);
124
125 if (smooth > 0.0f) {
126 float squared = sd->ray_length * sd->ray_length;
127 /* Distant lamps set the ray length to FLT_MAX, which causes squared to overflow. */
128 if (isfinite(squared)) {
129 strength *= squared / (smooth + squared);
130 }
131 }
132
133 stack_store_float(stack, out_offset, strength);
134}
135
unsigned int uint
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define ccl_private
#define ccl_device_noinline
#define CCL_NAMESPACE_END
draw_view in_light_buf[] float
ccl_device_forceinline void svm_unpack_node_uchar3(uint i, ccl_private uint *x, ccl_private uint *y, ccl_private uint *z)
ccl_device_inline void stack_store_float(ccl_private float *stack, uint a, float f)
ccl_device_inline float stack_load_float(ccl_private float *stack, uint a)
@ 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_LIGHT_FALLOFF_QUADRATIC
@ NODE_LIGHT_FALLOFF_LINEAR
@ NODE_LIGHT_FALLOFF_CONSTANT
@ SD_BACKFACING
#define IF_KERNEL_NODES_FEATURE(feature)
@ PATH_RAY_SHADOW
@ PATH_RAY_SINGULAR
@ PATH_RAY_REFLECT
@ PATH_RAY_TRANSMIT
@ PATH_RAY_EMISSION
@ PATH_RAY_VOLUME_SCATTER
@ PATH_RAY_GLOSSY
@ PATH_RAY_DIFFUSE
@ PATH_RAY_CAMERA
ShaderData
CCL_NAMESPACE_BEGIN ccl_device_noinline void svm_node_light_path(KernelGlobals kg, ConstIntegratorGenericState state, ccl_private const ShaderData *sd, ccl_private float *stack, uint type, uint out_offset, uint32_t path_flag)
Definition light_path.h:12
ccl_device_noinline void svm_node_light_falloff(ccl_private ShaderData *sd, ccl_private float *stack, uint4 node)
Definition light_path.h:101
static ulong state[N]
ccl_device_inline int integrator_state_bounce(ConstIntegratorState state, const int)
Definition state_util.h:454
ccl_device_inline int integrator_state_transmission_bounce(ConstIntegratorState state, const int)
Definition state_util.h:484
ccl_device_inline int integrator_state_transparent_bounce(ConstIntegratorState state, const int)
Definition state_util.h:495
ccl_device_inline int integrator_state_glossy_bounce(ConstIntegratorState state, const int)
Definition state_util.h:474
ccl_device_inline int integrator_state_diffuse_bounce(ConstIntegratorState state, const int)
Definition state_util.h:464
unsigned int uint32_t
Definition stdint.h:80