camera_attributes.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /**************************************************************************/
  2. /* camera_attributes.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef CAMERA_ATTRIBUTES_H
  31. #define CAMERA_ATTRIBUTES_H
  32. #include "core/io/resource.h"
  33. #include "core/templates/rid.h"
  34. class CameraAttributes : public Resource {
  35. GDCLASS(CameraAttributes, Resource);
  36. private:
  37. RID camera_attributes;
  38. protected:
  39. static void _bind_methods();
  40. void _validate_property(PropertyInfo &p_property) const;
  41. float exposure_multiplier = 1.0;
  42. float exposure_sensitivity = 100.0; // In ISO.
  43. void _update_exposure();
  44. bool auto_exposure_enabled = false;
  45. float auto_exposure_min = 0.01;
  46. float auto_exposure_max = 64.0;
  47. float auto_exposure_speed = 0.5;
  48. float auto_exposure_scale = 0.4;
  49. virtual void _update_auto_exposure() {}
  50. public:
  51. virtual RID get_rid() const override;
  52. virtual float calculate_exposure_normalization() const { return 1.0; }
  53. void set_exposure_multiplier(float p_multiplier);
  54. float get_exposure_multiplier() const;
  55. void set_exposure_sensitivity(float p_sensitivity);
  56. float get_exposure_sensitivity() const;
  57. void set_auto_exposure_enabled(bool p_enabled);
  58. bool is_auto_exposure_enabled() const;
  59. void set_auto_exposure_speed(float p_auto_exposure_speed);
  60. float get_auto_exposure_speed() const;
  61. void set_auto_exposure_scale(float p_auto_exposure_scale);
  62. float get_auto_exposure_scale() const;
  63. CameraAttributes();
  64. ~CameraAttributes();
  65. };
  66. class CameraAttributesPractical : public CameraAttributes {
  67. GDCLASS(CameraAttributesPractical, CameraAttributes);
  68. private:
  69. // DOF blur
  70. bool dof_blur_far_enabled = false;
  71. float dof_blur_far_distance = 10.0;
  72. float dof_blur_far_transition = 5.0;
  73. bool dof_blur_near_enabled = false;
  74. float dof_blur_near_distance = 2.0;
  75. float dof_blur_near_transition = 1.0;
  76. float dof_blur_amount = 0.1;
  77. void _update_dof_blur();
  78. virtual void _update_auto_exposure() override;
  79. protected:
  80. static void _bind_methods();
  81. void _validate_property(PropertyInfo &p_property) const;
  82. public:
  83. // DOF blur
  84. void set_dof_blur_far_enabled(bool p_enabled);
  85. bool is_dof_blur_far_enabled() const;
  86. void set_dof_blur_far_distance(float p_distance);
  87. float get_dof_blur_far_distance() const;
  88. void set_dof_blur_far_transition(float p_distance);
  89. float get_dof_blur_far_transition() const;
  90. void set_dof_blur_near_enabled(bool p_enabled);
  91. bool is_dof_blur_near_enabled() const;
  92. void set_dof_blur_near_distance(float p_distance);
  93. float get_dof_blur_near_distance() const;
  94. void set_dof_blur_near_transition(float p_distance);
  95. float get_dof_blur_near_transition() const;
  96. void set_dof_blur_amount(float p_amount);
  97. float get_dof_blur_amount() const;
  98. void set_auto_exposure_min_sensitivity(float p_min);
  99. float get_auto_exposure_min_sensitivity() const;
  100. void set_auto_exposure_max_sensitivity(float p_max);
  101. float get_auto_exposure_max_sensitivity() const;
  102. virtual float calculate_exposure_normalization() const override;
  103. CameraAttributesPractical();
  104. ~CameraAttributesPractical();
  105. };
  106. class CameraAttributesPhysical : public CameraAttributes {
  107. GDCLASS(CameraAttributesPhysical, CameraAttributes);
  108. private:
  109. // Exposure
  110. float exposure_aperture = 16.0; // In f-stops;
  111. float exposure_shutter_speed = 100.0; // In 1 / seconds;
  112. // Camera properties.
  113. float frustum_focal_length = 35.0; // In millimeters.
  114. float frustum_focus_distance = 10.0; // In Meters.
  115. real_t frustum_near = 0.05;
  116. real_t frustum_far = 4000.0;
  117. real_t frustum_fov = 75.0;
  118. void _update_frustum();
  119. virtual void _update_auto_exposure() override;
  120. protected:
  121. static void _bind_methods();
  122. void _validate_property(PropertyInfo &property) const;
  123. public:
  124. void set_aperture(float p_aperture);
  125. float get_aperture() const;
  126. void set_shutter_speed(float p_shutter_speed);
  127. float get_shutter_speed() const;
  128. void set_focal_length(float p_focal_length);
  129. float get_focal_length() const;
  130. void set_focus_distance(float p_focus_distance);
  131. float get_focus_distance() const;
  132. void set_near(real_t p_near);
  133. real_t get_near() const;
  134. void set_far(real_t p_far);
  135. real_t get_far() const;
  136. real_t get_fov() const;
  137. void set_auto_exposure_min_exposure_value(float p_min);
  138. float get_auto_exposure_min_exposure_value() const;
  139. void set_auto_exposure_max_exposure_value(float p_max);
  140. float get_auto_exposure_max_exposure_value() const;
  141. virtual float calculate_exposure_normalization() const override;
  142. CameraAttributesPhysical();
  143. ~CameraAttributesPhysical();
  144. };
  145. #endif // CAMERA_ATTRIBUTES_H