Blender V5.0
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#pragma once
6
7#include "bvh/params.h"
8
9#include "scene/devicescene.h"
10#include "scene/film.h"
11#include "scene/image.h"
12#include "scene/shader.h"
13
14#include "util/param.h"
15#include "util/string.h"
16#include "util/thread.h"
17#include "util/unique_ptr.h"
19
21
23class Background;
24class BVH;
25class Camera;
26class Device;
27class DeviceInfo;
28class Film;
29class Integrator;
30class Light;
31class LightManager;
32class LookupTables;
33class Geometry;
34class GeometryManager;
35class Object;
36class ObjectManager;
37class OSLManager;
39class ParticleSystem;
40class PointCloud;
41class Procedural;
43class CurveSystemManager;
44class Shader;
45class ShaderManager;
46class Progress;
47class BakeManager;
48class BakeData;
49class RenderStats;
51class Volume;
52class VolumeManager;
53
54/* Scene Parameters */
55
57 public:
59
60 /* Requested BVH layout.
61 *
62 * If it's not supported by the device, the widest one from supported ones
63 * will be used, but BVH wider than this one will never be used.
64 */
66
75
77
92
93 bool modified(const SceneParams &params) const
94 {
95 return !(shadingsystem == params.shadingsystem && bvh_layout == params.bvh_layout &&
96 bvh_type == params.bvh_type &&
97 use_bvh_spatial_split == params.use_bvh_spatial_split &&
98 use_bvh_compact_structure == params.use_bvh_compact_structure &&
99 use_bvh_unaligned_nodes == params.use_bvh_unaligned_nodes &&
100 num_bvh_time_steps == params.num_bvh_time_steps &&
101 hair_subdivisions == params.hair_subdivisions && hair_shape == params.hair_shape &&
102 texture_limit == params.texture_limit);
103 }
104
106 {
107 /* Matching the tessellation rate limit in Embree. */
108 return clamp(1 << hair_subdivisions, 1, 16);
109 }
110};
111
112/* Scene */
113
114class Scene : public NodeOwner {
115 public:
116 /* Optional name. Is used for logging and reporting. */
117 string name;
118
119 /* Maps from Light group names to their pass ID. */
120 map<ustring, int> lightgroups;
121
122 /* data */
125
131
132 /* data lists */
143
144 /* data managers */
155
156 /* default shaders */
162
163 /* device */
166
167 /* parameters */
169
170 /* mutex must be locked manually by callers */
173
174 /* scene update statistics */
176
178 ~Scene() override;
179
180 void device_update(Device *device, Progress &progress);
181
184
186 MotionType need_motion() const;
187 float motion_shutter_time();
188
189 bool need_update();
190 bool need_reset(const bool check_camera = true);
191
192 void reset();
193 void device_free();
194
195 void collect_statistics(RenderStats *stats);
196
197 void enable_update_stats();
198
199 bool update(Progress &progress);
200 bool update_camera_resolution(Progress &progress, int width, int height);
201
202 bool has_shadow_catcher();
204 bool has_volume();
205 bool has_volume_modified() const;
207
208 /* This function is used to create a node of a specified type instead of
209 * calling 'new', and sets the scene as the owner of the node.
210 * The function has overloads that will also add the created node to the right
211 * node array (e.g. Scene::geometry for Geometry nodes) and tag the appropriate
212 * manager for an update.
213 */
214 template<typename T, typename... Args> T *create_node(Args &&.../*args*/) = delete;
215
216 /* This function is used to delete a node from the scene instead of calling 'delete'
217 * and manually removing the node from the data array. It also tags the
218 * appropriate manager for an update, if any, and checks that the scene is indeed
219 * the owner of the node. Calling this function on a node not owned by the scene
220 * will likely cause a crash which we want in order to detect such cases.
221 */
222 template<typename T> void delete_node(T *node) = delete;
223
224 /* Remove all nodes in the set from the appropriate data arrays, and tag the
225 * specific managers for an update. This assumes that the scene owns the nodes.
226 */
227 template<typename T> void delete_nodes(const set<T *> &nodes)
228 {
229 delete_nodes(nodes, this);
230 }
231
232 /* Same as above, but specify the actual owner of all the nodes in the set.
233 */
234 template<typename T> void delete_nodes(const set<T *> &nodes, const NodeOwner *owner);
235
236 protected:
237 /* Check if some heavy data worth logging was updated.
238 * Mainly used to suppress extra annoying logging.
239 */
240 bool need_data_update();
241
242 void free_memory(bool final);
243
246
248
252
253 /* Maximum number of closure during session lifetime. */
255
256 /* Get maximum number of closures to be used in kernel. */
258
259 /* Get size of a volume stack needed to render this scene. */
260 int get_volume_stack_size() const;
261
262 bool load_kernels(Progress &progress);
263};
264
278
279template<> void Scene::delete_node(Light *node);
280template<> void Scene::delete_node(Mesh *node);
281template<> void Scene::delete_node(Volume *node);
282template<> void Scene::delete_node(PointCloud *node);
283template<> void Scene::delete_node(Hair *node);
284template<> void Scene::delete_node(Geometry *node);
285template<> void Scene::delete_node(Object *node);
286template<> void Scene::delete_node(ParticleSystem *node);
287template<> void Scene::delete_node(Shader *node);
288template<> void Scene::delete_node(Procedural *node);
289template<> void Scene::delete_node(Pass *node);
290
291template<> void Scene::delete_nodes(const set<Geometry *> &nodes, const NodeOwner *owner);
292template<> void Scene::delete_nodes(const set<Object *> &nodes, const NodeOwner *owner);
293template<> void Scene::delete_nodes(const set<ParticleSystem *> &nodes, const NodeOwner *owner);
294template<> void Scene::delete_nodes(const set<Shader *> &nodes, const NodeOwner *owner);
295template<> void Scene::delete_nodes(const set<Procedural *> &nodes, const NodeOwner *owner);
296template<> void Scene::delete_nodes(const set<Pass *> &nodes, const NodeOwner *owner);
297
unsigned int uint
struct Scene Scene
Definition bvh/bvh.h:67
Definition film.h:29
Definition hair.h:13
Definition pass.h:50
BVHLayout bvh_layout
Definition scene.h:65
bool background
Definition scene.h:76
bool use_bvh_unaligned_nodes
Definition scene.h:70
int texture_limit
Definition scene.h:74
SceneParams()
Definition scene.h:78
bool use_bvh_spatial_split
Definition scene.h:68
int curve_subdivisions()
Definition scene.h:105
CurveShapeType hair_shape
Definition scene.h:73
int num_bvh_time_steps
Definition scene.h:71
int hair_subdivisions
Definition scene.h:72
bool modified(const SceneParams &params) const
Definition scene.h:93
BVHType bvh_type
Definition scene.h:67
bool use_bvh_compact_structure
Definition scene.h:69
ShadingSystem shadingsystem
Definition scene.h:58
#define CCL_NAMESPACE_END
constexpr T clamp(T, U, U) RET
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
AttributeStandard
CurveShapeType
@ CURVE_RIBBON
@ BVH_LAYOUT_AUTO
#define T
KernelBVHLayout BVHLayout
Definition params.h:22
BVHType
Definition params.h:27
@ BVH_TYPE_DYNAMIC
Definition params.h:33
ShadingSystem
@ SHADINGSYSTEM_SVM
bool has_volume_modified() const
Definition scene.cpp:807
bool kernels_loaded
Definition scene.h:244
unique_ptr_vector< Procedural > procedurals
Definition scene.h:142
Film * film
Definition scene.h:128
string name
Definition scene.h:117
unique_ptr< ObjectManager > object_manager
Definition scene.h:150
bool need_global_attribute(AttributeStandard std)
Definition scene.cpp:429
MotionType need_motion() const
Definition scene.cpp:410
void need_global_attributes(AttributeRequestSet &attributes)
Definition scene.cpp:449
bool update(Progress &progress)
Definition scene.cpp:623
unique_ptr< LightManager > light_manager
Definition scene.h:146
Device * device
Definition scene.h:164
unique_ptr< ParticleSystemManager > particle_system_manager
Definition scene.h:151
int get_max_closure_count()
Definition scene.cpp:697
bool scene_updated_while_loading_kernels
Definition scene.h:172
void device_free()
Definition scene.cpp:498
bool has_shadow_catcher_
Definition scene.h:249
Shader * default_volume
Definition scene.h:158
Camera * dicing_camera
Definition scene.h:127
SceneParams params
Definition scene.h:168
unique_ptr_vector< Geometry > geometry
Definition scene.h:140
Shader * default_surface
Definition scene.h:157
unique_ptr< SceneUpdateStats > update_stats
Definition scene.h:175
bool has_volume_modified_
Definition scene.h:251
void tag_shadow_catcher_modified()
Definition scene.cpp:796
void free_memory(bool final)
Definition scene.cpp:88
unique_ptr_vector< Camera > cameras
Definition scene.h:136
Shader * default_empty
Definition scene.h:161
unique_ptr_vector< Background > backgrounds
Definition scene.h:133
void enable_update_stats()
Definition scene.cpp:509
Shader * default_background
Definition scene.h:160
uint loaded_kernel_features
Definition scene.h:245
Light * create_node()
Definition scene.cpp:817
T * create_node(Args &&...)=delete
unique_ptr< BakeManager > bake_manager
Definition scene.h:152
bool shadow_catcher_modified_
Definition scene.h:250
Background * background
Definition scene.h:129
void tag_has_volume_modified()
Definition scene.cpp:812
unique_ptr_vector< Shader > shaders
Definition scene.h:137
MotionType
Definition scene.h:185
@ MOTION_PASS
Definition scene.h:185
@ MOTION_NONE
Definition scene.h:185
@ MOTION_BLUR
Definition scene.h:185
bool has_volume()
Definition scene.cpp:801
void update_kernel_features()
Definition scene.cpp:516
unique_ptr< ShaderManager > shader_manager
Definition scene.h:148
void delete_nodes(const set< T * > &nodes)
Definition scene.h:227
unique_ptr_vector< ParticleSystem > particle_systems
Definition scene.h:139
bool has_shadow_catcher()
Definition scene.cpp:776
unique_ptr< GeometryManager > geometry_manager
Definition scene.h:149
void delete_node(T *node)=delete
~Scene() override
Definition scene.cpp:83
unique_ptr< OSLManager > osl_manager
Definition scene.h:147
unique_ptr_vector< Integrator > integrators
Definition scene.h:135
bool load_kernels(Progress &progress)
Definition scene.cpp:672
int max_closure_global
Definition scene.h:254
unique_ptr_vector< Object > objects
Definition scene.h:141
Integrator * integrator
Definition scene.h:130
thread_mutex mutex
Definition scene.h:171
bool need_data_update()
Definition scene.cpp:463
int get_volume_stack_size() const
Definition scene.cpp:729
unique_ptr< ImageManager > image_manager
Definition scene.h:145
unique_ptr< ProceduralManager > procedural_manager
Definition scene.h:153
bool need_reset(const bool check_camera=true)
Definition scene.cpp:473
struct Object * camera
bool need_update()
Definition scene.cpp:458
Shader * default_light
Definition scene.h:159
unique_ptr< BVH > bvh
Definition scene.h:123
bool update_camera_resolution(Progress &progress, int width, int height)
Definition scene.cpp:636
map< ustring, int > lightgroups
Definition scene.h:120
void reset()
Definition scene.cpp:478
void collect_statistics(RenderStats *stats)
Definition scene.cpp:503
unique_ptr_vector< Pass > passes
Definition scene.h:138
unique_ptr_vector< Film > films
Definition scene.h:134
DeviceScene dscene
Definition scene.h:165
void delete_nodes(const set< T * > &nodes, const NodeOwner *owner)
float motion_shutter_time()
Definition scene.cpp:421
unique_ptr< VolumeManager > volume_manager
Definition scene.h:154
struct Scene * set
unique_ptr< LookupTables > lookup_tables
Definition scene.h:124
void device_update(Device *device, Progress &progress)
Definition scene.cpp:171
std::mutex thread_mutex
Definition thread.h:27