Blender V5.0
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/* Light Sample Result */
14
16 float3 P; /* position on light, or direction for distant light */
17 packed_float3 Ng; /* normal on light */
18 float t; /* distance to light (FLT_MAX for distant light) */
19 float3 D; /* direction from shading point to light */
20 float u, v; /* parametric coordinate on primitive */
21 float pdf; /* pdf for selecting light and point on light */
22 float pdf_selection; /* pdf for selecting light */
23 float eval_fac; /* intensity multiplier */
24 int object; /* object id for triangle/curve lights */
25 int prim; /* lamp id for lights, primitive id for triangle/curve lights */
26 int shader; /* shader id */
27 int group; /* lightgroup */
28 LightType type; /* type of light */
29 int emitter_id; /* index in the emitter array */
30};
31
32/* Utilities */
33
35{
36 const float2 uv = sample_uniform_disk(rand);
37 return ru * uv.x + rv * uv.y;
38}
39
41{
42 return ru * (2.0f * rand.x - 1.0f) + rv * (2.0f * rand.y - 1.0f);
43}
44
46{
47 float3 ru;
48 float3 rv;
49
50 make_orthonormals(n, &ru, &rv);
51
52 return ellipse_sample(ru, rv, rand);
53}
54
55ccl_device float light_pdf_area_to_solid_angle(const float3 Ng, const float3 I, const float t)
56{
57 const float cos_pi = dot(Ng, I);
58
59 if (cos_pi <= 0.0f) {
60 return 0.0f;
61 }
62
63 return t * t / cos_pi;
64}
65
66/* Visibility flag om the light shader. */
67ccl_device_inline bool is_light_shader_visible_to_path(const int shader, const uint32_t path_flag)
68{
69 if ((shader & SHADER_EXCLUDE_ANY) == 0) {
70 return true;
71 }
72
73 if (((shader & SHADER_EXCLUDE_DIFFUSE) && (path_flag & PATH_RAY_DIFFUSE)) ||
74 ((shader & SHADER_EXCLUDE_GLOSSY) && ((path_flag & (PATH_RAY_GLOSSY | PATH_RAY_REFLECT)) ==
76 ((shader & SHADER_EXCLUDE_TRANSMIT) && (path_flag & PATH_RAY_TRANSMIT)) ||
77 ((shader & SHADER_EXCLUDE_CAMERA) && (path_flag & PATH_RAY_CAMERA)) ||
78 ((shader & SHADER_EXCLUDE_SCATTER) && (path_flag & PATH_RAY_VOLUME_SCATTER)))
79 {
80 return false;
81 }
82
83 return true;
84}
85
dot(value.rgb, luminance_coefficients)") DEFINE_VALUE("REDUCE(lhs
#define ccl_device_inline
#define CCL_NAMESPACE_END
@ PATH_RAY_REFLECT
@ PATH_RAY_TRANSMIT
@ PATH_RAY_VOLUME_SCATTER
@ PATH_RAY_GLOSSY
@ PATH_RAY_DIFFUSE
@ PATH_RAY_CAMERA
@ SHADER_EXCLUDE_CAMERA
@ SHADER_EXCLUDE_DIFFUSE
@ SHADER_EXCLUDE_ANY
@ SHADER_EXCLUDE_SCATTER
@ SHADER_EXCLUDE_GLOSSY
@ SHADER_EXCLUDE_TRANSMIT
LightType
ccl_device_inline float3 ellipse_sample(const float3 ru, const float3 rv, const float2 rand)
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)
ccl_device_inline bool is_light_shader_visible_to_path(const int shader, const uint32_t path_flag)
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)
packed_float3 Ng
LightType type
float pdf_selection
float x
float y