Blender V5.0
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::RegionView3D &b_rv3d,
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 const int width,
71 const int height,
72 const char *viewname);
73 void sync_view(BL::SpaceView3D &b_v3d,
74 BL::RegionView3D &b_rv3d,
75 const int width,
76 const int height);
78 {
79 return view_layer.samples;
80 }
82 {
83 return view_layer.bound_samples;
84 }
85
86 /* Early data free. */
87 void free_data_after_sync(BL::Depsgraph &b_depsgraph);
88
89 /* get parameters */
90 static SceneParams get_scene_params(BL::Scene &b_scene,
91 const bool background,
92 const bool use_developer_ui);
93 static SessionParams get_session_params(BL::RenderEngine &b_engine,
94 BL::Preferences &b_preferences,
95 BL::Scene &b_scene,
96 bool background);
97 static bool get_session_pause(BL::Scene &b_scene, bool background);
98 static BufferParams get_buffer_params(BL::SpaceView3D &b_v3d,
99 BL::RegionView3D &b_rv3d,
100 Camera *cam,
101 const int width,
102 const int height);
103
104 static DenoiseParams get_denoise_params(BL::Scene &b_scene,
105 BL::ViewLayer &b_view_layer,
106 bool background,
107 const DeviceInfo &denoise_device);
108
109 private:
110 /* sync */
111 void sync_lights(BL::Depsgraph &b_depsgraph, bool update_all);
112 void sync_materials(BL::Depsgraph &b_depsgraph, bool update_all);
113 void sync_objects(BL::Depsgraph &b_depsgraph,
114 BL::SpaceView3D &b_v3d,
115 const float motion_time = 0.0f);
116 void sync_motion(BL::RenderSettings &b_render,
117 BL::Depsgraph &b_depsgraph,
118 BL::SpaceView3D &b_v3d,
119 BL::RegionView3D &b_rv3d,
120 const int width,
121 const int height,
122 void **python_thread_state);
123 void sync_film(BL::ViewLayer &b_view_layer, BL::SpaceView3D &b_v3d);
124 void sync_view();
125
126 /* Shader */
127 array<Node *> find_used_shaders(BL::Object &b_ob);
128 void sync_world(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, bool update_all);
129 void sync_shaders(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, bool update_all);
130 void sync_nodes(Shader *shader, BL::ShaderNodeTree &b_ntree);
131
132 bool scene_attr_needs_recalc(Shader *shader, BL::Depsgraph &b_depsgraph);
133 void resolve_view_layer_attributes(Shader *shader,
134 ShaderGraph *graph,
135 BL::Depsgraph &b_depsgraph);
136
137 /* Object */
138 Object *sync_object(BL::ViewLayer &b_view_layer,
139 BL::DepsgraphObjectInstance &b_instance,
140 const float motion_time,
141 bool use_particle_hair,
142 bool show_lights,
143 BlenderObjectCulling &culling,
144 TaskPool *geom_task_pool);
145 void sync_object_motion_init(BL::Object &b_parent, BL::Object &b_ob, Object *object);
146
147 void sync_procedural(BL::Object &b_ob,
148 BL::MeshSequenceCacheModifier &b_mesh_cache,
149 bool has_subdivision);
150
151 bool sync_object_attributes(BL::DepsgraphObjectInstance &b_instance, Object *object);
152
153 /* Volume */
154 void sync_volume(BObjectInfo &b_ob_info, Volume *volume);
155
156 /* Mesh */
157 void sync_mesh(BObjectInfo &b_ob_info, Mesh *mesh);
158 void sync_mesh_motion(BObjectInfo &b_ob_info, Mesh *mesh, int motion_step);
159
160 /* Hair */
161 void sync_hair(BObjectInfo &b_ob_info, Hair *hair);
162 void sync_hair_motion(BObjectInfo &b_ob_info, Hair *hair, int motion_step);
163 void sync_hair(Hair *hair, BObjectInfo &b_ob_info, bool motion, const int motion_step = 0);
164 void sync_particle_hair(Hair *hair,
165 BL::Mesh &b_mesh,
166 BObjectInfo &b_ob_info,
167 bool motion,
168 const int motion_step = 0);
169 bool object_has_particle_hair(BL::Object b_ob);
170
171 /* Point Cloud */
172 void sync_pointcloud(PointCloud *pointcloud, BObjectInfo &b_ob_info);
173 void sync_pointcloud_motion(PointCloud *pointcloud,
174 BObjectInfo &b_ob_info,
175 const int motion_step = 0);
176
177 /* Camera */
178 void sync_camera_motion(BL::RenderSettings &b_render,
179 BL::Object &b_ob,
180 const int width,
181 const int height,
182 const float motion_time);
183
184 /* Geometry */
185 Geometry *sync_geometry(BObjectInfo &b_ob_info,
186 bool object_updated,
187 bool use_particle_hair,
189
190 void sync_geometry_motion(BObjectInfo &b_ob_info,
191 Object *object,
192 const float motion_time,
193 bool use_particle_hair,
195
196 /* Light */
197 void sync_light(BObjectInfo &b_ob_info, Light *light);
198 void sync_background_light(BL::SpaceView3D &b_v3d);
199
200 /* Particles */
201 bool sync_dupli_particle(BL::Object &b_ob,
202 BL::DepsgraphObjectInstance &b_instance,
203 Object *object);
204
205 /* Images. */
206 void sync_images();
207
208 /* util */
209 void find_shader(const BL::ID &id, array<Node *> &used_shaders, Shader *default_shader);
210 bool BKE_object_is_modified(BL::Object &b_ob);
211 bool object_is_geometry(BObjectInfo &b_ob_info);
212 bool object_can_have_geometry(BL::Object &b_ob);
213 bool object_is_light(BL::Object &b_ob);
214 bool object_is_camera(BL::Object &b_ob);
215
216 BL::Object get_camera_object(BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d);
217 BL::Object get_dicing_camera_object(BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d);
218
219 /* variables */
220 BL::RenderEngine b_engine;
221 BL::BlendData b_data;
222 BL::Scene b_scene;
223 BL::Object b_bake_target;
224
225 enum ShaderFlags { SHADER_WITH_LAYER_ATTRS };
226
227 id_map<void *, Shader, ShaderFlags> shader_map;
228 id_map<ObjectKey, Object> object_map;
229 id_map<void *, Procedural> procedural_map;
230 id_map<GeometryKey, Geometry> geometry_map;
231 id_map<ParticleSystemKey, ParticleSystem> particle_system_map;
232 set<Geometry *> geometry_synced;
233 set<Geometry *> geometry_motion_synced;
234 set<Geometry *> geometry_motion_attribute_synced;
236 map<void *, set<BL::ID>> instance_geometries_by_object;
237 set<float> motion_times;
238 void *world_map;
239 bool world_recalc;
240 BlenderViewportParameters viewport_parameters;
241
242 Scene *scene;
243 bool preview;
244 bool use_adaptive_subdivision = false;
245 bool use_developer_ui;
246
247 CurveShapeType curve_shape = CURVE_RIBBON;
248
249 float dicing_rate;
250 int max_subdivisions;
251
252 struct RenderLayerInfo {
253 RenderLayerInfo() : material_override(PointerRNA_NULL), world_override(PointerRNA_NULL) {}
254
255 string name;
256 BL::Material material_override;
257 BL::World world_override;
258 bool use_background_shader = true;
259 bool use_surfaces = true;
260 bool use_hair = true;
261 bool use_volumes = true;
262 bool use_motion_blur = true;
263 int samples = 0;
264 bool bound_samples = false;
265 } view_layer;
266
267 Progress &progress;
268
269 /* Indicates that `sync_recalc()` detected changes in the scene.
270 * If this flag is false then the data is considered to be up-to-date and will not be
271 * synchronized at all. */
272 bool has_updates_ = true;
273};
274
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
static bool get_session_pause(BL::Scene &b_scene, bool background)
Definition sync.cpp:921
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:927
void sync_camera(BL::RenderSettings &b_render, const int width, const int height, const char *viewname)
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:81
void sync_view_layer(BL::ViewLayer &b_view_layer)
Definition sync.cpp:604
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:830
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:866
int get_layer_samples()
Definition sync.h:77
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:749
static BufferParams get_buffer_params(BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, Camera *cam, const int width, const int height)
void sync_data(BL::RenderSettings &b_render, BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, const int width, const int height, void **python_thread_state, const DeviceInfo &denoise_device_info)
Definition sync.cpp:279
Definition film.h:29
Definition hair.h:13
#define CCL_NAMESPACE_END
TaskPool * task_pool
CurveShapeType
@ CURVE_RIBBON
const PointerRNA PointerRNA_NULL