Welcome to mirror list, hosted at ThFree Co, Russian Federation.

scene.h « scene « cycles « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d1004bb7b66cb2bbc580caf521692fadc41a109d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
/* SPDX-License-Identifier: Apache-2.0
 * Copyright 2011-2022 Blender Foundation */

#ifndef __SCENE_H__
#define __SCENE_H__

#include "bvh/params.h"

#include "scene/film.h"
#include "scene/image.h"
#include "scene/shader.h"

#include "device/device.h"
#include "device/memory.h"

#include "util/param.h"
#include "util/string.h"
#include "util/system.h"
#include "util/texture.h"
#include "util/thread.h"
#include "util/types.h"
#include "util/vector.h"

CCL_NAMESPACE_BEGIN

class AlembicProcedural;
class AttributeRequestSet;
class Background;
class BVH;
class Camera;
class Device;
class DeviceInfo;
class Film;
class Integrator;
class Light;
class LightManager;
class LookupTables;
class Geometry;
class GeometryManager;
class Object;
class ObjectManager;
class ParticleSystemManager;
class ParticleSystem;
class PointCloud;
class Procedural;
class ProceduralManager;
class CurveSystemManager;
class Shader;
class ShaderManager;
class Progress;
class BakeManager;
class BakeData;
class RenderStats;
class SceneUpdateStats;
class Volume;

/* Scene Device Data */

class DeviceScene {
 public:
  /* BVH */
  device_vector<int4> bvh_nodes;
  device_vector<int4> bvh_leaf_nodes;
  device_vector<int> object_node;
  device_vector<int> prim_type;
  device_vector<uint> prim_visibility;
  device_vector<int> prim_index;
  device_vector<int> prim_object;
  device_vector<float2> prim_time;

  /* mesh */
  device_vector<packed_float3> tri_verts;
  device_vector<uint> tri_shader;
  device_vector<packed_float3> tri_vnormal;
  device_vector<uint4> tri_vindex;
  device_vector<uint> tri_patch;
  device_vector<float2> tri_patch_uv;

  device_vector<KernelCurve> curves;
  device_vector<float4> curve_keys;
  device_vector<KernelCurveSegment> curve_segments;

  device_vector<uint> patches;

  /* point-cloud */
  device_vector<float4> points;
  device_vector<uint> points_shader;

  /* objects */
  device_vector<KernelObject> objects;
  device_vector<Transform> object_motion_pass;
  device_vector<DecomposedTransform> object_motion;
  device_vector<uint> object_flag;
  device_vector<float> object_volume_step;
  device_vector<uint> object_prim_offset;

  /* cameras */
  device_vector<DecomposedTransform> camera_motion;

  /* attributes */
  device_vector<AttributeMap> attributes_map;
  device_vector<float> attributes_float;
  device_vector<float2> attributes_float2;
  device_vector<packed_float3> attributes_float3;
  device_vector<float4> attributes_float4;
  device_vector<uchar4> attributes_uchar4;

  /* lights */
  device_vector<KernelLightDistribution> light_distribution;
  device_vector<KernelLight> lights;
  device_vector<float2> light_background_marginal_cdf;
  device_vector<float2> light_background_conditional_cdf;

  /* particles */
  device_vector<KernelParticle> particles;

  /* shaders */
  device_vector<int4> svm_nodes;
  device_vector<KernelShader> shaders;

  /* lookup tables */
  device_vector<float> lookup_table;

  /* integrator */
  device_vector<float> sample_pattern_lut;

  /* IES lights */
  device_vector<float> ies_lights;

  KernelData data;

  DeviceScene(Device *device);
};

/* Scene Parameters */

class SceneParams {
 public:
  ShadingSystem shadingsystem;

  /* Requested BVH layout.
   *
   * If it's not supported by the device, the widest one from supported ones
   * will be used, but BVH wider than this one will never be used.
   */
  BVHLayout bvh_layout;

