camera.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 __CAMERA_H__
  17. #define __CAMERA_H__
  18. #include "kernel/kernel_types.h"
  19. #include "graph/node.h"
  20. #include "util/util_array.h"
  21. #include "util/util_boundbox.h"
  22. #include "util/util_projection.h"
  23. #include "util/util_transform.h"
  24. #include "util/util_types.h"
  25. CCL_NAMESPACE_BEGIN
  26. class Device;
  27. class DeviceScene;
  28. class Scene;
  29. /* Camera
  30. *
  31. * The camera parameters are quite standard, tested to be both compatible with
  32. * Renderman, and Blender after remapping.
  33. */
  34. class Camera : public Node {
  35. public:
  36. NODE_DECLARE
  37. /* Specifies an offset for the shutter's time interval. */
  38. enum MotionPosition {
  39. /* Shutter opens at the current frame. */
  40. MOTION_POSITION_START = 0,
  41. /* Shutter is fully open at the current frame. */
  42. MOTION_POSITION_CENTER = 1,
  43. /* Shutter closes at the current frame. */
  44. MOTION_POSITION_END = 2,
  45. MOTION_NUM_POSITIONS,
  46. };
  47. /* Specifies rolling shutter effect. */
  48. enum RollingShutterType {
  49. /* No rolling shutter effect. */
  50. ROLLING_SHUTTER_NONE = 0,
  51. /* Sensor is being scanned vertically from top to bottom. */
  52. ROLLING_SHUTTER_TOP = 1,
  53. ROLLING_SHUTTER_NUM_TYPES,
  54. };
  55. /* Stereo Type */
  56. enum StereoEye {
  57. STEREO_NONE,
  58. STEREO_LEFT,
  59. STEREO_RIGHT,
  60. };
  61. /* motion blur */
  62. float shuttertime;
  63. MotionPosition motion_position;
  64. array<float> shutter_curve;
  65. size_t shutter_table_offset;
  66. /* ** Rolling shutter effect. ** */
  67. /* Defines rolling shutter effect type. */
  68. RollingShutterType rolling_shutter_type;
  69. /* Specifies exposure time of scanlines when using
  70. * rolling shutter effect.
  71. */
  72. float rolling_shutter_duration;
  73. /* depth of field */
  74. float focaldistance;
  75. float aperturesize;
  76. uint blades;
  77. float bladesrotation;
  78. /* type */
  79. CameraType type;
  80. float fov;
  81. /* panorama */
  82. PanoramaType panorama_type;
  83. float fisheye_fov;
  84. float fisheye_lens;
  85. float latitude_min;
  86. float latitude_max;
  87. float longitude_min;
  88. float longitude_max;
  89. /* panorama stereo */
  90. StereoEye stereo_eye;
  91. bool use_spherical_stereo;
  92. float interocular_distance;
  93. float convergence_distance;
  94. bool use_pole_merge;
  95. float pole_merge_angle_from;
  96. float pole_merge_angle_to;
  97. /* anamorphic lens bokeh */
  98. float aperture_ratio;
  99. /* sensor */
  100. float sensorwidth;
  101. float sensorheight;
  102. /* clipping */
  103. float nearclip;
  104. float farclip;
  105. /* screen */
  106. int width, height;
  107. int resolution;
  108. BoundBox2D viewplane;
  109. /* width and height change during preview, so we need these for calculating dice rates. */
  110. int full_width, full_height;
  111. /* controls how fast the dicing rate falls off for geometry out side of view */
  112. float offscreen_dicing_scale;
  113. /* border */
  114. BoundBox2D border;
  115. BoundBox2D viewport_camera_border;
  116. /* transformation */
  117. Transform matrix;
  118. /* motion */
  119. array<Transform> motion;
  120. bool use_perspective_motion;
  121. float fov_pre, fov_post;
  122. /* computed camera parameters */
  123. ProjectionTransform screentoworld;
  124. ProjectionTransform rastertoworld;
  125. ProjectionTransform ndctoworld;
  126. Transform cameratoworld;
  127. ProjectionTransform worldtoraster;
  128. ProjectionTransform worldtoscreen;
  129. ProjectionTransform worldtondc;
  130. Transform worldtocamera;
  131. ProjectionTransform rastertocamera;
  132. ProjectionTransform cameratoraster;
  133. ProjectionTransform full_rastertocamera;
  134. float3 dx;
  135. float3 dy;
  136. float3 full_dx;
  137. float3 full_dy;
  138. float3 frustum_right_normal;
  139. float3 frustum_top_normal;
  140. /* update */
  141. bool need_update;
  142. bool need_device_update;
  143. bool need_flags_update;
  144. int previous_need_motion;
  145. /* Kernel camera data, copied here for dicing. */
  146. KernelCamera kernel_camera;
  147. array<DecomposedTransform> kernel_camera_motion;
  148. /* functions */
  149. Camera();
  150. ~Camera();
  151. void compute_auto_viewplane();
  152. void update(Scene *scene);
  153. void device_update(Device *device, DeviceScene *dscene, Scene *scene);
  154. void device_update_volume(Device *device, DeviceScene *dscene, Scene *scene);
  155. void device_free(Device *device, DeviceScene *dscene, Scene *scene);
  156. bool modified(const Camera &cam);
  157. bool motion_modified(const Camera &cam);
  158. void tag_update();
  159. /* Public utility functions. */
  160. BoundBox viewplane_bounds_get();
  161. /* Calculates the width of a pixel at point in world space. */
  162. float world_to_raster_size(float3 P);
  163. /* Motion blur. */
  164. float motion_time(int step) const;
  165. int motion_step(float time) const;
  166. bool use_motion() const;
  167. private:
  168. /* Private utility functions. */
  169. float3 transform_raster_to_world(float raster_x, float raster_y);
  170. };
  171. CCL_NAMESPACE_END
  172. #endif /* __CAMERA_H__ */