Blender V4.5
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
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;
38class OSLManager;
40class ParticleSystem;
41class PointCloud;
42class Procedural;
44class CurveSystemManager;
45class Shader;
46class ShaderManager;
47class Progress;
48class BakeManager;
49class BakeData;
50class RenderStats;
52class Volume;
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 */
154
155 /* default shaders */
161
162 /* device */
165
166 /* parameters */
168
169 /* mutex must be locked manually by callers */
172
173 /* scene update statistics */
175
177 ~Scene() override;
178
180
183
185 MotionType need_motion() const;
186 float motion_shutter_time();
187
188 bool need_update();
189 bool need_reset(const bool check_camera = true);
190
191 void reset();
192 void device_free();
193
194 void collect_statistics(RenderStats *stats);
195
196 void enable_update_stats();
197
198 bool update(Progress &progress);
199 bool update_camera_resolution(Progress &progress, int width, int height);
200
201 bool has_shadow_catcher();
203
204 /* This function is used to create a node of a specified type instead of
205 * calling 'new', and sets the scene as the owner of the node.
206 * The function has overloads that will also add the created node to the right
207 * node array (e.g. Scene::geometry for Geometry nodes) and tag the appropriate
208 * manager for an update.
209 */
210 template<typename T, typename... Args> T *create_node(Args &&.../*args*/) = delete;
211
212 /* This function is used to delete a node from the scene instead of calling 'delete'
213 * and manually removing the node from the data array. It also tags the
214 * appropriate manager for an update, if any, and checks that the scene is indeed
215 * the owner of the node. Calling this function on a node not owned by the scene
216 * will likely cause a crash which we want in order to detect such cases.
217 */
218 template<typename T> void delete_node(T *node) = delete;
219
220 /* Remove all nodes in the set from the appropriate data arrays, and tag the
221 * specific managers for an update. This assumes that the scene owns the nodes.
222 */
223 template<typename T> void delete_nodes(const set<T *> &nodes)
224 {
225 delete_nodes(nodes, this);
226 }
227
228 /* Same as above, but specify the actual owner of all the nodes in the set.
229 */
230 template<typename T> void delete_nodes(const set<T *> &nodes, const NodeOwner *owner);
231
232 protected:
233 /* Check if some heavy data worth logging was updated.
234 * Mainly used to suppress extra annoying logging.
235 */
236 bool need_data_update();
237
238 void free_memory(bool final);
239
242
244
247
248 /* Maximum number of closure during session lifetime. */
250
251 /* Get maximum number of closures to be used in kernel. */
253
254 /* Get size of a volume stack needed to render this scene. */
255 int get_volume_stack_size() const;
256
258};
259
268template<> AlembicProcedural *Scene::create_node<AlembicProcedural>();
274
275template<> void Scene::delete_node(Light *node);
276template<> void Scene::delete_node(Mesh *node);
277template<> void Scene::delete_node(Volume *node);
278template<> void Scene::delete_node(PointCloud *node);
279template<> void Scene::delete_node(Hair *node);
280template<> void Scene::delete_node(Geometry *node);
281template<> void Scene::delete_node(Object *node);
282template<> void Scene::delete_node(ParticleSystem *node);
283template<> void Scene::delete_node(Shader *node);
284template<> void Scene::delete_node(Procedural *node);
285template<> void Scene::delete_node(AlembicProcedural *node);
286template<> void Scene::delete_node(Pass *node);
287
288template<> void Scene::delete_nodes(const set<Geometry *> &nodes, const NodeOwner *owner);
289template<> void Scene::delete_nodes(const set<Object *> &nodes, const NodeOwner *owner);
290template<> void Scene::delete_nodes(const set<ParticleSystem *> &nodes, const NodeOwner *owner);
291template<> void Scene::delete_nodes(const set<Shader *> &nodes, const NodeOwner *owner);
292template<> void Scene::delete_nodes(const set<Procedural *> &nodes, const NodeOwner *owner);
293template<> void Scene::delete_nodes(const set<Pass *> &nodes, const NodeOwner *owner);
294
unsigned int uint
struct Scene Scene
float progress
Definition WM_types.hh:1019
Definition bvh/bvh.h:67
Definition film.h:29
Definition hair.h:13
Definition pass.h:49
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 kernels_loaded
Definition scene.h:240
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:418
MotionType need_motion() const
Definition scene.cpp:399
void need_global_attributes(AttributeRequestSet &attributes)
Definition scene.cpp:438
bool update(Progress &progress)
Definition scene.cpp:592
unique_ptr< LightManager > light_manager
Definition scene.h:146
Device * device
Definition scene.h:163
unique_ptr< ParticleSystemManager > particle_system_manager
Definition scene.h:151
int get_max_closure_count()
Definition scene.cpp:673
bool scene_updated_while_loading_kernels
Definition scene.h:171
void device_free()
Definition scene.cpp:487
bool has_shadow_catcher_
Definition scene.h:245
Shader * default_volume
Definition scene.h:157
Camera * dicing_camera
Definition scene.h:127
SceneParams params
Definition scene.h:167
unique_ptr_vector< Geometry > geometry
Definition scene.h:140
Shader * default_surface
Definition scene.h:156
unique_ptr< SceneUpdateStats > update_stats
Definition scene.h:174
void tag_shadow_catcher_modified()
Definition scene.cpp:772
void free_memory(bool final)
Definition scene.cpp:85
unique_ptr_vector< Camera > cameras
Definition scene.h:136
Shader * default_empty
Definition scene.h:160
unique_ptr_vector< Background > backgrounds
Definition scene.h:133
void enable_update_stats()
Definition scene.cpp:498
Shader * default_background
Definition scene.h:159
uint loaded_kernel_features
Definition scene.h:241
Light * create_node()
Definition scene.cpp:777
T * create_node(Args &&...)=delete
unique_ptr< BakeManager > bake_manager
Definition scene.h:152
bool shadow_catcher_modified_
Definition scene.h:246
Background * background
Definition scene.h:129
unique_ptr_vector< Shader > shaders
Definition scene.h:137
MotionType
Definition scene.h:184
@ MOTION_PASS
Definition scene.h:184
@ MOTION_NONE
Definition scene.h:184
@ MOTION_BLUR
Definition scene.h:184
void update_kernel_features()
Definition scene.cpp:505
unique_ptr< ShaderManager > shader_manager
Definition scene.h:148
void delete_nodes(const set< T * > &nodes)
Definition scene.h:223
unique_ptr_vector< ParticleSystem > particle_systems
Definition scene.h:139
bool has_shadow_catcher()
Definition scene.cpp:752
unique_ptr< GeometryManager > geometry_manager
Definition scene.h:149
void delete_node(T *node)=delete
~Scene() override
Definition scene.cpp:80
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:648
int max_closure_global
Definition scene.h:249
unique_ptr_vector< Object > objects
Definition scene.h:141
Integrator * integrator
Definition scene.h:130
thread_mutex mutex
Definition scene.h:170
bool need_data_update()
Definition scene.cpp:452
int get_volume_stack_size() const
Definition scene.cpp:705
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:462
struct Object * camera
bool need_update()
Definition scene.cpp:447
Shader * default_light
Definition scene.h:158
unique_ptr< BVH > bvh
Definition scene.h:123
bool update_camera_resolution(Progress &progress, int width, int height)
Definition scene.cpp:605
map< ustring, int > lightgroups
Definition scene.h:120
void reset()
Definition scene.cpp:467
void collect_statistics(RenderStats *stats)
Definition scene.cpp:492
unique_ptr_vector< Pass > passes
Definition scene.h:138
unique_ptr_vector< Film > films
Definition scene.h:134
DeviceScene dscene
Definition scene.h:164
void delete_nodes(const set< T * > &nodes, const NodeOwner *owner)
float motion_shutter_time()
Definition scene.cpp:410
struct Scene * set
unique_ptr< LookupTables > lookup_tables
Definition scene.h:124
void device_update(Device *device, Progress &progress)
Definition scene.cpp:168
std::mutex thread_mutex
Definition thread.h:27