  BVHType bvh_type;
  bool use_bvh_spatial_split;
  bool use_bvh_compact_structure;
  bool use_bvh_unaligned_nodes;
  int num_bvh_time_steps;
  int hair_subdivisions;
  CurveShapeType hair_shape;
  int texture_limit;

  bool background;

  SceneParams()
  {
    shadingsystem = SHADINGSYSTEM_SVM;
    bvh_layout = BVH_LAYOUT_AUTO;
    bvh_type = BVH_TYPE_DYNAMIC;
    use_bvh_spatial_split = false;
    use_bvh_compact_structure = true;
    use_bvh_unaligned_nodes = true;
    num_bvh_time_steps = 0;
    hair_subdivisions = 3;
    hair_shape = CURVE_RIBBON;
    texture_limit = 0;
    background = true;
  }

  bool modified(const SceneParams &params) const
  {
    return !(shadingsystem == params.shadingsystem && bvh_layout == params.bvh_layout &&
             bvh_type == params.bvh_type &&
             use_bvh_spatial_split == params.use_bvh_spatial_split &&
             use_bvh_compact_structure == params.use_bvh_compact_structure &&
             use_bvh_unaligned_nodes == params.use_bvh_unaligned_nodes &&
             num_bvh_time_steps == params.num_bvh_time_steps &&
             hair_subdivisions == params.hair_subdivisions && hair_shape == params.hair_shape &&
             texture_limit == params.texture_limit);
  }

  int curve_subdivisions()
  {
    /* Matching the tessellation rate limit in Embree. */
    return clamp(1 << hair_subdivisions, 1, 16);
  }
};

/* Scene */

class Scene : public NodeOwner {
 public:
  /* Optional name. Is used for logging and reporting. */
  string name;

  /* Maps from Light group names to their pass ID. */
  map<ustring, int> lightgroups;

  /* data */
  BVH *bvh;
  Camera *camera;
  Camera *dicing_camera;
  LookupTables *lookup_tables;
  Film *film;
  Background *background;
  Integrator *integrator;

  /* data lists */
  vector<Object *> objects;
  vector<Geometry *> geometry;
  vector<Shader *> shaders;
  vector<Light *> lights;
  vector<ParticleSystem *> particle_systems;
  vector<Pass *> passes;
  vector<Procedural *> procedurals;

  /* data managers */
  ImageManager *image_manager;
  LightManager *light_manager;
  ShaderManager *shader_manager;
  GeometryManager *geometry_manager;
  ObjectManager *object_manager;
  ParticleSystemManager *particle_system_manager;
  BakeManager *bake_manager;
  ProceduralManager *procedural_manager;

  /* default shaders */
  Shader *default_surface;
  Shader *default_volume;
  Shader *default_light;
  Shader *default_background;
  Shader *default_empty;

  /* device */
  Device *device;
  DeviceScene dscene;

  /* parameters */
  SceneParams params;

  /* mutex must be locked manually by callers */
  thread_mutex mutex;

  /* scene update statistics */
  SceneUpdateStats *update_stats;

  Scene(const SceneParams &params, Device *device);
  ~Scene();

  void device_update(Device *device, Progress &progress);

  bool need_global_attribute(AttributeStandard std);
  void need_global_attributes(AttributeRequestSet &attributes);

  enum MotionType { MOTION_NONE = 0, MOTION_PASS, MOTION_BLUR };
  MotionType need_motion() const;
  float motion_shutter_time();

  bool need_update();
  bool need_reset();

  void reset();
  void device_free();

  void collect_statistics(RenderStats *stats);

  void enable_update_stats();

  bool update(Progress &progress);

  bool has_shadow_catcher();
  void tag_shadow_catcher_modified();

  /* This function is used to create a node of a specified type instead of
   * calling 'new', and sets the scene as the owner of the node.
   * The function has overloads that will also add the created node to the right
   * node array (e.g. Scene::geometry for Geometry nodes) and tag the appropriate
   * manager for an update.
   */
  template<typename T, typename... Args> T *create_node(Args &&...args)
  {
    T *node = new T(args...);
    node->set_owner(this);
    return node;
  }

