Blender  V2.93
light.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __LIGHT_H__
18 #define __LIGHT_H__
19 
20 #include "kernel/kernel_types.h"
21 
22 #include "graph/node.h"
23 
24 /* included as Light::set_shader defined through NODE_SOCKET_API does not select
25  * the right Node::set overload as it does not know that Shader is a Node */
26 #include "render/shader.h"
27 
28 #include "util/util_ies.h"
29 #include "util/util_thread.h"
30 #include "util/util_types.h"
31 #include "util/util_vector.h"
32 
34 
35 class Device;
36 class DeviceScene;
37 class Object;
38 class Progress;
39 class Scene;
40 class Shader;
41 
42 class Light : public Node {
43  public:
45 
46  Light();
47 
48  NODE_SOCKET_API(LightType, light_type)
49  NODE_SOCKET_API(float3, strength)
51 
53  NODE_SOCKET_API(float, size)
54  NODE_SOCKET_API(float, angle)
55 
56  NODE_SOCKET_API(float3, axisu)
57  NODE_SOCKET_API(float, sizeu)
58  NODE_SOCKET_API(float3, axisv)
59  NODE_SOCKET_API(float, sizev)
60  NODE_SOCKET_API(bool, round)
61  NODE_SOCKET_API(float, spread)
62 
64 
65  NODE_SOCKET_API(int, map_resolution)
66 
67  NODE_SOCKET_API(float, spot_angle)
68  NODE_SOCKET_API(float, spot_smooth)
69 
70  NODE_SOCKET_API(bool, cast_shadow)
71  NODE_SOCKET_API(bool, use_mis)
72  NODE_SOCKET_API(bool, use_diffuse)
73  NODE_SOCKET_API(bool, use_glossy)
74  NODE_SOCKET_API(bool, use_transmission)
75  NODE_SOCKET_API(bool, use_scatter)
76 
77  NODE_SOCKET_API(bool, is_portal)
78  NODE_SOCKET_API(bool, is_enabled)
79 
81  NODE_SOCKET_API(int, samples)
82  NODE_SOCKET_API(int, max_bounces)
83  NODE_SOCKET_API(uint, random_id)
84 
85  void tag_update(Scene *scene);
86 
87  /* Check whether the light has contribution the scene. */
89 
90  friend class LightManager;
91 };
92 
93 class LightManager {
94  public:
95  enum : uint32_t {
96  MESH_NEED_REBUILD = (1 << 0),
98  LIGHT_MODIFIED = (1 << 2),
99  LIGHT_ADDED = (1 << 3),
100  LIGHT_REMOVED = (1 << 4),
101  OBJECT_MANAGER = (1 << 5),
102  SHADER_COMPILED = (1 << 6),
103  SHADER_MODIFIED = (1 << 7),
104 
105  /* tag everything in the manager for an update */
106  UPDATE_ALL = ~0u,
107 
109  };
110 
112 
113  /* Need to update background (including multiple importance map) */
115 
116  LightManager();
117  ~LightManager();
118 
119  /* IES texture management */
120  int add_ies(const string &ies);
121  int add_ies_from_file(const string &filename);
122  void remove_ies(int slot);
123 
124  void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
125  void device_free(Device *device, DeviceScene *dscene, const bool free_background = true);
126 
127  void tag_update(Scene *scene, uint32_t flag);
128 
129  bool need_update() const;
130 
131  /* Check whether there is a background light. */
133 
134  protected:
135  /* Optimization: disable light which is either unsupported or
136  * which doesn't contribute to the scene or which is only used for MIS
137  * and scene doesn't need MIS.
138  */
140 
141  void device_update_points(Device *device, DeviceScene *dscene, Scene *scene);
142  void device_update_distribution(Device *device,
143  DeviceScene *dscene,
144  Scene *scene,
145  Progress &progress);
146  void device_update_background(Device *device,
147  DeviceScene *dscene,
148  Scene *scene,
149  Progress &progress);
150  void device_update_ies(DeviceScene *dscene);
151 
152  /* Check whether light manager can use the object as a light-emissive. */
153  bool object_usable_as_light(Object *object);
154 
155  struct IESSlot {
158  int users;
159  };
160 
163 
166 
168 };
169 
171 
172 #endif /* __LIGHT_H__ */
unsigned int uint
Definition: BLI_sys_types.h:83
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
Definition: device.h:293
void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
Definition: light.cpp:978
~LightManager()
Definition: light.cpp:200
void device_update_ies(DeviceScene *dscene)
Definition: light.cpp:1114
LightManager()
Definition: light.cpp:191
int add_ies(const string &ies)
Definition: light.cpp:1058
vector< IESSlot * > ies_slots
Definition: light.h:161
int add_ies_from_file(const string &filename)
Definition: light.cpp:1046
void test_enabled_lights(Scene *scene)
Definition: light.cpp:217
uint32_t update_flags
Definition: light.h:167
void device_free(Device *device, DeviceScene *dscene, const bool free_background=true)
Definition: light.cpp:1025
void device_update_distribution(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
Definition: light.cpp:286
bool need_update_background
Definition: light.h:114
bool use_light_visibility
Definition: light.h:111
@ LIGHT_ADDED
Definition: light.h:99
@ OBJECT_MANAGER
Definition: light.h:101
@ SHADER_MODIFIED
Definition: light.h:103
@ UPDATE_NONE
Definition: light.h:108
@ UPDATE_ALL
Definition: light.h:106
@ MESH_NEED_REBUILD
Definition: light.h:96
@ LIGHT_MODIFIED
Definition: light.h:98
@ LIGHT_REMOVED
Definition: light.h:100
@ SHADER_COMPILED
Definition: light.h:102
@ EMISSIVE_MESH_MODIFIED
Definition: light.h:97
void device_update_points(Device *device, DeviceScene *dscene, Scene *scene)
Definition: light.cpp:733
bool need_update() const
Definition: light.cpp:1041
void remove_ies(int slot)
Definition: light.cpp:1095
void device_update_background(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
Definition: light.cpp:579
int last_background_resolution
Definition: light.h:165
thread_mutex ies_mutex
Definition: light.h:162
bool has_background_light(Scene *scene)
Definition: light.cpp:207
bool object_usable_as_light(Object *object)
Definition: light.cpp:258
void tag_update(Scene *scene, uint32_t flag)
Definition: light.cpp:1036
bool last_background_enabled
Definition: light.h:164
Definition: shader.h:80
Scene scene
#define CCL_NAMESPACE_END
void KERNEL_FUNCTION_FULL_NAME() shader(KernelGlobals *kg, uint4 *input, float4 *output, int type, int filter, int i, int offset, int sample)
LightType
Definition: kernel_types.h:599
#define NODE_SOCKET_API(type_, name)
Definition: node.h:63
unsigned int uint32_t
Definition: stdint.h:83
NODE_DECLARE
Definition: light.h:44
void tag_update(Scene *scene)
Definition: light.cpp:164
bool has_contribution(Scene *scene)
Definition: light.cpp:175
Light()
Definition: light.cpp:160
Definition: node.h:98
CCL_NAMESPACE_BEGIN typedef std::mutex thread_mutex
Definition: util_thread.h:40