scene.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. #ifndef __SCENE_H__
  17. #define __SCENE_H__
  18. #include "bvh/bvh_params.h"
  19. #include "render/image.h"
  20. #include "render/shader.h"
  21. #include "device/device_memory.h"
  22. #include "util/util_param.h"
  23. #include "util/util_string.h"
  24. #include "util/util_system.h"
  25. #include "util/util_texture.h"
  26. #include "util/util_thread.h"
  27. #include "util/util_types.h"
  28. #include "util/util_vector.h"
  29. CCL_NAMESPACE_BEGIN
  30. class AttributeRequestSet;
  31. class Background;
  32. class Camera;
  33. class Device;
  34. class DeviceInfo;
  35. class Film;
  36. class Integrator;
  37. class Light;
  38. class LightManager;
  39. class LookupTables;
  40. class Mesh;
  41. class MeshManager;
  42. class Object;
  43. class ObjectManager;
  44. class ParticleSystemManager;
  45. class ParticleSystem;
  46. class CurveSystemManager;
  47. class Shader;
  48. class ShaderManager;
  49. class Progress;
  50. class BakeManager;
  51. class BakeData;
  52. class RenderStats;
  53. /* Scene Device Data */
  54. class DeviceScene {
  55. public:
  56. /* BVH */
  57. device_vector<int4> bvh_nodes;
  58. device_vector<int4> bvh_leaf_nodes;
  59. device_vector<int> object_node;
  60. device_vector<uint> prim_tri_index;
  61. device_vector<float4> prim_tri_verts;
  62. device_vector<int> prim_type;
  63. device_vector<uint> prim_visibility;
  64. device_vector<int> prim_index;
  65. device_vector<int> prim_object;
  66. device_vector<float2> prim_time;
  67. /* mesh */
  68. device_vector<uint> tri_shader;
  69. device_vector<float4> tri_vnormal;
  70. device_vector<uint4> tri_vindex;
  71. device_vector<uint> tri_patch;
  72. device_vector<float2> tri_patch_uv;
  73. device_vector<float4> curves;
  74. device_vector<float4> curve_keys;
  75. device_vector<uint> patches;
  76. /* objects */
  77. device_vector<KernelObject> objects;
  78. device_vector<Transform> object_motion_pass;
  79. device_vector<DecomposedTransform> object_motion;
  80. device_vector<uint> object_flag;
  81. /* cameras */
  82. device_vector<DecomposedTransform> camera_motion;
  83. /* attributes */
  84. device_vector<uint4> attributes_map;
  85. device_vector<float> attributes_float;
  86. device_vector<float2> attributes_float2;
  87. device_vector<float4> attributes_float3;
  88. device_vector<uchar4> attributes_uchar4;
  89. /* lights */
  90. device_vector<KernelLightDistribution> light_distribution;
  91. device_vector<KernelLight> lights;
  92. device_vector<float2> light_background_marginal_cdf;
  93. device_vector<float2> light_background_conditional_cdf;
  94. /* particles */
  95. device_vector<KernelParticle> particles;
  96. /* shaders */
  97. device_vector<int4> svm_nodes;
  98. device_vector<KernelShader> shaders;
  99. /* lookup tables */
  100. device_vector<float> lookup_table;
  101. /* integrator */
  102. device_vector<uint> sobol_directions;
  103. /* ies lights */
  104. device_vector<float> ies_lights;
  105. KernelData data;
  106. DeviceScene(Device *device);
  107. };
  108. /* Scene Parameters */
  109. class SceneParams {
  110. public:
  111. /* Type of BVH, in terms whether it is supported dynamic updates of meshes
  112. * or whether modifying geometry requires full BVH rebuild.
  113. */
  114. enum BVHType {
  115. /* BVH supports dynamic updates of geometry.
  116. *
  117. * Faster for updating BVH tree when doing modifications in viewport,
  118. * but slower for rendering.
  119. */
  120. BVH_DYNAMIC = 0,
  121. /* BVH tree is calculated for specific scene, updates in geometry
  122. * requires full tree rebuild.
  123. *
  124. * Slower to update BVH tree when modifying objects in viewport, also
  125. * slower to build final BVH tree but gives best possible render speed.
  126. */
  127. BVH_STATIC = 1,
  128. BVH_NUM_TYPES,
  129. };
  130. ShadingSystem shadingsystem;
  131. /* Requested BVH layout.
  132. *
  133. * If it's not supported by the device, the widest one from supported ones
  134. * will be used, but BVH wider than this one will never be used.
  135. */
  136. BVHLayout bvh_layout;
  137. BVHType bvh_type;
  138. bool use_bvh_spatial_split;
  139. bool use_bvh_unaligned_nodes;
  140. int num_bvh_time_steps;
  141. bool persistent_data;
  142. int texture_limit;
  143. SceneParams()
  144. {
  145. shadingsystem = SHADINGSYSTEM_SVM;
  146. bvh_layout = BVH_LAYOUT_BVH2;
  147. bvh_type = BVH_DYNAMIC;
  148. use_bvh_spatial_split = false;
  149. use_bvh_unaligned_nodes = true;
  150. num_bvh_time_steps = 0;
  151. persistent_data = false;
  152. texture_limit = 0;
  153. }
  154. bool modified(const SceneParams &params)
  155. {
  156. return !(shadingsystem == params.shadingsystem && bvh_layout == params.bvh_layout &&
  157. bvh_type == params.bvh_type &&
  158. use_bvh_spatial_split == params.use_bvh_spatial_split &&
  159. use_bvh_unaligned_nodes == params.use_bvh_unaligned_nodes &&
  160. num_bvh_time_steps == params.num_bvh_time_steps &&
  161. persistent_data == params.persistent_data && texture_limit == params.texture_limit);
  162. }
  163. };
  164. /* Scene */
  165. class Scene {
  166. public:
  167. /* Optional name. Is used for logging and reporting. */
  168. string name;
  169. /* data */
  170. Camera *camera;
  171. Camera *dicing_camera;
  172. LookupTables *lookup_tables;
  173. Film *film;
  174. Background *background;
  175. Integrator *integrator;
  176. /* data lists */
  177. vector<Object *> objects;
  178. vector<Mesh *> meshes;
  179. vector<Shader *> shaders;
  180. vector<Light *> lights;
  181. vector<ParticleSystem *> particle_systems;
  182. /* data managers */
  183. ImageManager *image_manager;
  184. LightManager *light_manager;
  185. ShaderManager *shader_manager;
  186. MeshManager *mesh_manager;
  187. ObjectManager *object_manager;
  188. ParticleSystemManager *particle_system_manager;
  189. CurveSystemManager *curve_system_manager;
  190. BakeManager *bake_manager;
  191. /* default shaders */
  192. Shader *default_surface;
  193. Shader *default_light;
  194. Shader *default_background;
  195. Shader *default_empty;
  196. /* device */
  197. Device *device;
  198. DeviceScene dscene;
  199. /* parameters */
  200. SceneParams params;
  201. /* mutex must be locked manually by callers */
  202. thread_mutex mutex;
  203. Scene(const SceneParams &params, Device *device);
  204. ~Scene();
  205. void device_update(Device *device, Progress &progress);
  206. bool need_global_attribute(AttributeStandard std);
  207. void need_global_attributes(AttributeRequestSet &attributes);
  208. enum MotionType { MOTION_NONE = 0, MOTION_PASS, MOTION_BLUR };
  209. MotionType need_motion();
  210. float motion_shutter_time();
  211. bool need_update();
  212. bool need_reset();
  213. void reset();
  214. void device_free();
  215. void collect_statistics(RenderStats *stats);
  216. protected:
  217. /* Check if some heavy data worth logging was updated.
  218. * Mainly used to suppress extra annoying logging.
  219. */
  220. bool need_data_update();
  221. void free_memory(bool final);
  222. };
  223. CCL_NAMESPACE_END
  224. #endif /* __SCENE_H__ */