Blender V4.3
scene.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#ifndef __SCENE_H__
6#define __SCENE_H__
7
8#include "bvh/params.h"
9
10#include "scene/devicescene.h"
11#include "scene/film.h"
12#include "scene/image.h"
13#include "scene/shader.h"
14
15#include "util/param.h"
16#include "util/string.h"
17#include "util/texture.h"
18#include "util/thread.h"
19
21
22class AlembicProcedural;
24class Background;
25class BVH;
26class Camera;
27class Device;
28class DeviceInfo;
29class Film;
30class Integrator;
31class Light;
32class LightManager;
33class LookupTables;
34class Geometry;
35class GeometryManager;
36class Object;
37class ObjectManager;
39class ParticleSystem;
40class PointCloud;
41class Procedural;
43class CurveSystemManager;
44class Shader;
45class ShaderManager;
46class Progress;
47class BakeManager;
48class BakeData;
49class RenderStats;
51class Volume;
52
53/* Scene Parameters */
54
56 public:
58
59 /* Requested BVH layout.
60 *
61 * If it's not supported by the device, the widest one from supported ones
62 * will be used, but BVH wider than this one will never be used.
63 */
65
74
76
91
92 bool modified(const SceneParams &params) const
93 {
94 return !(shadingsystem == params.shadingsystem && bvh_layout == params.bvh_layout &&
95 bvh_type == params.bvh_type &&
96 use_bvh_spatial_split == params.use_bvh_spatial_split &&
97 use_bvh_compact_structure == params.use_bvh_compact_structure &&
98 use_bvh_unaligned_nodes == params.use_bvh_unaligned_nodes &&
99 num_bvh_time_steps == params.num_bvh_time_steps &&
100 hair_subdivisions == params.hair_subdivisions && hair_shape == params.hair_shape &&
101 texture_limit == params.texture_limit);
102 }
103
105 {
106 /* Matching the tessellation rate limit in Embree. */
107 return clamp(1 << hair_subdivisions, 1, 16);
108 }
109};
110
111/* Scene */
112
113class Scene : public NodeOwner {
114 public:
115 /* Optional name. Is used for logging and reporting. */
116 string name;
117
118 /* Maps from Light group names to their pass ID. */
119 map<ustring, int> lightgroups;
120
121 /* data */
129
130 /* data lists */
138
139 /* data managers */
148
149 /* default shaders */
155
156 /* device */
159
160 /* parameters */
162
163 /* mutex must be locked manually by callers */
165
166 /* scene update statistics */
168
170 ~Scene();
171
172 void device_update(Device *device, Progress &progress);
173
176
178 MotionType need_motion() const;
179 float motion_shutter_time();
180
181 bool need_update();
182 bool need_reset(const bool check_camera = true);
183
184 void reset();
185 void device_free();
186
187 void collect_statistics(RenderStats *stats);
188
189 void enable_update_stats();
190
191 bool load_kernels(Progress &progress);
192 bool update(Progress &progress);
193
194 bool has_shadow_catcher();
196
197 /* This function is used to create a node of a specified type instead of
198 * calling 'new', and sets the scene as the owner of the node.
199 * The function has overloads that will also add the created node to the right
200 * node array (e.g. Scene::geometry for Geometry nodes) and tag the appropriate
201 * manager for an update.
202 */
203 template<typename T, typename... Args> T *create_node(Args &&...args)
204 {
205 T *node = new T(args...);
206 node->set_owner(this);
207 return node;
208 }
209
210 /* This function is used to delete a node from the scene instead of calling 'delete'
211 * and manually removing the node from the data array. It also tags the
212 * appropriate manager for an update, if any, and checks that the scene is indeed
213 * the owner of the node. Calling this function on a node not owned by the scene
214 * will likely cause a crash which we want in order to detect such cases.
215 */
216 template<typename T> void delete_node(T *node)
217 {
218 assert(node->get_owner() == this);
219 delete_node_impl(node);
220 }
221
222 /* Same as above, but specify the actual owner.
223 */
224 template<typename T> void delete_node(T *node, const NodeOwner *owner)
225 {
226 assert(node->get_owner() == owner);
227 delete_node_impl(node);
228 (void)owner;
229 }
230
231 /* Remove all nodes in the set from the appropriate data arrays, and tag the
232 * specific managers for an update. This assumes that the scene owns the nodes.
233 */
234 template<typename T> void delete_nodes(const set<T *> &nodes)
235 {
236 delete_nodes(nodes, this);
237 }
238
239 /* Same as above, but specify the actual owner of all the nodes in the set.
240 */
241 template<typename T> void delete_nodes(const set<T *> &nodes, const NodeOwner *owner);
242
243 protected:
244 /* Check if some heavy data worth logging was updated.
245 * Mainly used to suppress extra annoying logging.
246 */
247 bool need_data_update();
248
249 void free_memory(bool final);
250
253
255
258
259 /* Maximum number of closure during session lifetime. */
261
262 /* Get maximum number of closures to be used in kernel. */
264
265 /* Get size of a volume stack needed to render this scene. */
266 int get_volume_stack_size() const;
267
268 template<typename T> void delete_node_impl(T *node)
269 {
270 delete node;
271 }
272};
273
275
277
279
281
283
285
287
289
290template<> AlembicProcedural *Scene::create_node<AlembicProcedural>();
291
293
294template<> void Scene::delete_node_impl(Light *node);
295
296template<> void Scene::delete_node_impl(Mesh *node);
297
298template<> void Scene::delete_node_impl(Volume *node);
299
300template<> void Scene::delete_node_impl(PointCloud *node);
301
302template<> void Scene::delete_node_impl(Hair *node);
303
304template<> void Scene::delete_node_impl(Geometry *node);
305
306template<> void Scene::delete_node_impl(Object *node);
307
309
310template<> void Scene::delete_node_impl(Shader *node);
311
312template<> void Scene::delete_node_impl(Procedural *node);
313
314template<> void Scene::delete_node_impl(AlembicProcedural *node);
315
316template<> void Scene::delete_node_impl(Pass *node);
317
318template<> void Scene::delete_nodes(const set<Light *> &nodes, const NodeOwner *owner);
319
320template<> void Scene::delete_nodes(const set<Geometry *> &nodes, const NodeOwner *owner);
321
322template<> void Scene::delete_nodes(const set<Object *> &nodes, const NodeOwner *owner);
323
324template<> void Scene::delete_nodes(const set<ParticleSystem *> &nodes, const NodeOwner *owner);
325
326template<> void Scene::delete_nodes(const set<Shader *> &nodes, const NodeOwner *owner);
327
328template<> void Scene::delete_nodes(const set<Procedural *> &nodes, const NodeOwner *owner);
329
330template<> void Scene::delete_nodes(const set<Pass *> &nodes, const NodeOwner *owner);
331
333
334#endif /* __SCENE_H__ */
unsigned int uint
struct Scene Scene
Definition bvh/bvh.h:66
Definition film.h:30
Definition hair.h:14
Definition pass.h:49
BVHLayout bvh_layout
Definition scene.h:64
bool background
Definition scene.h:75
bool use_bvh_unaligned_nodes
Definition scene.h:69
int texture_limit
Definition scene.h:73
SceneParams()
Definition scene.h:77
bool use_bvh_spatial_split
Definition scene.h:67
int curve_subdivisions()
Definition scene.h:104
CurveShapeType hair_shape
Definition scene.h:72
int num_bvh_time_steps
Definition scene.h:70
int hair_subdivisions
Definition scene.h:71
bool modified(const SceneParams &params) const
Definition scene.h:92
BVHType bvh_type
Definition scene.h:66
bool use_bvh_compact_structure
Definition scene.h:68
ShadingSystem shadingsystem
Definition scene.h:57
OperationNode * node
#define CCL_NAMESPACE_END
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
AttributeStandard
CurveShapeType
@ CURVE_RIBBON
@ BVH_LAYOUT_AUTO
#define T
CCL_NAMESPACE_BEGIN typedef KernelBVHLayout BVHLayout
Definition params.h:23
BVHType
Definition params.h:28
@ BVH_TYPE_DYNAMIC
Definition params.h:34
ShadingSystem
@ SHADINGSYSTEM_SVM
bool kernels_loaded
Definition scene.h:251
BakeManager * bake_manager
Definition scene.h:146
Film * film
Definition scene.h:126
string name
Definition scene.h:116
BVH * bvh
Definition scene.h:122
bool need_global_attribute(AttributeStandard std)
Definition scene.cpp:385
ParticleSystemManager * particle_system_manager
Definition scene.h:145
vector< Geometry * > geometry
Definition scene.h:132
MotionType need_motion() const
Definition scene.cpp:362
void need_global_attributes(AttributeRequestSet &attributes)
Definition scene.cpp:405
bool update(Progress &progress)
Definition scene.cpp:574
vector< Pass * > passes
Definition scene.h:136
Device * device
Definition scene.h:157
vector< Shader * > shaders
Definition scene.h:133
vector< Procedural * > procedurals
Definition scene.h:137
int get_max_closure_count()
Definition scene.cpp:650
~Scene()
Definition scene.cpp:79
void device_free()
Definition scene.cpp:454
bool has_shadow_catcher_
Definition scene.h:256
Shader * default_volume
Definition scene.h:151
Camera * dicing_camera
Definition scene.h:124
LookupTables * lookup_tables
Definition scene.h:125
SceneParams params
Definition scene.h:161
vector< Light * > lights
Definition scene.h:134
Shader * default_surface
Definition scene.h:150
void tag_shadow_catcher_modified()
Definition scene.cpp:743
void free_memory(bool final)
Definition scene.cpp:84
Shader * default_empty
Definition scene.h:154
vector< ParticleSystem * > particle_systems
Definition scene.h:135
ImageManager * image_manager
Definition scene.h:140
void enable_update_stats()
Definition scene.cpp:465
Shader * default_background
Definition scene.h:153
uint loaded_kernel_features
Definition scene.h:252
vector< Object * > objects
Definition scene.h:131
Light * create_node()
Definition scene.cpp:748
ObjectManager * object_manager
Definition scene.h:144
void delete_node(T *node)
Definition scene.h:216
bool shadow_catcher_modified_
Definition scene.h:257
Background * background
Definition scene.h:127
MotionType
Definition scene.h:177
@ MOTION_PASS
Definition scene.h:177
@ MOTION_NONE
Definition scene.h:177
@ MOTION_BLUR
Definition scene.h:177
void update_kernel_features()
Definition scene.cpp:472
void delete_nodes(const set< T * > &nodes)
Definition scene.h:234
Camera * camera
Definition scene.h:123
bool has_shadow_catcher()
Definition scene.cpp:726
ProceduralManager * procedural_manager
Definition scene.h:147
ShaderManager * shader_manager
Definition scene.h:142
void delete_node_impl(T *node)
Definition scene.h:268
bool load_kernels(Progress &progress)
Definition scene.cpp:619
int max_closure_global
Definition scene.h:260
Integrator * integrator
Definition scene.h:128
LightManager * light_manager
Definition scene.h:141
thread_mutex mutex
Definition scene.h:164
T * create_node(Args &&...args)
Definition scene.h:203
bool need_data_update()
Definition scene.cpp:419
int get_volume_stack_size() const
Definition scene.cpp:682
bool need_reset(const bool check_camera=true)
Definition scene.cpp:429
bool need_update()
Definition scene.cpp:414
Shader * default_light
Definition scene.h:152
void delete_node(T *node, const NodeOwner *owner)
Definition scene.h:224
map< ustring, int > lightgroups
Definition scene.h:119
void reset()
Definition scene.cpp:434
void collect_statistics(RenderStats *stats)
Definition scene.cpp:459
SceneUpdateStats * update_stats
Definition scene.h:167
GeometryManager * geometry_manager
Definition scene.h:143
DeviceScene dscene
Definition scene.h:158
void delete_nodes(const set< T * > &nodes, const NodeOwner *owner)
float motion_shutter_time()
Definition scene.cpp:375
void device_update(Device *device, Progress &progress)
Definition scene.cpp:176
CCL_NAMESPACE_BEGIN typedef std::mutex thread_mutex
Definition thread.h:29
ccl_device_inline int clamp(int a, int mn, int mx)
Definition util/math.h:379