camera_attributes.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. #pragma once
  31. #include "core/io/resource.h"
  32. #include "core/templates/rid.h"
  33. class CameraAttributes : public Resource {
  34. GDCLASS(CameraAttributes, Resource);
  35. private:
  36. RID camera_attributes;
  37. protected:
  38. static void _bind_methods();
  39. void _validate_property(PropertyInfo &p_property) const;
  40. float exposure_multiplier = 1.0;
  41. float exposure_sensitivity = 100.0; // In ISO.
  42. void _update_exposure();
  43. bool auto_exposure_enabled = false;
  44. float auto_exposure_min = 0.01;
  45. float auto_exposure_max = 64.0;
  46. float auto_exposure_speed = 0.5;
  47. float auto_exposure_scale = 0.4;
  48. virtual void _update_auto_exposure() {}
  49. public:
  50. virtual RID get_rid() const override;
  51. virtual float calculate_exposure_normalization() const { return 1.0; }
  52. void set_exposure_multiplier(float p_multiplier);
  53. float get_exposure_multiplier() const;
  54. void set_exposure_sensitivity(float p_sensitivity);
  55. float get_exposure_sensitivity() const;
  56. void set_auto_exposure_enabled(bool p_enabled);
  57. bool is_auto_exposure_enabled() const;
  58. void set_auto_exposure_speed(float p_auto_exposure_speed);
  59. float get_auto_exposure_speed() const;
  60. void set_auto_exposure_scale(float p_auto_exposure_scale);
  61. float get_auto_exposure_scale() const;
  62. CameraAttributes();
  63. ~CameraAttributes();
  64. };
  65. class CameraAttributesPractical : public CameraAttributes {
  66. GDCLASS(CameraAttributesPractical, CameraAttributes);
  67. private:
  68. // DOF blur
  69. bool dof_blur_far_enabled = false;
  70. float dof_blur_far_distance = 10.0;
  71. float dof_blur_far_transition = 5.0;
  72. bool dof_blur_near_enabled = false;
  73. float dof_blur_near_distance = 2.0;
  74. float dof_blur_near_transition = 1.0;
  75. float dof_blur_amount = 0.1;
  76. void _update_dof_blur();
  77. virtual void _update_auto_exposure() override;
  78. protected:
  79. static void _bind_methods();
  80. void _validate_property(PropertyInfo &p_property) const;
  81. public:
  82. // DOF blur
  83. void set_dof_blur_far_enabled(bool p_enabled);
  84. bool is_dof_blur_far_enabled() const;
  85. void set_dof_blur_far_distance(float p_distance);
  86. float get_dof_blur_far_distance() const;
  87. void set_dof_blur_far_transition(float p_distance);
  88. float get_dof_blur_far_transition() const;
  89. void set_dof_blur_near_enabled(bool p_enabled);
  90. bool is_dof_blur_near_enabled() const;
  91. void set_dof_blur_near_distance(float p_distance);
  92. float get_dof_blur_near_distance() const;
  93. void set_dof_blur_near_transition(float p_distance);
  94. float get_dof_blur_near_transition() const;
  95. void set_dof_blur_amount(float p_amount);
  96. float get_dof_blur_amount() const;
  97. void set_auto_exposure_min_sensitivity(float p_min);
  98. float get_auto_exposure_min_sensitivity() const;
  99. void set_auto_exposure_max_sensitivity(float p_max);
  100. float get_auto_exposure_max_sensitivity() const;
  101. virtual float calculate_exposure_normalization() const override;
  102. CameraAttributesPractical();
  103. ~CameraAttributesPractical();
  104. };
  105. class CameraAttributesPhysical : public CameraAttributes {
  106. GDCLASS(CameraAttributesPhysical, CameraAttributes);
  107. private:
  108. // Exposure
  109. float exposure_aperture = 16.0; // In f-stops;
  110. float exposure_shutter_speed = 100.0; // In 1 / seconds;
  111. // Camera properties.
  112. float frustum_focal_length = 35.0; // In millimeters.
  113. float frustum_focus_distance = 10.0; // In Meters.
  114. real_t frustum_near = 0.05;
  115. real_t frustum_far = 4000.0;
  116. real_t frustum_fov = 75.0;
  117. void _update_frustum();
  118. virtual void _update_auto_exposure() override;
  119. protected:
  120. static void _bind_methods();
  121. void _validate_property(PropertyInfo &property) const;
  122. public:
  123. void set_aperture(float p_aperture);
  124. float get_aperture() const;
  125. void set_shutter_speed(float p_shutter_speed);
  126. float get_shutter_speed() const;
  127. void set_focal_length(float p_focal_length);
  128. float get_focal_length() const;
  129. void set_focus_distance(float p_focus_distance);
  130. float get_focus_distance() const;
  131. void set_near(real_t p_near);
  132. real_t get_near() const;
  133. void set_far(real_t p_far);
  134. real_t get_far() const;
  135. real_t get_fov() const;
  136. void set_auto_exposure_min_exposure_value(float p_min);
  137. float get_auto_exposure_min_exposure_value() const;
  138. void set_auto_exposure_max_exposure_value(float p_max);
  139. float get_auto_exposure_max_exposure_value() const;
  140. virtual float calculate_exposure_normalization() const override;
  141. CameraAttributesPhysical();
  142. ~CameraAttributesPhysical();
  143. };