Blender V4.5
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 "RNA_blender_cpp.hh"
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
21
22class Background;
25class Camera;
26class Film;
27class Hair;
28class Light;
29class Mesh;
30class Object;
31class ParticleSystem;
32class Scene;
33class Shader;
34class ShaderGraph;
35class TaskPool;
36
38 public:
39 BlenderSync(BL::RenderEngine &b_engine,
40 BL::BlendData &b_data,
41 BL::Scene &b_scene,
42 Scene *scene,
43 bool preview,
44 bool use_developer_ui,
45 Progress &progress);
47
48 void reset(BL::BlendData &b_data, BL::Scene &b_scene);
49
50 void tag_update();
51
52 void set_bake_target(BL::Object &b_object);
53
54 /* sync */
55 void sync_recalc(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d);
56 void sync_data(BL::RenderSettings &b_render,
57 BL::Depsgraph &b_depsgraph,
58 BL::SpaceView3D &b_v3d,
59 BL::Object &b_override,
60 const int width,
61 const int height,
62 void **python_thread_state,
63 const DeviceInfo &denoise_device_info);
64 void sync_view_layer(BL::ViewLayer &b_view_layer);
65 void sync_render_passes(BL::RenderLayer &b_rlay, BL::ViewLayer &b_view_layer);
66 void sync_integrator(BL::ViewLayer &b_view_layer,
67 bool background,
68 const DeviceInfo &denoise_device_info);
69 void sync_camera(BL::RenderSettings &b_render,
70 BL::Object &b_override,
71 const int width,
72 const int height,
73 const char *viewname);
74 void sync_view(BL::SpaceView3D &b_v3d,
75 BL::RegionView3D &b_rv3d,
76 const int width,
77 const int height);
79 {
80 return view_layer.samples;
81 }
83 {
84 return view_layer.bound_samples;
85 }
86
87 /* Early data free. */
88 void free_data_after_sync(BL::Depsgraph &b_depsgraph);
89
90 /* get parameters */
91 static SceneParams get_scene_params(BL::Scene &b_scene,
92 const bool background,
93 const bool use_developer_ui);
94 static SessionParams get_session_params(BL::RenderEngine &b_engine,
95 BL::Preferences &b_preferences,
96 BL::Scene &b_scene,
97 bool background);
98 static bool get_session_pause(BL::Scene &b_scene, bool background);
99 static BufferParams get_buffer_params(BL::SpaceView3D &b_v3d,
100 BL::RegionView3D &b_rv3d,
101 Camera *cam,
102 const int width,
103 const 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,
115 BL::SpaceView3D &b_v3d,
116 const float motion_time = 0.0f);
117 void sync_motion(BL::RenderSettings &b_render,
118 BL::Depsgraph &b_depsgraph,
119 BL::SpaceView3D &b_v3d,
120 BL::Object &b_override,
121 const int width,
122 const int height,
123 void **python_thread_state);
124 void sync_film(BL::ViewLayer &b_view_layer, BL::SpaceView3D &b_v3d);
125 void sync_view();
126
127 /* Shader */
128 array<Node *> find_used_shaders(BL::Object &b_ob);
129 void sync_world(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, bool update_all);
130 void sync_shaders(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, bool update_all);
131 void sync_nodes(Shader *shader, BL::ShaderNodeTree &b_ntree);
132
133 bool scene_attr_needs_recalc(Shader *shader, BL::Depsgraph &b_depsgraph);
134 void resolve_view_layer_attributes(Shader *shader,
135 ShaderGraph *graph,
136 BL::Depsgraph &b_depsgraph);
137
138 /* Object */
139 Object *sync_object(BL::ViewLayer &b_view_layer,
140 BL::DepsgraphObjectInstance &b_instance,
141 const float motion_time,
142 bool use_particle_hair,
143 bool show_lights,
144 BlenderObjectCulling &culling,
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(BObjectInfo &b_ob_info, Mesh *mesh);
159 void sync_mesh_motion(BObjectInfo &b_ob_info, Mesh *mesh, int motion_step);
160
161 /* Hair */
162 void sync_hair(BObjectInfo &b_ob_info, Hair *hair);
163 void sync_hair_motion(BObjectInfo &b_ob_info, Hair *hair, int motion_step);
164 void sync_hair(Hair *hair, BObjectInfo &b_ob_info, bool motion, const int motion_step = 0);
165 void sync_particle_hair(Hair *hair,
166 BL::Mesh &b_mesh,
167 BObjectInfo &b_ob_info,
168 bool motion,
169 const int motion_step = 0);
170 bool object_has_particle_hair(BL::Object b_ob);
171
172 /* Point Cloud */
173 void sync_pointcloud(PointCloud *pointcloud, BObjectInfo &b_ob_info);
174 void sync_pointcloud_motion(PointCloud *pointcloud,
175 BObjectInfo &b_ob_info,
176 const int motion_step = 0);
177
178 /* Camera */
179 void sync_camera_motion(BL::RenderSettings &b_render,
180 BL::Object &b_ob,
181 const int width,
182 const int height,
183 const float motion_time);
184
185 /* Geometry */
186 Geometry *sync_geometry(BObjectInfo &b_ob_info,
187 bool object_updated,
188 bool use_particle_hair,
190
191 void sync_geometry_motion(BObjectInfo &b_ob_info,
192 Object *object,
193 const float motion_time,
194 bool use_particle_hair,
196
197 /* Light */
198 void sync_light(BObjectInfo &b_ob_info, Light *light);
199 void sync_background_light(BL::SpaceView3D &b_v3d);
200
201 /* Particles */
202 bool sync_dupli_particle(BL::Object &b_ob,
203 BL::DepsgraphObjectInstance &b_instance,
204 Object *object);
205
206 /* Images. */
207 void sync_images();
208
209 /* util */
210 void find_shader(const BL::ID &id, array<Node *> &used_shaders, Shader *default_shader);
211 bool BKE_object_is_modified(BL::Object &b_ob);
212 bool object_is_geometry(BObjectInfo &b_ob_info);
213 bool object_can_have_geometry(BL::Object &b_ob);
214 bool object_is_light(BL::Object &b_ob);
215 bool object_is_camera(BL::Object &b_ob);
216 BL::Object get_dicing_camera_object(BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d);
217
218 /* variables */
219 BL::RenderEngine b_engine;
220 BL::BlendData b_data;
221 BL::Scene b_scene;
222 BL::Object b_bake_target;
223
224 enum ShaderFlags { SHADER_WITH_LAYER_ATTRS };
225
226 id_map<void *, Shader, ShaderFlags> shader_map;
227 id_map<ObjectKey, Object> object_map;
228 id_map<void *, Procedural> procedural_map;
229 id_map<GeometryKey, Geometry> geometry_map;
230 id_map<ParticleSystemKey, ParticleSystem> particle_system_map;
231 set<Geometry *> geometry_synced;
232 set<Geometry *> geometry_motion_synced;
233 set<Geometry *> geometry_motion_attribute_synced;
235 map<void *, set<BL::ID>> instance_geometries_by_object;
236 set<float> motion_times;
237 void *world_map;
238 bool world_recalc;
239 bool world_use_portal = false;
240 BlenderViewportParameters viewport_parameters;
241
242 Scene *scene;
243 bool preview;
244 bool use_experimental_procedural = false;
245 bool use_adaptive_subdivision = false;
246 bool use_developer_ui;
247
248 float dicing_rate;
249 int max_subdivisions;
250
251 struct RenderLayerInfo {
252 RenderLayerInfo() : material_override(PointerRNA_NULL), world_override(PointerRNA_NULL) {}
253
254 string name;
255 BL::Material material_override;
256 BL::World world_override;
257 bool use_background_shader = true;
258 bool use_surfaces = true;
259 bool use_hair = true;
260 bool use_volumes = true;
261 bool use_motion_blur = true;
262 int samples = 0;
263 bool bound_samples = false;
264 } view_layer;
265
266 Progress &progress;
267
268 /* Indicates that `sync_recalc()` detected changes in the scene.
269 * If this flag is false then the data is considered to be up-to-date and will not be
270 * synchronized at all. */
271 bool has_updates_ = true;
272};
273
int BKE_object_is_modified(Scene *scene, Object *ob)
struct Scene Scene
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:41
static DenoiseParams get_denoise_params(BL::Scene &b_scene, BL::ViewLayer &b_view_layer, bool background, const DeviceInfo &denoise_device)
Definition sync.cpp:1020
void sync_data(BL::RenderSettings &b_render, BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, BL::Object &b_override, const int width, const int height, void **python_thread_state, const DeviceInfo &denoise_device_info)
Definition sync.cpp:279
static bool get_session_pause(BL::Scene &b_scene, bool background)
Definition sync.cpp:918
void sync_camera(BL::RenderSettings &b_render, BL::Object &b_override, const int width, const int height, const char *viewname)
void tag_update()
Definition sync.cpp:85
static SessionParams get_session_params(BL::RenderEngine &b_engine, BL::Preferences &b_preferences, BL::Scene &b_scene, bool background)
Definition sync.cpp:924
void sync_recalc(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d)
Definition sync.cpp:97
int get_layer_bound_samples()
Definition sync.h:82
void sync_view_layer(BL::ViewLayer &b_view_layer)
Definition sync.cpp:605
void sync_integrator(BL::ViewLayer &b_view_layer, bool background, const DeviceInfo &denoise_device_info)
Definition sync.cpp:333
void free_data_after_sync(BL::Depsgraph &b_depsgraph)
Definition sync.cpp:827
void sync_view(BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, const int width, const int height)
static SceneParams get_scene_params(BL::Scene &b_scene, const bool background, const bool use_developer_ui)
Definition sync.cpp:863
int get_layer_samples()
Definition sync.h:78
void set_bake_target(BL::Object &b_object)
Definition sync.cpp:90
void sync_render_passes(BL::RenderLayer &b_rlay, BL::ViewLayer &b_view_layer)
Definition sync.cpp:746
static BufferParams get_buffer_params(BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, Camera *cam, const int width, const int height)
Definition film.h:29
Definition hair.h:13
#define CCL_NAMESPACE_END
TaskPool * task_pool
const PointerRNA PointerRNA_NULL