Blender V5.3
cycles/kernel/light/common.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/types.h"
8
10
12
13/* Result from light sampling with next event estimation.
14 *
15 * TODO: It may be possible to reduce the size of this struct now that shader evaluation
16 * no longer uses this. For example D, Ng or P, though it's not trivial. */
18 float3 P; /* position on light, or direction for distant light */
19 packed_float3 Ng; /* normal on light */
20 float t; /* distance to light (FLT_MAX for distant light) */
21 float3 D; /* direction from shading point to light */
22 float pdf; /* pdf for selecting light and point on light */
23 float pdf_selection; /* pdf for selecting light */
24 float eval_fac; /* intensity multiplier (normalization, spot falloff) */
25 int object; /* object id for triangle/curve lights */
26 int prim; /* lamp id for lights, primitive id for triangle/curve lights */
27 int shader; /* shader id */
28 int group; /* lightgroup */
29 LightType type; /* type of light */
30 int emitter_id; /* index in the emitter array */
31};
32
33/* Result of evaluating a light from an intersection. */
34struct LightEval {
35 float eval_fac = 0.0f; /* Intensity multiplier (normalization, spot falloff) */
36 float pdf = 0.0f; /* PDF for light sampling with next event estimation sampling. */
37};
38
39/* Utilities */
40
42{
43 const float2 uv = sample_uniform_disk(rand);
44 return ru * uv.x + rv * uv.y;
45}
46
48{
49 return ru * (2.0f * rand.x - 1.0f) + rv * (2.0f * rand.y - 1.0f);
50}
51
53{
54 float3 ru;
55 float3 rv;
56
57 make_orthonormals(n, &ru, &rv);
58
59 return ellipse_sample(ru, rv, rand);
60}
61
62ccl_device float light_pdf_area_to_solid_angle(const float3 Ng, const float3 I, const float t)
63{
64 const float cos_pi = dot(Ng, I);
65
66 if (cos_pi <= 0.0f) {
67 return 0.0f;
68 }
69
70 return t * t / cos_pi;
71}
72
73/* Visibility flag om the light shader. */
75 const PathRayVisibility path_visibility,
76 const uint32_t path_flag)
77{
78 if ((shader & SHADER_EXCLUDE_ANY) == 0) {
79 return true;
80 }
81
82 if (((shader & SHADER_EXCLUDE_DIFFUSE) && (path_visibility & PATH_RAY_VISIBILITY_DIFFUSE)) ||
83 ((shader & SHADER_EXCLUDE_GLOSSY) &&
84 ((path_visibility & PATH_RAY_VISIBILITY_GLOSSY) && (path_flag & PATH_RAY_REFLECT))) ||
85 ((shader & SHADER_EXCLUDE_TRANSMIT) && (path_visibility & PATH_RAY_VISIBILITY_TRANSMIT)) ||
86 ((shader & SHADER_EXCLUDE_CAMERA) && (path_visibility & PATH_RAY_VISIBILITY_CAMERA)) ||
87 ((shader & SHADER_EXCLUDE_SCATTER) &&
88 (path_visibility & PATH_RAY_VISIBILITY_VOLUME_SCATTER)))
89 {
90 return false;
91 }
92
93 return true;
94}
95
ccl_device_inline float3 ellipse_sample(const float3 ru, const float3 rv, const float2 rand)
ccl_device_inline bool is_light_shader_visible_to_path(const int shader, const PathRayVisibility path_visibility, const uint32_t path_flag)
ccl_device float3 disk_light_sample(const float3 n, const float2 rand)
ccl_device float light_pdf_area_to_solid_angle(const float3 Ng, const float3 I, const float t)
ccl_device_inline float3 rectangle_sample(const float3 ru, const float3 rv, const float2 rand)
#define ccl_device_inline
#define CCL_NAMESPACE_END
float dot(VecOp< float, D >, VecOp< float, D >) RET
uint32_t PathRayVisibility
@ PATH_RAY_REFLECT
@ PATH_RAY_VISIBILITY_VOLUME_SCATTER
@ PATH_RAY_VISIBILITY_CAMERA
@ PATH_RAY_VISIBILITY_TRANSMIT
@ PATH_RAY_VISIBILITY_DIFFUSE
@ PATH_RAY_VISIBILITY_GLOSSY
@ SHADER_EXCLUDE_CAMERA
@ SHADER_EXCLUDE_DIFFUSE
@ SHADER_EXCLUDE_ANY
@ SHADER_EXCLUDE_SCATTER
@ SHADER_EXCLUDE_GLOSSY
@ SHADER_EXCLUDE_TRANSMIT
LightType
ccl_device_inline void make_orthonormals(const float3 N, ccl_private float3 *a, ccl_private float3 *b)
#define I
#define ccl_device
CCL_NAMESPACE_BEGIN ccl_device float2 sample_uniform_disk(const float2 rand)
float x
float y