Blender V5.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#pragma once
6
7#include "DNA_userdef_types.h"
8#include "RNA_types.hh"
9
10#include "blender/id_map.h"
11#include "blender/util.h"
12#include "blender/viewport.h"
13
14#include "scene/scene.h"
15#include "session/session.h"
16
17#include "util/map.h"
18#include "util/set.h"
19
20namespace blender {
22struct MeshSequenceCacheModifier;
23} // namespace blender
24
26
27class Background;
30class Camera;
31class Film;
32class Hair;
33class Light;
34class Mesh;
35class Object;
36class ParticleSystem;
37class Scene;
38class Shader;
39class ShaderGraph;
40class TaskPool;
41
43 public:
45 blender::Main &b_data,
46 blender::Scene &b_scene,
47 Scene *scene,
48 bool preview,
49 bool use_developer_ui,
50 Progress &progress);
52
53 void reset(blender::Main &b_data, blender::Scene &b_scene);
54
55 void tag_update();
56
57 void set_bake_target(blender::Object &b_object);
58
59 /* sync */
60 void sync_recalc(blender::Depsgraph &b_depsgraph,
61 blender::bScreen *b_screen,
62 blender::View3D *b_v3d,
63 blender::RegionView3D *b_rv3d);
64 void sync_data(blender::RenderData &b_render,
65 blender::Depsgraph &b_depsgraph,
66 blender::bScreen *b_screen,
67 blender::View3D *b_v3d,
69 const int width,
70 const int height,
71 const DeviceInfo &denoise_device_info);
72 void sync_view_layer(blender::ViewLayer &b_view_layer);
74 void sync_integrator(blender::ViewLayer &b_view_layer,
75 bool background,
76 const DeviceInfo &denoise_device_info);
78 void sync_camera(const blender::RenderData &b_render,
79 const int width,
80 const int height,
81 const char *viewname);
82 void sync_view(const blender::Depsgraph *b_depsgraph,
83 blender::View3D *b_v3d,
85 const int width,
86 const int height);
88 {
89 return view_layer.samples;
90 }
92 {
93 return view_layer.bound_samples;
94 }
95
96 /* Early data free. */
97 void free_data_after_sync(blender::Depsgraph &b_depsgraph);
98
99 /* get parameters */
100 static SceneParams get_scene_params(blender::UserDef &b_preferences,
101 blender::Main &b_data,
102 blender::Scene &b_scene,
103 const bool background,
104 const bool use_developer_ui);
106 blender::UserDef &b_preferences,
107 blender::Scene &b_scene,
108 bool background,
109 float pixelsize);
111 blender::RegionView3D *b_rv3d,
112 Camera *cam,
113 const int width,
114 const int height);
115
117 blender::ViewLayer *b_view_layer,
118 bool background,
119 const DeviceInfo &denoise_device);
120
121 private:
122 /* sync */
123 void sync_lights(blender::Depsgraph &b_depsgraph, bool update_all, bool update_time);
124 void sync_materials(blender::Depsgraph &b_depsgraph, bool update_all, bool update_time);
125 void sync_objects(blender::Depsgraph &b_depsgraph,
126 blender::bScreen *b_screen,
127 blender::View3D *b_v3d,
128 const float motion_time = 0.0f);
129 void sync_objects_and_motion(blender::RenderData &b_render,
130 blender::Depsgraph &b_depsgraph,
131 blender::bScreen *b_screen,
132 blender::View3D *b_v3d,
133 blender::RegionView3D *b_rv3d,
134 const int width,
135 const int height);
136 void sync_film(blender::ViewLayer &b_view_layer,
137 blender::bScreen *b_screen,
138 blender::View3D *b_v3d);
139 void sync_view();
140
141 /* Shader */
142 array<Node *> find_used_shaders(blender::Object &b_ob);
143 void sync_world(blender::Depsgraph &b_depsgraph,
144 blender::bScreen *b_screen,
145 blender::View3D *b_v3d,
146 bool update_all,
147 bool update_time);
148 void sync_shaders(blender::Depsgraph &b_depsgraph,
149 blender::bScreen *b_screen,
150 blender::View3D *b_v3d,
151 bool update_all,
152 bool update_time);
153 void sync_nodes(Shader *shader, blender::bNodeTree &b_ntree);
154
155 bool scene_attr_needs_recalc(Shader *shader, blender::Depsgraph &b_depsgraph);
156 void resolve_view_layer_attributes(Shader *shader,
157 ShaderGraph *graph,
158 blender::Depsgraph &b_depsgraph);
159
160 /* Object */
161 Object *sync_object(blender::ViewLayer &b_view_layer,
162 blender::Object &b_ob,
163 blender::DEGObjectIterData &b_deg_iter_data,
164 const float motion_time,
165 bool use_particle_hair,
166 bool show_lights,
167 BlenderObjectCulling &culling,
168 TaskPool *geom_task_pool);
169 void sync_object_motion_init(blender::Object &b_parent, blender::Object &b_ob, Object *object);
170
171 void sync_procedural(blender::Object &b_ob,
172 blender::MeshSequenceCacheModifier &b_mesh_cache,
173 bool has_subdivision);
174
175 bool sync_object_attributes(blender::Object &b_ob,
176 blender::DEGObjectIterData &b_deg_iter_data,
177 Object *object);
178
179 /* Volume */
180 void sync_volume(BObjectInfo &b_ob_info, Volume *volume);
181
182 /* Mesh */
183 void sync_mesh(BObjectInfo &b_ob_info, Mesh *mesh);
184 void sync_mesh_motion(BObjectInfo &b_ob_info, Mesh *mesh, int motion_step);
185
186 /* Hair */
187 void sync_hair(BObjectInfo &b_ob_info, Hair *hair);
188 void sync_hair_motion(BObjectInfo &b_ob_info, Hair *hair, int motion_step);
189 void sync_hair(Hair *hair, BObjectInfo &b_ob_info, bool motion, const int motion_step = 0);
190 void sync_particle_hair(Hair *hair,
191 const blender::Mesh &b_mesh,
192 BObjectInfo &b_ob_info,
193 bool motion,
194 const int motion_step = 0);
195 bool object_has_particle_hair(blender::Object *b_ob);
196
197 /* Point Cloud */
198 void sync_pointcloud(PointCloud *pointcloud, BObjectInfo &b_ob_info);
199 void sync_pointcloud_motion(PointCloud *pointcloud,
200 BObjectInfo &b_ob_info,
201 const int motion_step = 0);
202
203 /* Camera */
204 void sync_camera_motion(const blender::RenderData &b_render,
205 blender::Object *b_ob,
206 const int width,
207 const int height,
208 const float motion_time);
209
210 /* Geometry */
211 Geometry *sync_geometry(BObjectInfo &b_ob_info,
212 bool object_updated,
213 bool use_particle_hair,
214 TaskPool *task_pool);
215
216 void sync_geometry_motion(BObjectInfo &b_ob_info,
217 Object *object,
218 const float motion_time,
219 bool use_particle_hair,
220 TaskPool *task_pool);
221
222 /* Light */
223 Geometry *create_light(BObjectInfo &b_ob_info);
224 void sync_light(BObjectInfo &b_ob_info, Light *light);
225 void sync_background_light(blender::bScreen *b_screen, blender::View3D *b_v3d);
226
227 /* Particles */
228 bool sync_dupli_particle(blender::Object &b_parent,
229 blender::DEGObjectIterData &b_deg_iter_data,
230 blender::Object &b_ob,
231 Object *object);
232
233 /* Images. */
234 void sync_images();
235
236 /* util */
237 void find_shader(const blender::ID *id, array<Node *> &used_shaders, Shader *default_shader);
238 bool BKE_object_is_modified(blender::Object &b_ob);
239 bool object_is_geometry(BObjectInfo &b_ob_info);
240 bool object_can_have_geometry(blender::Object &b_ob);
241 bool object_is_light(blender::Object &b_ob);
242 bool object_is_camera(blender::Object &b_ob);
243
244 blender::Object *get_camera_object(blender::View3D *b_v3d, blender::RegionView3D *b_rv3d);
245 blender::Object *get_dicing_camera_object(blender::View3D *b_v3d, blender::RegionView3D *b_rv3d);
246
247 /* variables */
248 blender::RenderEngine *b_engine;
249 blender::Main *b_data;
250 blender::Scene *b_scene;
251 blender::Object *b_bake_target;
252
253 enum ShaderFlags { SHADER_WITH_LAYER_ATTRS };
254
255 id_map<const void *, Shader, ShaderFlags> shader_map;
256 /* To keep track of the AOVs in consecutive view layers that are rendered, this is the old data
257 * for comparing. */
258 blender::Vector<std::pair<std::string, int>> shader_view_layer_aovs;
259 id_map<ObjectKey, Object> object_map;
260 id_map<void *, Procedural> procedural_map;
261 id_map<GeometryKey, Geometry> geometry_map;
262 id_map<ParticleSystemKey, ParticleSystem> particle_system_map;
263 set<Geometry *> geometry_synced;
264 set<Geometry *> geometry_motion_synced;
265 set<Geometry *> geometry_motion_attribute_synced;
267 map<void *, set<blender::ID *>> instance_geometries_by_object;
268 set<float> motion_times;
269 void *world_map;
270 bool world_recalc;
271 BlenderViewportParameters viewport_parameters;
272
273 Scene *scene;
274 bool preview;
275 bool use_adaptive_subdivision = false;
276 bool use_developer_ui;
277
278 CurveShapeType curve_shape = CURVE_RIBBON;
279
280 float dicing_rate;
281 int max_subdivisions;
282
283 struct RenderLayerInfo {
284 string name;
285 blender::Material *material_override = nullptr;
286 blender::World *world_override = nullptr;
287 bool use_background_shader = true;
288 bool use_surfaces = true;
289 bool use_hair = true;
290 bool use_volumes = true;
291 bool use_motion_blur = true;
292 int samples = 0;
293 bool bound_samples = false;
294 } view_layer;
295
296 Progress &progress;
297
298 /* Indicates that `sync_recalc()` detected changes in the scene.
299 * If this flag is false then the data is considered to be up-to-date and will not be
300 * synchronized at all. */
301 bool has_updates_ = true;
302
303 float frame_last_synced = 0;
304};
305
static SessionParams get_session_params(blender::RenderEngine &b_engine, blender::UserDef &b_preferences, blender::Scene &b_scene, bool background, float pixelsize)
Definition sync.cpp:1035
static BufferParams get_buffer_params(blender::View3D *b_v3d, blender::RegionView3D *b_rv3d, Camera *cam, const int width, const int height)
void sync_data(blender::RenderData &b_render, blender::Depsgraph &b_depsgraph, blender::bScreen *b_screen, blender::View3D *b_v3d, blender::RegionView3D *b_rv3d, const int width, const int height, const DeviceInfo &denoise_device_info)
Definition sync.cpp:298
void set_bake_target(blender::Object &b_object)
Definition sync.cpp:102
BlenderSync(blender::RenderEngine &b_engine, blender::Main &b_data, blender::Scene &b_scene, Scene *scene, bool preview, bool use_developer_ui, Progress &progress)
Definition sync.cpp:52
void tag_update()
Definition sync.cpp:97
void reset(blender::Main &b_data, blender::Scene &b_scene)
Definition sync.cpp:87
void sync_view_layer(blender::ViewLayer &b_view_layer)
Definition sync.cpp:674
void sync_render_passes(blender::RenderLayer &b_rlay, blender::ViewLayer &b_view_layer)
Definition sync.cpp:833
void sync_integrator(blender::ViewLayer &b_view_layer, bool background, const DeviceInfo &denoise_device_info)
Definition sync.cpp:354
int get_layer_bound_samples()
Definition sync.h:91
static DenoiseParams get_denoise_params(blender::Scene &b_scene, blender::ViewLayer *b_view_layer, bool background, const DeviceInfo &denoise_device)
Definition sync.cpp:1143
void sync_view(const blender::Depsgraph *b_depsgraph, blender::View3D *b_v3d, blender::RegionView3D *b_rv3d, const int width, const int height)
void free_data_after_sync(blender::Depsgraph &b_depsgraph)
Definition sync.cpp:908
void sync_recalc(blender::Depsgraph &b_depsgraph, blender::bScreen *b_screen, blender::View3D *b_v3d, blender::RegionView3D *b_rv3d)
Definition sync.cpp:109
void sync_scene_attributes()
Definition sync.cpp:599
int get_layer_samples()
Definition sync.h:87
void sync_camera(const blender::RenderData &b_render, const int width, const int height, const char *viewname)
static SceneParams get_scene_params(blender::UserDef &b_preferences, blender::Main &b_data, blender::Scene &b_scene, const bool background, const bool use_developer_ui)
Definition sync.cpp:968
Definition film.h:29
Definition hair.h:13
Definition scene.h:133
#define CCL_NAMESPACE_END
CurveShapeType
@ CURVE_RIBBON
BMesh Iterators.