Blender V5.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#pragma once
6
7#include "bvh/params.h"
8
9#include "scene/devicescene.h"
10#include "scene/film.h"
11#include "scene/image.h"
13#include "scene/shader.h"
14
15#include "util/param.h"
16#include "util/string.h"
17#include "util/thread.h"
18#include "util/unique_ptr.h"
20
22
24class Background;
25class BVH;
26class Camera;
27class Device;
28class DeviceInfo;
29class Film;
30class Integrator;
31class SceneAttributes;
32class PointLight;
33class SpotLight;
34class AreaLight;
35class SunLight;
36class BackgroundLight;
37class Light;
38class LightManager;
39class LookupTables;
40class Geometry;
41class GeometryManager;
42class Object;
43class ObjectManager;
44class OSLManager;
46class ParticleSystem;
47class PointCloud;
48class Procedural;
50class CurveSystemManager;
51class Shader;
52class ShaderManager;
53class Progress;
54class BakeManager;
55class BakeData;
56class RenderStats;
58class Volume;
59class VolumeManager;
60
61/* Scene Parameters */
62
64 public:
66
67 /* Requested BVH layout.
68 *
69 * If it's not supported by the device, the widest one from supported ones
70 * will be used, but BVH wider than this one will never be used.
71 */
73
83
84 /* Use tx files if they exist. */
85 bool use_texture_cache = true;
86 /* Auto generate tx files. */
87 bool auto_texture_cache = false;
88 /* Relative (to the image file) or absolute directory for auto generating tx files. */
89 std::string texture_cache_path;
90
92
108
123
125 {
126 /* Matching the tessellation rate limit in Embree. */
127 return clamp(1 << hair_subdivisions, 1, 16);
128 }
129};
130
131/* Scene */
132
133class Scene : public NodeOwner {
134 public:
135 /* Optional name. Is used for logging and reporting. */
136 string name;
137
138 /* Maps from Light group names to their pass ID. */
139 map<ustring, int> lightgroups;
140
141 /* data */
144
151
152 /* data lists */
164
165 /* data managers */
176
177 /* default shaders */
184
185 /* device */
188
189 /* parameters */
191
192 /* mutex must be locked manually by callers */
195
196 /* scene update statistics */
198
200 ~Scene() override;
201
202 void device_update(Device *device, Progress &progress);
203
206
208 MotionType need_motion() const;
209 float motion_shutter_time();
210
211 bool need_update();
212 bool need_reset(const bool check_camera = true);
213
214 void reset();
215 void device_free();
216
217 void collect_statistics(RenderStats *stats);
218
219 void enable_update_stats();
220
221 bool update(Progress &progress);
222 bool update_camera_resolution(Progress &progress, int width, int height);
223
224 bool has_shadow_catcher();
226 bool has_volume();
227 bool has_volume_modified() const;
229 /* Check if we use multiple importance sampling for any light in the scene. */
230 bool use_light_mis() const;
231
232 /* This function is used to create a node of a specified type instead of
233 * calling 'new', and sets the scene as the owner of the node.
234 * The function has overloads that will also add the created node to the right
235 * node array (e.g. Scene::geometry for Geometry nodes) and tag the appropriate
236 * manager for an update.
237 */
238 template<typename T, typename... Args> T *create_node(Args &&.../*args*/) = delete;
239
240 /* This function is used to delete a node from the scene instead of calling 'delete'
241 * and manually removing the node from the data array. It also tags the
242 * appropriate manager for an update, if any, and checks that the scene is indeed
243 * the owner of the node. Calling this function on a node not owned by the scene
244 * will likely cause a crash which we want in order to detect such cases.
245 */
246 template<typename T> void delete_node(T *node) = delete;
247
248 /* Remove all nodes in the set from the appropriate data arrays, and tag the
249 * specific managers for an update. This assumes that the scene owns the nodes.
250 */
251 template<typename T> void delete_nodes(const set<T *> &nodes)
252 {
253 delete_nodes(nodes, this);
254 }
255
256 /* Same as above, but specify the actual owner of all the nodes in the set.
257 */
258 template<typename T> void delete_nodes(const set<T *> &nodes, const NodeOwner *owner);
259
260 template<class T> T *create_light_node();
261
262 protected:
263 /* Check if some heavy data worth logging was updated.
264 * Mainly used to suppress extra annoying logging.
265 */
266 bool need_data_update();
267
268 void free_memory(bool final);
269
272
274
278
279 /* Maximum number of closure during session lifetime. */
281
282 /* Get maximum number of closures to be used in kernel. */
284
285 /* Get size of a volume stack needed to render this scene. */
286 int get_volume_stack_size() const;
287
288 bool load_kernels(Progress &progress);
289};
290
309
310template<> void Scene::delete_node(Light *node);
311template<> void Scene::delete_node(Mesh *node);
314template<> void Scene::delete_node(Hair *node);
320template<> void Scene::delete_node(Pass *node);
321
322template<> void Scene::delete_nodes(const set<Geometry *> &nodes, const NodeOwner *owner);
323template<> void Scene::delete_nodes(const set<Object *> &nodes, const NodeOwner *owner);
324template<> void Scene::delete_nodes(const set<ParticleSystem *> &nodes, const NodeOwner *owner);
325template<> void Scene::delete_nodes(const set<Shader *> &nodes, const NodeOwner *owner);
326template<> void Scene::delete_nodes(const set<Procedural *> &nodes, const NodeOwner *owner);
327template<> void Scene::delete_nodes(const set<Pass *> &nodes, const NodeOwner *owner);
328
unsigned long long int uint64_t
void reset()
Definition bvh/bvh.h:67
Definition film.h:29
Definition hair.h:13
Definition pass.h:50
std::string texture_cache_path
Definition scene.h:89
BVHLayout bvh_layout
Definition scene.h:72
bool background
Definition scene.h:91
bool use_bvh_unaligned_nodes
Definition scene.h:77
int texture_limit
Definition scene.h:82
float texture_resolution
Definition scene.h:81
bool auto_texture_cache
Definition scene.h:87
SceneParams()
Definition scene.h:93
bool use_bvh_spatial_split
Definition scene.h:75
int curve_subdivisions()
Definition scene.h:124
CurveShapeType hair_shape
Definition scene.h:80
int num_bvh_time_steps
Definition scene.h:78
int hair_subdivisions
Definition scene.h:79
bool modified(const SceneParams &params) const
Definition scene.h:109
BVHType bvh_type
Definition scene.h:74
bool use_bvh_compact_structure
Definition scene.h:76
bool use_texture_cache
Definition scene.h:85
ShadingSystem shadingsystem
Definition scene.h:65
bool has_volume_modified() const
Definition scene.cpp:849
bool kernels_loaded
Definition scene.h:270
unique_ptr_vector< Procedural > procedurals
Definition scene.h:163
Film * film
Definition scene.h:147
string name
Definition scene.h:136
unique_ptr< ObjectManager > object_manager
Definition scene.h:171
bool need_global_attribute(AttributeStandard std) const
Definition scene.cpp:455
MotionType need_motion() const
Definition scene.cpp:429
void need_global_attributes(AttributeRequestSet &attributes)
Definition scene.cpp:469
Scene(const SceneParams &params, Device *device)
Definition scene.cpp:41
bool update(Progress &progress)
Definition scene.cpp:652
unique_ptr< LightManager > light_manager
Definition scene.h:167
T * create_light_node()
Definition scene.cpp:875
Device * device
Definition scene.h:186
unique_ptr< ParticleSystemManager > particle_system_manager
Definition scene.h:172
int get_max_closure_count()
Definition scene.cpp:739
bool scene_updated_while_loading_kernels
Definition scene.h:194
void device_free()
Definition scene.cpp:523
bool has_shadow_catcher_
Definition scene.h:275
Shader * default_volume
Definition scene.h:179
Camera * dicing_camera
Definition scene.h:146
SceneParams params
Definition scene.h:190
unique_ptr_vector< Geometry > geometry
Definition scene.h:161
Shader * default_surface
Definition scene.h:178
unique_ptr< SceneUpdateStats > update_stats
Definition scene.h:197
bool has_volume_modified_
Definition scene.h:277
void tag_shadow_catcher_modified()
Definition scene.cpp:838
void free_memory(bool final)
Definition scene.cpp:90
unique_ptr_vector< Camera > cameras
Definition scene.h:157
Shader * default_empty
Definition scene.h:182
unique_ptr_vector< SceneAttributes > scene_attributes
Definition scene.h:156
unique_ptr_vector< Background > backgrounds
Definition scene.h:153
void enable_update_stats()
Definition scene.cpp:534
Shader * default_background
Definition scene.h:181
Shader * default_gsplat
Definition scene.h:183
T * create_node(Args &&...)=delete
unique_ptr< BakeManager > bake_manager
Definition scene.h:173
bool shadow_catcher_modified_
Definition scene.h:276
Background * background
Definition scene.h:148
void tag_has_volume_modified()
Definition scene.cpp:854
unique_ptr_vector< Shader > shaders
Definition scene.h:158
PointLight * create_node()
Definition scene.cpp:885
MotionType
Definition scene.h:207
@ MOTION_PASS
Definition scene.h:207
@ MOTION_NONE
Definition scene.h:207
@ MOTION_BLUR
Definition scene.h:207
@ MOTION_PASS_INTERACTIVE
Definition scene.h:207
bool has_volume()
Definition scene.cpp:843
void update_kernel_features()
Definition scene.cpp:541
unique_ptr< ShaderManager > shader_manager
Definition scene.h:169
void delete_nodes(const set< T * > &nodes)
Definition scene.h:251
Camera * camera
Definition scene.h:145
unique_ptr_vector< ParticleSystem > particle_systems
Definition scene.h:160
bool has_shadow_catcher()
Definition scene.cpp:818
unique_ptr< GeometryManager > geometry_manager
Definition scene.h:170
void delete_node(T *node)=delete
bool use_light_mis() const
Definition scene.cpp:859
unique_ptr< OSLManager > osl_manager
Definition scene.h:168
unique_ptr_vector< Integrator > integrators
Definition scene.h:155
bool load_kernels(Progress &progress)
Definition scene.cpp:714
int max_closure_global
Definition scene.h:280
unique_ptr_vector< Object > objects
Definition scene.h:162
Integrator * integrator
Definition scene.h:149
uint64_t loaded_kernel_features
Definition scene.h:271
thread_mutex mutex
Definition scene.h:193
bool need_data_update()
Definition scene.cpp:487
int get_volume_stack_size() const
Definition scene.cpp:771
unique_ptr< ImageManager > image_manager
Definition scene.h:166
unique_ptr< ProceduralManager > procedural_manager
Definition scene.h:174
bool need_reset(const bool check_camera=true)
Definition scene.cpp:497
SceneAttributes * scene_attribute
Definition scene.h:150
bool need_update()
Definition scene.cpp:482
Shader * default_light
Definition scene.h:180
unique_ptr< BVH > bvh
Definition scene.h:142
bool update_camera_resolution(Progress &progress, int width, int height)
Definition scene.cpp:665
map< ustring, int > lightgroups
Definition scene.h:139
void collect_statistics(RenderStats *stats)
Definition scene.cpp:528
unique_ptr_vector< Pass > passes
Definition scene.h:159
unique_ptr_vector< Film > films
Definition scene.h:154
DeviceScene dscene
Definition scene.h:187
void delete_nodes(const set< T * > &nodes, const NodeOwner *owner)
float motion_shutter_time()
Definition scene.cpp:447
unique_ptr< VolumeManager > volume_manager
Definition scene.h:175
unique_ptr< LookupTables > lookup_tables
Definition scene.h:143
void device_update(Device *device, Progress &progress)
Definition scene.cpp:176
#define CCL_NAMESPACE_END
constexpr T clamp(T, U, U) RET
CurveShapeType
@ CURVE_RIBBON
@ BVH_LAYOUT_AUTO
AttributeStandard
#define T
KernelBVHLayout BVHLayout
Definition params.h:22
BVHType
Definition params.h:27
@ BVH_TYPE_DYNAMIC
Definition params.h:33
ShadingSystem
@ SHADINGSYSTEM_SVM
std::mutex thread_mutex
Definition thread.h:27