Blender V5.0
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
7#include "kernel/svm/util.h"
8
10
11/* Light Path Node */
12
13template<uint node_feature_mask, typename ConstIntegratorGenericState>
15 ConstIntegratorGenericState state,
16 const ccl_private ShaderData *sd,
17 ccl_private float *stack,
18 const uint type,
19 const uint out_offset,
20 const uint32_t path_flag)
21{
22 float info = 0.0f;
23
24 switch ((NodeLightPath)type) {
25 case NODE_LP_camera:
26 info = (path_flag & PATH_RAY_CAMERA) ? 1.0f : 0.0f;
27 break;
28 case NODE_LP_shadow:
29 info = (path_flag & PATH_RAY_SHADOW) ? 1.0f : 0.0f;
30 break;
31 case NODE_LP_diffuse:
32 info = (path_flag & PATH_RAY_DIFFUSE) ? 1.0f : 0.0f;
33 break;
34 case NODE_LP_glossy:
35 info = (path_flag & PATH_RAY_GLOSSY) ? 1.0f : 0.0f;
36 break;
38 info = (path_flag & PATH_RAY_SINGULAR) ? 1.0f : 0.0f;
39 break;
41 info = (path_flag & PATH_RAY_REFLECT) ? 1.0f : 0.0f;
42 break;
44 info = (path_flag & PATH_RAY_TRANSMIT) ? 1.0f : 0.0f;
45 break;
47 info = (path_flag & PATH_RAY_VOLUME_SCATTER) ? 1.0f : 0.0f;
48 break;
50 info = (sd->flag & SD_BACKFACING) ? 1.0f : 0.0f;
51 break;
53 info = sd->ray_length;
54 break;
55 case NODE_LP_ray_depth: {
56 /* Read bounce from different locations depending on if this is a shadow
57 * path. It's a bit dubious to have integrate state details leak into
58 * this function but hard to avoid currently. */
59 IF_KERNEL_NODES_FEATURE(LIGHT_PATH)
60 {
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_flag & (PATH_RAY_SHADOW | PATH_RAY_EMISSION)) {
67 info += 1.0f;
68 }
69 break;
70 }
72 IF_KERNEL_NODES_FEATURE(LIGHT_PATH)
73 {
75 }
76 break;
77 }
79 IF_KERNEL_NODES_FEATURE(LIGHT_PATH)
80 {
82 }
83 break;
85 IF_KERNEL_NODES_FEATURE(LIGHT_PATH)
86 {
87 info = (float)integrator_state_glossy_bounce(state, path_flag);
88 }
89 break;
91 IF_KERNEL_NODES_FEATURE(LIGHT_PATH)
92 {
94 }
95 break;
97 IF_KERNEL_NODES_FEATURE(LIGHT_PATH)
98 {
99 info = (float)integrator_state_portal_bounce(kg, state, path_flag);
100 }
101 break;
102 }
103
104 stack_store_float(stack, out_offset, info);
105}
106
107/* Light Falloff Node */
108
110 ccl_private float *stack,
111 const uint4 node)
112{
113 uint strength_offset;
114 uint out_offset;
115 uint smooth_offset;
116
117 svm_unpack_node_uchar3(node.z, &strength_offset, &smooth_offset, &out_offset);
118
119 float strength = stack_load_float(stack, strength_offset);
120 if (sd->ray_length == FLT_MAX) {
121 /* Distant lights (which have a ray_length of FLT_MAX) overflow when using most outputs of
122 * the light falloff node. So just ignore the node in that case. */
123 stack_store_float(stack, out_offset, strength);
124 return;
125 }
126
127 const uint type = node.y;
128
129 switch ((NodeLightFalloff)type) {
131 break;
133 strength *= sd->ray_length;
134 break;
136 strength *= sd->ray_length * sd->ray_length;
137 break;
138 }
139
140 const float smooth = stack_load_float(stack, smooth_offset);
141
142 if (smooth > 0.0f) {
143 const float squared = sd->ray_length * sd->ray_length;
144 strength *= squared / (smooth + squared);
145 }
146
147 stack_store_float(stack, out_offset, strength);
148}
149
unsigned int uint
nullptr float
ccl_device_inline float stack_load_float(const ccl_private float *stack, const uint a)
ccl_device_inline void stack_store_float(ccl_private float *stack, const uint a, const float f)
ccl_device_forceinline void svm_unpack_node_uchar3(const uint i, ccl_private uint *x, ccl_private uint *y, ccl_private uint *z)
#define IF_KERNEL_NODES_FEATURE(feature)
#define ccl_private
const ThreadKernelGlobalsCPU * KernelGlobals
#define ccl_device_noinline
#define CCL_NAMESPACE_END
NodeLightPath
@ 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
NodeLightFalloff
@ NODE_LIGHT_FALLOFF_QUADRATIC
@ NODE_LIGHT_FALLOFF_LINEAR
@ NODE_LIGHT_FALLOFF_CONSTANT
@ SD_BACKFACING
@ 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
CCL_NAMESPACE_BEGIN ccl_device_noinline void svm_node_light_path(KernelGlobals kg, ConstIntegratorGenericState state, const ccl_private ShaderData *sd, ccl_private float *stack, const uint type, const uint out_offset, const uint32_t path_flag)
Definition light_path.h:14
ccl_device_noinline void svm_node_light_falloff(ccl_private ShaderData *sd, ccl_private float *stack, const uint4 node)
Definition light_path.h:109
static ulong state[N]
ccl_device_inline int integrator_state_bounce(ConstIntegratorState state, const int)
Definition state_util.h:475
ccl_device_inline int integrator_state_transmission_bounce(ConstIntegratorState state, const int)
Definition state_util.h:510
ccl_device_inline int integrator_state_transparent_bounce(ConstIntegratorState state, const int)
Definition state_util.h:522
ccl_device_inline int integrator_state_glossy_bounce(ConstIntegratorState state, const int)
Definition state_util.h:498
ccl_device_inline int integrator_state_diffuse_bounce(ConstIntegratorState state, const int)
Definition state_util.h:486
ccl_device_inline int integrator_state_portal_bounce(KernelGlobals kg, ConstIntegratorState state, const int)
Definition state_util.h:534
#define FLT_MAX
Definition stdcycles.h:14
uint y
Definition types_uint4.h:13
uint z
Definition types_uint4.h:13