  /* This function is used to delete a node from the scene instead of calling 'delete'
   * and manually removing the node from the data array. It also tags the
   * appropriate manager for an update, if any, and checks that the scene is indeed
   * the owner of the node. Calling this function on a node not owned by the scene
   * will likely cause a crash which we want in order to detect such cases.
   */
  template<typename T> void delete_node(T *node)
  {
    assert(node->get_owner() == this);
    delete_node_impl(node);
  }

  /* Same as above, but specify the actual owner.
   */
  template<typename T> void delete_node(T *node, const NodeOwner *owner)
  {
    assert(node->get_owner() == owner);
    delete_node_impl(node);
    (void)owner;
  }

  /* Remove all nodes in the set from the appropriate data arrays, and tag the
   * specific managers for an update. This assumes that the scene owns the nodes.
   */
  template<typename T> void delete_nodes(const set<T *> &nodes)
  {
    delete_nodes(nodes, this);
  }

  /* Same as above, but specify the actual owner of all the nodes in the set.
   */
  template<typename T> void delete_nodes(const set<T *> &nodes, const NodeOwner *owner);

 protected:
  /* Check if some heavy data worth logging was updated.
   * Mainly used to suppress extra annoying logging.
   */
  bool need_data_update();

  void free_memory(bool final);

  bool kernels_loaded;
  uint loaded_kernel_features;

  void update_kernel_features();
  bool load_kernels(Progress &progress, bool lock_scene = true);

  bool has_shadow_catcher_ = false;
  bool shadow_catcher_modified_ = true;

  /* Maximum number of closure during session lifetime. */
  int max_closure_global;

  /* Get maximum number of closures to be used in kernel. */
  int get_max_closure_count();

  /* Get size of a volume stack needed to render this scene.  */
  int get_volume_stack_size() const;

  template<typename T> void delete_node_impl(T *node)
  {
    delete node;
  }
};

template<> Light *Scene::create_node<Light>();

template<> Mesh *Scene::create_node<Mesh>();

template<> Object *Scene::create_node<Object>();

template<> Hair *Scene::create_node<Hair>();

template<> Volume *Scene::create_node<Volume>();

template<> PointCloud *Scene::create_node<PointCloud>();

template<> ParticleSystem *Scene::create_node<ParticleSystem>();

template<> Shader *Scene::create_node<Shader>();

template<> AlembicProcedural *Scene::create_node<AlembicProcedural>();

template<> Pass *Scene::create_node<Pass>();

template<> void Scene::delete_node_impl(Light *node);

template<> void Scene::delete_node_impl(Mesh *node);

template<> void Scene::delete_node_impl(Volume *node);

template<> void Scene::delete_node_impl(PointCloud *node);

template<> void Scene::delete_node_impl(Hair *node);

template<> void Scene::delete_node_impl(Geometry *node);

template<> void Scene::delete_node_impl(Object *node);

template<> void Scene::delete_node_impl(ParticleSystem *node);

template<> void Scene::delete_node_impl(Shader *node);

template<> void Scene::delete_node_impl(Procedural *node);

template<> void Scene::delete_node_impl(AlembicProcedural *node);

template<> void Scene::delete_node_impl(Pass *node);

template<> void Scene::delete_nodes(const set<Light *> &nodes, const NodeOwner *owner);

template<> void Scene::delete_nodes(const set<Geometry *> &nodes, const NodeOwner *owner);

template<> void Scene::delete_nodes(const set<Object *> &nodes, const NodeOwner *owner);

template<> void Scene::delete_nodes(const set<ParticleSystem *> &nodes, const NodeOwner *owner);

template<> void Scene::delete_nodes(const set<Shader *> &nodes, const NodeOwner *owner);

template<> void Scene::delete_nodes(const set<Procedural *> &nodes, const NodeOwner *owner);

template<> void Scene::delete_nodes(const set<Pass *> &nodes, const NodeOwner *owner);

CCL_NAMESPACE_END

#endif /*  __SCENE_H__ */