Blender  V2.93
blender_sync.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __BLENDER_SYNC_H__
18 #define __BLENDER_SYNC_H__
19 
20 #include "MEM_guardedalloc.h"
21 #include "RNA_access.h"
22 #include "RNA_blender_cpp.h"
23 #include "RNA_types.h"
24 
25 #include "blender/blender_id_map.h"
27 
28 #include "render/scene.h"
29 #include "render/session.h"
30 
31 #include "util/util_map.h"
32 #include "util/util_set.h"
33 #include "util/util_transform.h"
34 #include "util/util_vector.h"
35 
37 
38 class Background;
41 class Camera;
42 class Film;
43 class Hair;
44 class Light;
45 class Mesh;
46 class Object;
47 class ParticleSystem;
48 class Scene;
49 class ViewLayer;
50 class Shader;
51 class ShaderGraph;
52 class ShaderNode;
53 class TaskPool;
54 
55 class BlenderSync {
56  public:
57  BlenderSync(BL::RenderEngine &b_engine,
58  BL::BlendData &b_data,
59  BL::Scene &b_scene,
60  Scene *scene,
61  bool preview,
62  Progress &progress);
63  ~BlenderSync();
64 
65  void reset(BL::BlendData &b_data, BL::Scene &b_scene);
66 
67  void tag_update();
68 
69  /* sync */
70  void sync_recalc(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d);
71  void sync_data(BL::RenderSettings &b_render,
72  BL::Depsgraph &b_depsgraph,
73  BL::SpaceView3D &b_v3d,
74  BL::Object &b_override,
75  int width,
76  int height,
77  void **python_thread_state);
78  void sync_view_layer(BL::SpaceView3D &b_v3d, BL::ViewLayer &b_view_layer);
80  BL::RenderLayer &b_render_layer,
81  BL::ViewLayer &b_view_layer,
82  bool adaptive_sampling,
83  const DenoiseParams &denoising);
84  void sync_integrator();
85  void sync_camera(BL::RenderSettings &b_render,
86  BL::Object &b_override,
87  int width,
88  int height,
89  const char *viewname);
90  void sync_view(BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, int width, int height);
91  inline int get_layer_samples()
92  {
93  return view_layer.samples;
94  }
96  {
97  return view_layer.bound_samples;
98  }
99 
100  /* get parameters */
101  static SceneParams get_scene_params(BL::Scene &b_scene, bool background);
103  BL::RenderEngine &b_engine,
104  BL::Preferences &b_userpref,
105  BL::Scene &b_scene,
106  bool background,
108  static bool get_session_pause(BL::Scene &b_scene, bool background);
109  static BufferParams get_buffer_params(BL::RenderSettings &b_render,
110  BL::SpaceView3D &b_v3d,
111  BL::RegionView3D &b_rv3d,
112  Camera *cam,
113  int width,
114  int height,
115  const bool use_denoiser);
116 
117  static PassType get_pass_type(BL::RenderPass &b_pass);
118  static int get_denoising_pass(BL::RenderPass &b_pass);
119 
120  private:
121  static DenoiseParams get_denoise_params(BL::Scene &b_scene,
122  BL::ViewLayer &b_view_layer,
123  bool background);
124 
125  /* sync */
126  void sync_lights(BL::Depsgraph &b_depsgraph, bool update_all);
127  void sync_materials(BL::Depsgraph &b_depsgraph, bool update_all);
128  void sync_objects(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, float motion_time = 0.0f);
129  void sync_motion(BL::RenderSettings &b_render,
130  BL::Depsgraph &b_depsgraph,
131  BL::SpaceView3D &b_v3d,
132  BL::Object &b_override,
133  int width,
134  int height,
135  void **python_thread_state);
136  void sync_film(BL::SpaceView3D &b_v3d);
137  void sync_view();
138 
139  /* Shader */
140  array<Node *> find_used_shaders(BL::Object &b_ob);
141  void sync_world(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, bool update_all);
142  void sync_shaders(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d);
143  void sync_nodes(Shader *shader, BL::ShaderNodeTree &b_ntree);
144 
145  /* Object */
146  Object *sync_object(BL::Depsgraph &b_depsgraph,
147  BL::ViewLayer &b_view_layer,
148  BL::DepsgraphObjectInstance &b_instance,
149  float motion_time,
150  bool use_particle_hair,
151  bool show_lights,
152  BlenderObjectCulling &culling,
153  bool *use_portal,
154  TaskPool *geom_task_pool);
155  void sync_object_motion_init(BL::Object &b_parent, BL::Object &b_ob, Object *object);
156 
157  bool sync_object_attributes(BL::DepsgraphObjectInstance &b_instance, Object *object);
158 
159  /* Volume */
160  void sync_volume(BL::Object &b_ob, Volume *volume);
161 
162  /* Mesh */
163  void sync_mesh(BL::Depsgraph b_depsgraph, BL::Object b_ob, Mesh *mesh);
164  void sync_mesh_motion(BL::Depsgraph b_depsgraph, BL::Object b_ob, Mesh *mesh, int motion_step);
165 
166  /* Hair */
167  void sync_hair(BL::Depsgraph b_depsgraph, BL::Object b_ob, Hair *hair);
168  void sync_hair_motion(BL::Depsgraph b_depsgraph, BL::Object b_ob, Hair *hair, int motion_step);
169  void sync_hair(Hair *hair, BL::Object &b_ob, bool motion, int motion_step = 0);
170  void sync_particle_hair(
171  Hair *hair, BL::Mesh &b_mesh, BL::Object &b_ob, bool motion, int motion_step = 0);
172  bool object_has_particle_hair(BL::Object b_ob);
173 
174  /* Camera */
175  void sync_camera_motion(
176  BL::RenderSettings &b_render, BL::Object &b_ob, int width, int height, float motion_time);
177 
178  /* Geometry */
179  Geometry *sync_geometry(BL::Depsgraph &b_depsgrpah,
180  BL::Object &b_ob,
181  BL::Object &b_ob_instance,
182  bool object_updated,
183  bool use_particle_hair,
185 
186  void sync_geometry_motion(BL::Depsgraph &b_depsgraph,
187  BL::Object &b_ob,
188  Object *object,
189  float motion_time,
190  bool use_particle_hair,
192 
193  /* Light */
194  void sync_light(BL::Object &b_parent,
195  int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
196  BL::Object &b_ob,
197  BL::Object &b_ob_instance,
198  int random_id,
199  Transform &tfm,
200  bool *use_portal);
201  void sync_background_light(BL::SpaceView3D &b_v3d, bool use_portal);
202 
203  /* Particles */
204  bool sync_dupli_particle(BL::Object &b_ob,
205  BL::DepsgraphObjectInstance &b_instance,
206  Object *object);
207 
208  /* Images. */
209  void sync_images();
210 
211  /* Early data free. */
212  void free_data_after_sync(BL::Depsgraph &b_depsgraph);
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(BL::Object &b_ob);
218  bool object_is_light(BL::Object &b_ob);
219 
220  /* variables */
221  BL::RenderEngine b_engine;
222  BL::BlendData b_data;
223  BL::Scene b_scene;
224 
225  id_map<void *, Shader> shader_map;
226  id_map<ObjectKey, Object> object_map;
227  id_map<GeometryKey, Geometry> geometry_map;
228  id_map<ObjectKey, Light> light_map;
229  id_map<ParticleSystemKey, ParticleSystem> particle_system_map;
230  set<Geometry *> geometry_synced;
231  set<Geometry *> geometry_motion_synced;
232  set<float> motion_times;
233  void *world_map;
234  bool world_recalc;
235  BlenderViewportParameters viewport_parameters;
236 
237  Scene *scene;
238  bool preview;
239  bool experimental;
240 
241  float dicing_rate;
242  int max_subdivisions;
243 
244  struct RenderLayerInfo {
245  RenderLayerInfo()
246  : material_override(PointerRNA_NULL),
247  use_background_shader(true),
248  use_background_ao(true),
249  use_surfaces(true),
250  use_hair(true),
251  use_volumes(true),
252  samples(0),
253  bound_samples(false)
254  {
255  }
256 
257  string name;
258  BL::Material material_override;
259  bool use_background_shader;
260  bool use_background_ao;
261  bool use_surfaces;
262  bool use_hair;
263  bool use_volumes;
264  int samples;
265  bool bound_samples;
266  } view_layer;
267 
268  Progress &progress;
269 
270  /* Indicates that `sync_recalc()` detected changes in the scene.
271  * If this flag is false then the data is considered to be up-to-date and will not be
272  * synchronized at all. */
273  bool has_updates_ = true;
274 };
275 
277 
278 #endif /* __BLENDER_SYNC_H__ */
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
struct ID ID
struct ViewLayer ViewLayer
struct Material Material
struct Mesh Mesh
struct Object Object
struct Scene Scene
struct RegionView3D RegionView3D
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
Read Guarded memory(de)allocation.
struct RenderEngine RenderEngine
struct RenderLayer RenderLayer
struct RenderPass RenderPass
@ OBJECT_PERSISTENT_ID_SIZE
static BufferParams get_buffer_params(BL::RenderSettings &b_render, BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, Camera *cam, int width, int height, const bool use_denoiser)
static bool get_session_pause(BL::Scene &b_scene, bool background)
static SessionParams get_session_params(BL::RenderEngine &b_engine, BL::Preferences &b_userpref, BL::Scene &b_scene, bool background, BL::ViewLayer b_view_layer=BL::ViewLayer(PointerRNA_NULL))
void sync_recalc(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d)
void tag_update()
BlenderSync(BL::RenderEngine &b_engine, BL::BlendData &b_data, BL::Scene &b_scene, Scene *scene, bool preview, Progress &progress)
static SceneParams get_scene_params(BL::Scene &b_scene, bool background)
void sync_camera(BL::RenderSettings &b_render, BL::Object &b_override, int width, int height, const char *viewname)
int get_layer_bound_samples()
Definition: blender_sync.h:95
vector< Pass > sync_render_passes(BL::Scene &b_scene, BL::RenderLayer &b_render_layer, BL::ViewLayer &b_view_layer, bool adaptive_sampling, const DenoiseParams &denoising)
void sync_view(BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, int width, int height)
static int get_denoising_pass(BL::RenderPass &b_pass)
static PassType get_pass_type(BL::RenderPass &b_pass)
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)
void reset(BL::BlendData &b_data, BL::Scene &b_scene)
int get_layer_samples()
Definition: blender_sync.h:91
void sync_view_layer(BL::SpaceView3D &b_v3d, BL::ViewLayer &b_view_layer)
void sync_integrator()
Definition: film.h:59
Definition: shader.h:80
Scene scene
TaskPool * task_pool
#define CCL_NAMESPACE_END
void KERNEL_FUNCTION_FULL_NAME() shader(KernelGlobals *kg, uint4 *input, float4 *output, int type, int filter, int i, int offset, int sample)
PassType
Definition: kernel_types.h:347
const PointerRNA PointerRNA_NULL
Definition: rna_access.c:71