Blender V4.3
sync.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 __BLENDER_SYNC_H__
6#define __BLENDER_SYNC_H__
7
8#include "MEM_guardedalloc.h"
9#include "RNA_access.hh"
10#include "RNA_blender_cpp.hh"
11#include "RNA_path.hh"
12#include "RNA_types.hh"
13
14#include "blender/id_map.h"
15#include "blender/util.h"
16#include "blender/viewport.h"
17
18#include "scene/scene.h"
19#include "session/session.h"
20
21#include "util/map.h"
22#include "util/set.h"
23#include "util/transform.h"
24#include "util/vector.h"
25
27
28class Background;
31class Camera;
32class Film;
33class Hair;
34class Light;
35class Mesh;
36class Object;
37class ParticleSystem;
38class Scene;
39class ViewLayer;
40class Shader;
41class ShaderGraph;
42class ShaderNode;
43class TaskPool;
44
46 public:
47 BlenderSync(BL::RenderEngine &b_engine,
48 BL::BlendData &b_data,
49 BL::Scene &b_scene,
50 Scene *scene,
51 bool preview,
52 bool use_developer_ui,
53 Progress &progress);
55
56 void reset(BL::BlendData &b_data, BL::Scene &b_scene);
57
58 void tag_update();
59
60 /* sync */
61 void sync_recalc(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d);
62 void sync_data(BL::RenderSettings &b_render,
63 BL::Depsgraph &b_depsgraph,
64 BL::SpaceView3D &b_v3d,
65 BL::Object &b_override,
66 int width,
67 int height,
68 void **python_thread_state,
69 const DeviceInfo &denoise_device_info);
70 void sync_view_layer(BL::ViewLayer &b_view_layer);
71 void sync_render_passes(BL::RenderLayer &b_render_layer, BL::ViewLayer &b_view_layer);
72 void sync_integrator(BL::ViewLayer &b_view_layer,
73 bool background,
74 const DeviceInfo &denoise_device_info);
75 void sync_camera(BL::RenderSettings &b_render,
76 BL::Object &b_override,
77 int width,
78 int height,
79 const char *viewname);
80 void sync_view(BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, int width, int height);
81 inline int get_layer_samples()
82 {
83 return view_layer.samples;
84 }
86 {
87 return view_layer.bound_samples;
88 }
89
90 /* Early data free. */
91 void free_data_after_sync(BL::Depsgraph &b_depsgraph);
92
93 /* get parameters */
94 static SceneParams get_scene_params(BL::Scene &b_scene,
95 const bool background,
96 const bool use_developer_ui);
97 static SessionParams get_session_params(BL::RenderEngine &b_engine,
98 BL::Preferences &b_userpref,
99 BL::Scene &b_scene,
100 bool background);
101 static bool get_session_pause(BL::Scene &b_scene, bool background);
103 BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, Camera *cam, int width, int height);
104
105 static DenoiseParams get_denoise_params(BL::Scene &b_scene,
106 BL::ViewLayer &b_view_layer,
107 bool background,
108 const DeviceInfo &denoise_device);
109
110 private:
111 /* sync */
112 void sync_lights(BL::Depsgraph &b_depsgraph, bool update_all);
113 void sync_materials(BL::Depsgraph &b_depsgraph, bool update_all);
114 void sync_objects(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, float motion_time = 0.0f);
115 void sync_motion(BL::RenderSettings &b_render,
116 BL::Depsgraph &b_depsgraph,
117 BL::SpaceView3D &b_v3d,
118 BL::Object &b_override,
119 int width,
120 int height,
121 void **python_thread_state);
122 void sync_film(BL::ViewLayer &b_view_layer, BL::SpaceView3D &b_v3d);
123 void sync_view();
124
125 /* Shader */
126 array<Node *> find_used_shaders(BL::Object &b_ob);
127 void sync_world(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, bool update_all);
128 void sync_shaders(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, bool update_all);
129 void sync_nodes(Shader *shader, BL::ShaderNodeTree &b_ntree);
130
131 bool scene_attr_needs_recalc(Shader *shader, BL::Depsgraph &b_depsgraph);
132 void resolve_view_layer_attributes(Shader *shader,
133 ShaderGraph *graph,
134 BL::Depsgraph &b_depsgraph);
135
136 /* Object */
137 Object *sync_object(BL::Depsgraph &b_depsgraph,
138 BL::ViewLayer &b_view_layer,
139 BL::DepsgraphObjectInstance &b_instance,
140 float motion_time,
141 bool use_particle_hair,
142 bool show_lights,
143 BlenderObjectCulling &culling,
144 bool *use_portal,
145 TaskPool *geom_task_pool);
146 void sync_object_motion_init(BL::Object &b_parent, BL::Object &b_ob, Object *object);
147
148 void sync_procedural(BL::Object &b_ob,
149 BL::MeshSequenceCacheModifier &b_mesh_cache,
150 bool has_subdivision);
151
152 bool sync_object_attributes(BL::DepsgraphObjectInstance &b_instance, Object *object);
153
154 /* Volume */
155 void sync_volume(BObjectInfo &b_ob_info, Volume *volume);
156
157 /* Mesh */
158 void sync_mesh(BL::Depsgraph b_depsgraph, BObjectInfo &b_ob_info, Mesh *mesh);
159 void sync_mesh_motion(BL::Depsgraph b_depsgraph,
160 BObjectInfo &b_ob_info,
161 Mesh *mesh,
162 int motion_step);
163
164 /* Hair */
165 void sync_hair(BL::Depsgraph b_depsgraph, BObjectInfo &b_ob_info, Hair *hair);
166 void sync_hair_motion(BL::Depsgraph b_depsgraph,
167 BObjectInfo &b_ob_info,
168 Hair *hair,
169 int motion_step);
170 void sync_hair(Hair *hair, BObjectInfo &b_ob_info, bool motion, int motion_step = 0);
171 void sync_particle_hair(
172 Hair *hair, BL::Mesh &b_mesh, BObjectInfo &b_ob_info, bool motion, int motion_step = 0);
173 bool object_has_particle_hair(BL::Object b_ob);
174
175 /* Point Cloud */
176 void sync_pointcloud(PointCloud *pointcloud, BObjectInfo &b_ob_info);
177 void sync_pointcloud_motion(PointCloud *pointcloud, BObjectInfo &b_ob_info, int motion_step = 0);
178
179 /* Camera */
180 void sync_camera_motion(
181 BL::RenderSettings &b_render, BL::Object &b_ob, int width, int height, float motion_time);
182
183 /* Geometry */
184 Geometry *sync_geometry(BL::Depsgraph &b_depsgraph,
185 BObjectInfo &b_ob_info,
186 bool object_updated,
187 bool use_particle_hair,
189
190 void sync_geometry_motion(BL::Depsgraph &b_depsgraph,
191 BObjectInfo &b_ob_info,
192 Object *object,
193 float motion_time,
194 bool use_particle_hair,
196
197 /* Light */
198 void sync_light(BL::Object &b_parent,
199 int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
200 BObjectInfo &b_ob_info,
201 int random_id,
202 Transform &tfm,
203 bool *use_portal);
204 void sync_background_light(BL::SpaceView3D &b_v3d, bool use_portal);
205
206 /* Particles */
207 bool sync_dupli_particle(BL::Object &b_ob,
208 BL::DepsgraphObjectInstance &b_instance,
209 Object *object);
210
211 /* Images. */
212 void sync_images();
213
214 /* util */
215 void find_shader(BL::ID &id, array<Node *> &used_shaders, Shader *default_shader);
216 bool BKE_object_is_modified(BL::Object &b_ob);
217 bool object_is_geometry(BObjectInfo &b_ob_info);
218 bool object_can_have_geometry(BL::Object &b_ob);
219 bool object_is_light(BL::Object &b_ob);
220 bool object_is_camera(BL::Object &b_ob);
221
222 /* variables */
223 BL::RenderEngine b_engine;
224 BL::BlendData b_data;
225 BL::Scene b_scene;
226
227 enum ShaderFlags { SHADER_WITH_LAYER_ATTRS };
228
230 id_map<ObjectKey, Object> object_map;
231 id_map<void *, Procedural> procedural_map;
233 id_map<ObjectKey, Light> light_map;
235 set<Geometry *> geometry_synced;
236 set<Geometry *> geometry_motion_synced;
237 set<Geometry *> geometry_motion_attribute_synced;
239 map<void *, set<BL::ID>> instance_geometries_by_object;
240 set<float> motion_times;
241 void *world_map;
242 bool world_recalc;
243 BlenderViewportParameters viewport_parameters;
244
245 Scene *scene;
246 bool preview;
247 bool experimental;
248 bool use_developer_ui;
249
250 float dicing_rate;
251 int max_subdivisions;
252
253 struct RenderLayerInfo {
254 RenderLayerInfo()
255 : material_override(PointerRNA_NULL),
256 world_override(PointerRNA_NULL),
257 use_background_shader(true),
258 use_surfaces(true),
259 use_hair(true),
260 use_volumes(true),
261 use_motion_blur(true),
262 samples(0),
263 bound_samples(false)
264 {
265 }
266
267 string name;
268 BL::Material material_override;
269 BL::World world_override;
270 bool use_background_shader;
271 bool use_surfaces;
272 bool use_hair;
273 bool use_volumes;
274 bool use_motion_blur;
275 int samples;
276 bool bound_samples;
277 } view_layer;
278
279 Progress &progress;
280
281 /* Indicates that `sync_recalc()` detected changes in the scene.
282 * If this flag is false then the data is considered to be up-to-date and will not be
283 * synchronized at all. */
284 bool has_updates_ = true;
285};
286
288
289#endif /* __BLENDER_SYNC_H__ */
Read Guarded memory(de)allocation.
constexpr PointerRNA PointerRNA_NULL
Definition RNA_types.hh:45
void reset()
clear internal cached data and reset random seed
BlenderSync(BL::RenderEngine &b_engine, BL::BlendData &b_data, BL::Scene &b_scene, Scene *scene, bool preview, bool use_developer_ui, Progress &progress)
Definition sync.cpp:40
static DenoiseParams get_denoise_params(BL::Scene &b_scene, BL::ViewLayer &b_view_layer, bool background, const DeviceInfo &denoise_device)
Definition sync.cpp:988
~BlenderSync()
Definition sync.cpp:73
static bool get_session_pause(BL::Scene &b_scene, bool background)
Definition sync.cpp:887
void sync_recalc(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d)
Definition sync.cpp:92
void tag_update()
Definition sync.cpp:85
void sync_data(BL::RenderSettings &b_render, BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, BL::Object &b_override, int width, int height, void **python_thread_state, const DeviceInfo &denoise_device_info)
Definition sync.cpp:250
void sync_camera(BL::RenderSettings &b_render, BL::Object &b_override, int width, int height, const char *viewname)
void sync_render_passes(BL::RenderLayer &b_render_layer, BL::ViewLayer &b_view_layer)
Definition sync.cpp:715
int get_layer_bound_samples()
Definition sync.h:85
void sync_view_layer(BL::ViewLayer &b_view_layer)
Definition sync.cpp:574
void sync_integrator(BL::ViewLayer &b_view_layer, bool background, const DeviceInfo &denoise_device_info)
Definition sync.cpp:304
void free_data_after_sync(BL::Depsgraph &b_depsgraph)
Definition sync.cpp:796
static BufferParams get_buffer_params(BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, Camera *cam, int width, int height)
void sync_view(BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, int width, int height)
static SceneParams get_scene_params(BL::Scene &b_scene, const bool background, const bool use_developer_ui)
Definition sync.cpp:832
int get_layer_samples()
Definition sync.h:81
static SessionParams get_session_params(BL::RenderEngine &b_engine, BL::Preferences &b_userpref, BL::Scene &b_scene, bool background)
Definition sync.cpp:893
Definition film.h:30
Definition hair.h:14
#define CCL_NAMESPACE_END
TaskPool * task_pool
@ OBJECT_PERSISTENT_ID_SIZE
Definition id_map.h:214