Blender V5.0
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();
33
34 NODE_SOCKET_API(LightType, light_type)
35 NODE_SOCKET_API(float3, strength)
36
37 NODE_SOCKET_API(float, size)
39
40 NODE_SOCKET_API(float, sizeu)
41 NODE_SOCKET_API(float, sizev)
42 NODE_SOCKET_API(bool, ellipse)
43 NODE_SOCKET_API(float, spread)
44
45 NODE_SOCKET_API(int, map_resolution)
46 NODE_SOCKET_API(float, average_radiance)
47
48 NODE_SOCKET_API(bool, is_sphere)
49
50 NODE_SOCKET_API(float, spot_angle)
51 NODE_SOCKET_API(float, spot_smooth)
52
53 NODE_SOCKET_API(bool, cast_shadow)
54 NODE_SOCKET_API(bool, use_mis)
55 NODE_SOCKET_API(bool, use_caustics)
56
57 NODE_SOCKET_API(bool, is_portal)
58 NODE_SOCKET_API(bool, is_enabled)
59
60 NODE_SOCKET_API(int, max_bounces)
61
62 /* Normalize power by the surface area of the light. */
64
65 void tag_update(Scene *scene);
66
67 /* Check whether the light has contribution the scene. */
68 bool has_contribution(const Scene *scene, const Object *object);
69
70 /* Shader */
71 Shader *get_shader() const;
72
73 float area(const Transform &tfm) const;
74
75 /* Geometry */
76 void compute_bounds() override;
77 void apply_transform(const Transform &tfm, const bool apply_to_motion) override;
78 void get_uv_tiles(ustring map, unordered_set<int> &tiles) override;
79 PrimitiveType primitive_type() const override;
80
81 friend class LightManager;
82 friend class LightTree;
83};
84
86 public:
87 enum : uint32_t {
90 LIGHT_MODIFIED = (1 << 2),
91 LIGHT_ADDED = (1 << 3),
92 LIGHT_REMOVED = (1 << 4),
93 OBJECT_MANAGER = (1 << 5),
94 SHADER_COMPILED = (1 << 6),
95 SHADER_MODIFIED = (1 << 7),
96
97 /* tag everything in the manager for an update */
99
101 };
102
103 /* Need to update background (including multiple importance map) */
105
106 LightManager();
107
108 /* IES texture management */
109 int add_ies(const string &content);
110 int add_ies_from_file(const string &filename);
111 void remove_ies(const int slot);
112
113 void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
114 void device_free(Device *device, DeviceScene *dscene, const bool free_background = true);
115
116 void tag_update(Scene *scene, const uint32_t flag);
117
118 bool need_update() const;
119
120 /* Check whether there is a background light. */
121 bool has_background_light(Scene *scene);
122
123 protected:
124 /* Optimization: disable light which is either unsupported or
125 * which doesn't contribute to the scene or which is only used for MIS
126 * and scene doesn't need MIS.
127 */
128 void test_enabled_lights(Scene *scene);
129
130 void device_update_lights(DeviceScene *dscene, Scene *scene);
132 DeviceScene *dscene,
133 Scene *scene,
134 Progress &progress);
135 void device_update_tree(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
136 void device_update_background(Device *device,
137 DeviceScene *dscene,
138 Scene *scene,
139 Progress &progress);
140 void device_update_ies(DeviceScene *dscene);
141
147
150
153
154 uint32_t update_flags;
155};
156
unsigned int uint
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
Definition IK_Math.h:117
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
void device_update_ies(DeviceScene *dscene)
@ EMISSIVE_MESH_MODIFIED
Definition scene/light.h:89
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
int add_ies(const string &content)
bool need_update() const
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
#define CCL_NAMESPACE_END
VecBase< float, D > normalize(VecOp< float, D >) RET
#define NODE_SOCKET_API(type_, name)
Definition graph/node.h:55
ccl_gpu_kernel_postfix ccl_global KernelWorkTile * tiles
PrimitiveType
LightType
bool has_contribution(const Scene *scene, const Object *object)
void tag_update(Scene *scene)
void get_uv_tiles(ustring map, unordered_set< int > &tiles) override
void compute_bounds() override
void apply_transform(const Transform &tfm, const bool apply_to_motion) override
PrimitiveType primitive_type() const override
Shader * get_shader() const
float area(const Transform &tfm) const
friend class LightManager
Definition scene/light.h:81
friend class LightTree
Definition scene/light.h:82
std::mutex thread_mutex
Definition thread.h:27
uint8_t flag
Definition wm_window.cc:145