Blender  V3.3
light_path.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #pragma once
5 
7 
8 /* Light Path Node */
9 
10 template<uint node_feature_mask, typename ConstIntegratorGenericState>
12  ConstIntegratorGenericState state,
13  ccl_private const ShaderData *sd,
14  ccl_private float *stack,
15  uint type,
16  uint out_offset,
17  uint32_t path_flag)
18 {
19  float info = 0.0f;
20 
21  switch (type) {
22  case NODE_LP_camera:
23  info = (path_flag & PATH_RAY_CAMERA) ? 1.0f : 0.0f;
24  break;
25  case NODE_LP_shadow:
26  info = (path_flag & PATH_RAY_SHADOW) ? 1.0f : 0.0f;
27  break;
28  case NODE_LP_diffuse:
29  info = (path_flag & PATH_RAY_DIFFUSE) ? 1.0f : 0.0f;
30  break;
31  case NODE_LP_glossy:
32  info = (path_flag & PATH_RAY_GLOSSY) ? 1.0f : 0.0f;
33  break;
34  case NODE_LP_singular:
35  info = (path_flag & PATH_RAY_SINGULAR) ? 1.0f : 0.0f;
36  break;
37  case NODE_LP_reflection:
38  info = (path_flag & PATH_RAY_REFLECT) ? 1.0f : 0.0f;
39  break;
41  info = (path_flag & PATH_RAY_TRANSMIT) ? 1.0f : 0.0f;
42  break;
44  info = (path_flag & PATH_RAY_VOLUME_SCATTER) ? 1.0f : 0.0f;
45  break;
46  case NODE_LP_backfacing:
47  info = (sd->flag & SD_BACKFACING) ? 1.0f : 0.0f;
48  break;
49  case NODE_LP_ray_length:
50  info = sd->ray_length;
51  break;
52  case NODE_LP_ray_depth: {
53  /* Read bounce from difference location depending if this is a shadow
54  * path. It's a bit dubious to have integrate state details leak into
55  * this function but hard to avoid currently. */
56  IF_KERNEL_NODES_FEATURE(LIGHT_PATH)
57  {
58  info = (float)integrator_state_bounce(state, path_flag);
59  }
60 
61  /* For background, light emission and shadow evaluation from a
62  * surface or volume we are effectively one bounce further. */
63  if (path_flag & (PATH_RAY_SHADOW | PATH_RAY_EMISSION)) {
64  info += 1.0f;
65  }
66  break;
67  }
69  IF_KERNEL_NODES_FEATURE(LIGHT_PATH)
70  {
72  }
73  break;
74  }
76  IF_KERNEL_NODES_FEATURE(LIGHT_PATH)
77  {
78  info = (float)integrator_state_diffuse_bounce(state, path_flag);
79  }
80  break;
81  case NODE_LP_ray_glossy:
82  IF_KERNEL_NODES_FEATURE(LIGHT_PATH)
83  {
84  info = (float)integrator_state_glossy_bounce(state, path_flag);
85  }
86  break;
88  IF_KERNEL_NODES_FEATURE(LIGHT_PATH)
89  {
91  }
92  break;
93  }
94 
95  stack_store_float(stack, out_offset, info);
96 }
97 
98 /* Light Falloff Node */
99 
101  ccl_private float *stack,
102  uint4 node)
103 {
104  uint strength_offset, out_offset, smooth_offset;
105 
106  svm_unpack_node_uchar3(node.z, &strength_offset, &smooth_offset, &out_offset);
107 
108  float strength = stack_load_float(stack, strength_offset);
109  uint type = node.y;
110 
111  switch (type) {
113  break;
115  strength *= sd->ray_length;
116  break;
118  strength *= sd->ray_length * sd->ray_length;
119  break;
120  }
121 
122  float smooth = stack_load_float(stack, smooth_offset);
123 
124  if (smooth > 0.0f) {
125  float squared = sd->ray_length * sd->ray_length;
126  /* Distant lamps set the ray length to FLT_MAX, which causes squared to overflow. */
127  if (isfinite(squared)) {
128  strength *= squared / (smooth + squared);
129  }
130  }
131 
132  stack_store_float(stack, out_offset, strength);
133 }
134 
typedef float(TangentPoint)[2]
unsigned int uint
Definition: BLI_sys_types.h:67
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
#define ccl_private
Definition: cuda/compat.h:48
#define ccl_device_noinline
Definition: cuda/compat.h:40
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
OperationNode * node
const KernelGlobalsCPU *ccl_restrict KernelGlobals
const int state
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
Definition: kernel/types.h:738
#define IF_KERNEL_NODES_FEATURE(feature)
@ PATH_RAY_SHADOW
Definition: kernel/types.h:206
@ PATH_RAY_SINGULAR
Definition: kernel/types.h:199
@ PATH_RAY_REFLECT
Definition: kernel/types.h:195
@ PATH_RAY_TRANSMIT
Definition: kernel/types.h:196
@ PATH_RAY_EMISSION
Definition: kernel/types.h:255
@ PATH_RAY_VOLUME_SCATTER
Definition: kernel/types.h:201
@ PATH_RAY_GLOSSY
Definition: kernel/types.h:198
@ PATH_RAY_DIFFUSE
Definition: kernel/types.h:197
@ PATH_RAY_CAMERA
Definition: kernel/types.h:194
ShaderData
Definition: kernel/types.h:925
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:11
ccl_device_noinline void svm_node_light_falloff(ccl_private ShaderData *sd, ccl_private float *stack, uint4 node)
Definition: light_path.h:100
bool isfinite(uchar)
Definition: scene/image.cpp:31
smooth(Type::FLOAT, "mask_weight")
ccl_device_inline int integrator_state_bounce(ConstIntegratorState state, const int)
Definition: state_util.h:342
ccl_device_inline int integrator_state_transmission_bounce(ConstIntegratorState state, const int)
Definition: state_util.h:372
ccl_device_inline int integrator_state_transparent_bounce(ConstIntegratorState state, const int)
Definition: state_util.h:383
ccl_device_inline int integrator_state_glossy_bounce(ConstIntegratorState state, const int)
Definition: state_util.h:362
ccl_device_inline int integrator_state_diffuse_bounce(ConstIntegratorState state, const int)
Definition: state_util.h:352
unsigned int uint32_t
Definition: stdint.h:80