Blender  V3.3
scene/light.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #ifndef __LIGHT_H__
5 #define __LIGHT_H__
6 
7 #include "kernel/types.h"
8 
9 #include "graph/node.h"
10 
11 /* included as Light::set_shader defined through NODE_SOCKET_API does not select
12  * the right Node::set overload as it does not know that Shader is a Node */
13 #include "scene/shader.h"
14 
15 #include "util/ies.h"
16 #include "util/thread.h"
17 #include "util/types.h"
18 #include "util/vector.h"
19 
21 
22 class Device;
23 class DeviceScene;
24 class Object;
25 class Progress;
26 class Scene;
27 class Shader;
28 
29 class Light : public Node {
30  public:
32 
33  Light();
34 
35  NODE_SOCKET_API(LightType, light_type)
36  NODE_SOCKET_API(float3, strength)
38 
40  NODE_SOCKET_API(float, size)
41  NODE_SOCKET_API(float, angle)
42 
43  NODE_SOCKET_API(float3, axisu)
44  NODE_SOCKET_API(float, sizeu)
45  NODE_SOCKET_API(float3, axisv)
46  NODE_SOCKET_API(float, sizev)
47  NODE_SOCKET_API(bool, round)
48  NODE_SOCKET_API(float, spread)
49 
51 
52  NODE_SOCKET_API(int, map_resolution)
53 
54  NODE_SOCKET_API(float, spot_angle)
55  NODE_SOCKET_API(float, spot_smooth)
56 
57  NODE_SOCKET_API(bool, cast_shadow)
58  NODE_SOCKET_API(bool, use_mis)
59  NODE_SOCKET_API(bool, use_camera)
60  NODE_SOCKET_API(bool, use_diffuse)
61  NODE_SOCKET_API(bool, use_glossy)
62  NODE_SOCKET_API(bool, use_transmission)
63  NODE_SOCKET_API(bool, use_scatter)
64  NODE_SOCKET_API(bool, use_caustics)
65 
66  NODE_SOCKET_API(bool, is_shadow_catcher)
67  NODE_SOCKET_API(bool, is_portal)
68  NODE_SOCKET_API(bool, is_enabled)
69 
70  NODE_SOCKET_API(Shader *, shader)
71  NODE_SOCKET_API(int, max_bounces)
72  NODE_SOCKET_API(uint, random_id)
73 
74  NODE_SOCKET_API(ustring, lightgroup)
75 
76  void tag_update(Scene *scene);
77 
78  /* Check whether the light has contribution the scene. */
80 
81  friend class LightManager;
82 };
83 
84 class LightManager {
85  public:
86  enum : uint32_t {
87  MESH_NEED_REBUILD = (1 << 0),
89  LIGHT_MODIFIED = (1 << 2),
90  LIGHT_ADDED = (1 << 3),
91  LIGHT_REMOVED = (1 << 4),
92  OBJECT_MANAGER = (1 << 5),
93  SHADER_COMPILED = (1 << 6),
94  SHADER_MODIFIED = (1 << 7),
95 
96  /* tag everything in the manager for an update */
97  UPDATE_ALL = ~0u,
98 
100  };
101 
102  /* Need to update background (including multiple importance map) */
104 
105  LightManager();
106  ~LightManager();
107 
108  /* IES texture management */
109  int add_ies(const string &ies);
110  int add_ies_from_file(const string &filename);
111  void remove_ies(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, uint32_t flag);
117 
118  bool need_update() const;
119 
120  /* Check whether there is a background light. */
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  */
129 
130  void device_update_points(Device *device, DeviceScene *dscene, Scene *scene);
131  void device_update_distribution(Device *device,
132  DeviceScene *dscene,
133  Scene *scene,
134  Progress &progress);
135  void device_update_background(Device *device,
136  DeviceScene *dscene,
137  Scene *scene,
138  Progress &progress);
139  void device_update_ies(DeviceScene *dscene);
140 
141  /* Check whether light manager can use the object as a light-emissive. */
142  bool object_usable_as_light(Object *object);
143 
144  struct IESSlot {
147  int users;
148  };
149 
152 
155 
157 };
158 
160 
161 #endif /* __LIGHT_H__ */
unsigned int uint
Definition: BLI_sys_types.h:67
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
void device_update_ies(DeviceScene *dscene)
int add_ies(const string &ies)
vector< IESSlot * > ies_slots
Definition: scene/light.h:150
int add_ies_from_file(const string &filename)
void test_enabled_lights(Scene *scene)
uint32_t update_flags
Definition: scene/light.h:156
void device_free(Device *device, DeviceScene *dscene, const bool free_background=true)
void device_update_distribution(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
bool need_update_background
Definition: scene/light.h:103
@ EMISSIVE_MESH_MODIFIED
Definition: scene/light.h:88
void device_update_points(Device *device, DeviceScene *dscene, Scene *scene)
bool need_update() const
void remove_ies(int slot)
void device_update_background(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
int last_background_resolution
Definition: scene/light.h:154
thread_mutex ies_mutex
Definition: scene/light.h:151
bool has_background_light(Scene *scene)
bool object_usable_as_light(Object *object)
void tag_update(Scene *scene, uint32_t flag)
bool last_background_enabled
Definition: scene/light.h:153
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
Scene scene
#define NODE_SOCKET_API(type_, name)
Definition: graph/node.h:54
LightType
Definition: kernel/types.h:455
unsigned int uint32_t
Definition: stdint.h:80
NODE_DECLARE
Definition: scene/light.h:31
void tag_update(Scene *scene)
bool has_contribution(Scene *scene)
CCL_NAMESPACE_BEGIN typedef std::mutex thread_mutex
Definition: thread.h:27