Cycles: Added Cryptomatte output.
[blender.git] / intern / cycles / blender / blender_sync.h
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_types.h"
22 #include "RNA_access.h"
23 #include "RNA_blender_cpp.h"
24
25 #include "blender/blender_util.h"
26
27 #include "render/scene.h"
28 #include "render/session.h"
29
30 #include "util/util_map.h"
31 #include "util/util_set.h"
32 #include "util/util_transform.h"
33 #include "util/util_vector.h"
34
35 CCL_NAMESPACE_BEGIN
36
37 class Background;
38 class BlenderObjectCulling;
39 class Camera;
40 class Film;
41 class Light;
42 class Mesh;
43 class Object;
44 class ParticleSystem;
45 class Scene;
46 class Shader;
47 class ShaderGraph;
48 class ShaderNode;
49
50 class BlenderSync {
51 public:
52         BlenderSync(BL::RenderEngine& b_engine,
53                     BL::BlendData& b_data,
54                     BL::Scene& b_scene,
55                     Scene *scene,
56                     bool preview,
57                     Progress &progress);
58         ~BlenderSync();
59
60         /* sync */
61         bool sync_recalc();
62         void sync_data(BL::RenderSettings& b_render,
63                        BL::SpaceView3D& b_v3d,
64                        BL::Object& b_override,
65                        int width, int height,
66                        void **python_thread_state,
67                        const char *layer = 0);
68         void sync_render_layers(BL::SpaceView3D& b_v3d, const char *layer);
69         vector<Pass> sync_render_passes(BL::RenderLayer& b_rlay,
70                                         BL::SceneRenderLayer& b_srlay,
71                                         const SessionParams &session_params);
72         void sync_integrator();
73         void sync_camera(BL::RenderSettings& b_render,
74                          BL::Object& b_override,
75                          int width, int height,
76                          const char *viewname);
77         void sync_view(BL::SpaceView3D& b_v3d,
78                        BL::RegionView3D& b_rv3d,
79                        int width, int height);
80         inline int get_layer_samples() { return render_layer.samples; }
81         inline int get_layer_bound_samples() { return render_layer.bound_samples; }
82
83         /* get parameters */
84         static SceneParams get_scene_params(BL::Scene& b_scene,
85                                             bool background);
86         static SessionParams get_session_params(BL::RenderEngine& b_engine,
87                                                 BL::UserPreferences& b_userpref,
88                                                 BL::Scene& b_scene,
89                                                 bool background);
90         static bool get_session_pause(BL::Scene& b_scene, bool background);
91         static BufferParams get_buffer_params(BL::RenderSettings& b_render,
92                                               BL::SpaceView3D& b_v3d,
93                                               BL::RegionView3D& b_rv3d,
94                                               Camera *cam,
95                                               int width, int height);
96
97         static PassType get_pass_type(BL::RenderPass& b_pass);
98         static int get_denoising_pass(BL::RenderPass& b_pass);
99
100 private:
101         /* sync */
102         void sync_lamps(bool update_all);
103         void sync_materials(bool update_all);
104         void sync_objects(float motion_time = 0.0f);
105         void sync_motion(BL::RenderSettings& b_render,
106                          BL::Object& b_override,
107                          int width, int height,
108                          void **python_thread_state);
109         void sync_film();
110         void sync_view();
111         void sync_world(bool update_all);
112         void sync_shaders();
113         void sync_curve_settings();
114
115         void sync_nodes(Shader *shader, BL::ShaderNodeTree& b_ntree);
116         Mesh *sync_mesh(BL::Object& b_ob, bool object_updated, bool hide_tris);
117         void sync_curves(Mesh *mesh,
118                          BL::Mesh& b_mesh,
119                          BL::Object& b_ob,
120                          bool motion,
121                          int motion_step = 0);
122         Object *sync_object(BL::Object& b_parent,
123                             int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
124                             BL::DupliObject& b_dupli_ob,
125                             Transform& tfm,
126                             uint layer_flag,
127                             float motion_time,
128                             bool hide_tris,
129                             BlenderObjectCulling& culling,
130                             bool *use_portal);
131         void sync_light(BL::Object& b_parent,
132                         int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
133                         BL::Object& b_ob,
134                         BL::DupliObject& b_dupli_ob,
135                         Transform& tfm,
136                         bool *use_portal);
137         void sync_background_light(bool use_portal);
138         void sync_mesh_motion(BL::Object& b_ob,
139                               Object *object,
140                               float motion_time);
141         void sync_camera_motion(BL::RenderSettings& b_render,
142                                 BL::Object& b_ob,
143                                 int width, int height,
144                                 float motion_time);
145
146         /* particles */
147         bool sync_dupli_particle(BL::Object& b_ob,
148                                  BL::DupliObject& b_dup,
149                                  Object *object);
150
151         /* Images. */
152         void sync_images();
153
154         /* util */
155         void find_shader(BL::ID& id, vector<Shader*>& used_shaders, Shader *default_shader);
156         bool BKE_object_is_modified(BL::Object& b_ob);
157         bool object_is_mesh(BL::Object& b_ob);
158         bool object_is_light(BL::Object& b_ob);
159
160         /* variables */
161         BL::RenderEngine b_engine;
162         BL::BlendData b_data;
163         BL::Scene b_scene;
164
165         id_map<void*, Shader> shader_map;
166         id_map<ObjectKey, Object> object_map;
167         id_map<void*, Mesh> mesh_map;
168         id_map<ObjectKey, Light> light_map;
169         id_map<ParticleSystemKey, ParticleSystem> particle_system_map;
170         set<Mesh*> mesh_synced;
171         set<Mesh*> mesh_motion_synced;
172         set<float> motion_times;
173         void *world_map;
174         bool world_recalc;
175
176         Scene *scene;
177         bool preview;
178         bool experimental;
179
180         float dicing_rate;
181         int max_subdivisions;
182
183         struct RenderLayerInfo {
184                 RenderLayerInfo()
185                 : scene_layer(0), layer(0),
186                   holdout_layer(0), exclude_layer(0),
187                   material_override(PointerRNA_NULL),
188                   use_background_shader(true),
189                   use_background_ao(true),
190                   use_surfaces(true),
191                   use_hair(true),
192                   use_viewport_visibility(false),
193                   samples(0), bound_samples(false)
194                 {}
195
196                 string name;
197                 uint scene_layer;
198                 uint layer;
199                 uint holdout_layer;
200                 uint exclude_layer;
201                 BL::Material material_override;
202                 bool use_background_shader;
203                 bool use_background_ao;
204                 bool use_surfaces;
205                 bool use_hair;
206                 bool use_viewport_visibility;
207                 int samples;
208                 bool bound_samples;
209         } render_layer;
210
211         Progress &progress;
212 };
213
214 CCL_NAMESPACE_END
215
216 #endif /* __BLENDER_SYNC_H__ */