Blender V5.3
scene/light.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
9#include "graph/node.h"
10
11#include "scene/geometry.h"
12
13#include "util/ies.h"
14#include "util/thread.h"
15#include "util/types.h"
16#include "util/unique_ptr.h"
17#include "util/vector.h"
18
20
21class Device;
22class DeviceScene;
23class Object;
24class Progress;
25class Scene;
26class Shader;
27
28class Light : public Geometry {
29 public:
31
32 Light(const NodeType *node_type, const Geometry::Type type);
33
34 NODE_SOCKET_API(LightType, light_type)
35 NODE_SOCKET_API(float3, strength)
36
37 NODE_SOCKET_API(bool, cast_shadow)
38 NODE_SOCKET_API(bool, use_mis)
39 NODE_SOCKET_API(bool, use_caustics)
40
41 NODE_SOCKET_API(bool, is_enabled)
42
43 NODE_SOCKET_API(int, max_bounces)
44
45 /* Normalize power by the surface area of the light. */
47
48 void tag_update(Scene *scene);
49
50 /* Check whether the light has contribution the scene. */
51 bool has_contribution(const Scene *scene, const Object *object);
52
53 /* Shader */
54 Shader *get_shader() const;
55
56 virtual float area(const Transform &tfm) const = 0;
57
58 /* Geometry */
59 void compute_bounds() override;
60 void apply_transform(const Transform &tfm, const bool apply_to_motion) override;
61 void get_uv_tiles(ustring map, unordered_set<int> &tiles) override;
62 PrimitiveType primitive_type() const override;
63
64 void copy_to_kernel(KernelLight *klight,
65 const Scene *scene,
66 const Object *object,
67 const uint shader_flags) const;
68 virtual void copy_to_kernel(KernelLight *klight,
69 const Scene *scene,
70 const Object *object) const = 0;
71
72 virtual bool is_traceable() const = 0;
73
74 bool is_spot_light() const;
75 bool is_point_light() const;
76 bool is_area_light() const;
77 bool is_sun_light() const;
78 bool is_background_light() const;
79 bool is_distant_light() const;
80 virtual bool is_portal_light() const
81 {
82 return false;
83 }
84
85 friend class LightManager;
86 friend class LightTree;
87};
88
89class PointLight : public Light {
90 public:
92
93 PointLight();
94 PointLight(const NodeType *node_type, const Geometry::Type type) : Light(node_type, type) {};
95
96 float area(const Transform &tfm) const override;
97 void copy_to_kernel(KernelLight *klight,
98 const Scene *scene,
99 const Object *object) const override;
100 bool is_traceable() const override
101 {
102 return radius > 0.0f;
103 };
104
105 NODE_SOCKET_API(float, radius)
106 NODE_SOCKET_API(bool, is_sphere)
107};
108
109class SpotLight : public PointLight {
110 public:
112
113 SpotLight();
114 void copy_to_kernel(KernelLight *klight,
115 const Scene *scene,
116 const Object *object) const override;
117
118 NODE_SOCKET_API(float, angle)
119 NODE_SOCKET_API(float, smooth)
120};
121
122class AreaLight : public Light {
123 public:
125
126 AreaLight();
127
128 float area(const Transform &tfm) const override;
129 void copy_to_kernel(KernelLight *klight,
130 const Scene *scene,
131 const Object *object) const override;
132 bool is_traceable() const override
133 {
134 return sizeu * sizev > 0.0f;
135 };
136
137 bool is_portal_light() const override
138 {
139 return is_portal;
140 }
141
142 NODE_SOCKET_API(float, sizeu)
143 NODE_SOCKET_API(float, sizev)
144 NODE_SOCKET_API(bool, ellipse)
145 NODE_SOCKET_API(float, spread)
146 NODE_SOCKET_API(bool, is_portal)
147};
148
149class SunLight : public Light {
150 public:
152
153 SunLight();
154
155 float area(const Transform &tfm) const override;
156 void copy_to_kernel(KernelLight *klight,
157 const Scene *scene,
158 const Object *object) const override;
159 bool is_traceable() const override
160 {
161 return false;
162 };
163
164 NODE_SOCKET_API(float, angle)
165};
166
167class BackgroundLight : public Light {
168 public:
170
172
173 float area(const Transform &tfm) const override;
174 void copy_to_kernel(KernelLight *klight,
175 const Scene *scene,
176 const Object *object) const override;
177 bool is_traceable() const override
178 {
179 return false;
180 };
181
182 NODE_SOCKET_API(int, map_resolution)
183 NODE_SOCKET_API(float, average_radiance)
184};
185
187 public:
188 enum : uint32_t {
191 LIGHT_MODIFIED = (1 << 2),
192 LIGHT_ADDED = (1 << 3),
193 LIGHT_REMOVED = (1 << 4),
194 OBJECT_MANAGER = (1 << 5),
195 SHADER_COMPILED = (1 << 6),
196 SHADER_MODIFIED = (1 << 7),
197
198 /* tag everything in the manager for an update */
200
202 };
203
204 /* Need to update background (including multiple importance map) */
206
207 LightManager();
208
209 /* IES texture management */
210 int add_ies(const string &content, const bool log_parsing_error);
211 int add_ies_from_file(const string &filename);
212 void remove_ies(const int slot);
213
214 void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
215 void device_free(Device *device, DeviceScene *dscene, const bool free_background = true);
216
217 void tag_update(Scene *scene, const uint32_t flag);
218
219 bool need_update() const;
220
221 /* Check whether there is a background light. */
222 bool has_background_light(Scene *scene);
223
224 protected:
225 /* Optimization: disable light which is either unsupported or
226 * which doesn't contribute to the scene or which is only used for MIS
227 * and scene doesn't need MIS.
228 */
229 void test_enabled_lights(Scene *scene);
230 /* Count lights in the scene. */
231 void count_lights(KernelIntegrator *kintegrator, const Scene *scene);
232
233 void device_update_lights(DeviceScene *dscene, Scene *scene);
235 DeviceScene *dscene,
236 Scene *scene,
237 Progress &progress);
238 void device_update_tree(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
239 void device_update_background(Device *device,
240 DeviceScene *dscene,
241 Scene *scene,
242 Progress &progress);
243 void device_update_ies(DeviceScene *dscene);
244
245 struct IESSlot {
247 uint hash;
248 int users;
249 };
250
253
256
257 uint32_t update_flags;
258};
259
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
bool is_traceable() const override
float area(const Transform &tfm) const override
bool is_portal_light() const override
void copy_to_kernel(KernelLight *klight, const Scene *scene, const Object *object) const override
float area(const Transform &tfm) const override
bool is_traceable() const override
void copy_to_kernel(KernelLight *klight, const Scene *scene, const Object *object) const override
Geometry(const NodeType *node_type, const Type type)
void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
void count_lights(KernelIntegrator *kintegrator, const Scene *scene)
void device_update_ies(DeviceScene *dscene)
void device_update_tree(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
vector< unique_ptr< IESSlot > > ies_slots
int add_ies_from_file(const string &filename)
void device_update_lights(DeviceScene *dscene, Scene *scene)
void test_enabled_lights(Scene *scene)
uint32_t update_flags
void device_free(Device *device, DeviceScene *dscene, const bool free_background=true)
void remove_ies(const int slot)
void device_update_distribution(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
bool need_update_background
bool need_update() const
int add_ies(const string &content, const bool log_parsing_error)
void tag_update(Scene *scene, const uint32_t flag)
void device_update_background(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
int last_background_resolution
thread_mutex ies_mutex
bool has_background_light(Scene *scene)
bool last_background_enabled
bool has_contribution(const Scene *scene, const Object *object)
bool is_distant_light() const
Light(const NodeType *node_type, const Geometry::Type type)
bool is_spot_light() const
void tag_update(Scene *scene)
void get_uv_tiles(ustring map, unordered_set< int > &tiles) override
bool is_sun_light() const
void copy_to_kernel(KernelLight *klight, const Scene *scene, const Object *object, const uint shader_flags) const
virtual float area(const Transform &tfm) const =0
void compute_bounds() override
virtual bool is_portal_light() const
Definition scene/light.h:80
virtual bool is_traceable() const =0
void apply_transform(const Transform &tfm, const bool apply_to_motion) override
PrimitiveType primitive_type() const override
Shader * get_shader() const
virtual void copy_to_kernel(KernelLight *klight, const Scene *scene, const Object *object) const =0
friend class LightManager
Definition scene/light.h:85
bool is_background_light() const
friend class LightTree
Definition scene/light.h:86
bool is_point_light() const
NODE_ABSTRACT_DECLARE
Definition scene/light.h:30
bool is_area_light() const
void copy_to_kernel(KernelLight *klight, const Scene *scene, const Object *object) const override
bool is_traceable() const override
PointLight(const NodeType *node_type, const Geometry::Type type)
Definition scene/light.h:94
float area(const Transform &tfm) const override
Definition scene.h:133
void copy_to_kernel(KernelLight *klight, const Scene *scene, const Object *object) const override
bool is_traceable() const override
float area(const Transform &tfm) const override
void copy_to_kernel(KernelLight *klight, const Scene *scene, const Object *object) const override
#define CCL_NAMESPACE_END
#define smooth
VecBase< float, D > normalize(VecOp< float, D >) RET
#define NODE_SOCKET_API(type_, name)
Definition graph/node.h:56
ccl_gpu_kernel_postfix ccl_global KernelWorkTile * tiles
PrimitiveType
LightType
const NodeType * type
Definition graph/node.h:179
std::mutex thread_mutex
Definition thread.h:27