camera_attributes_storage.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**************************************************************************/
  2. /* camera_attributes_storage.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_STORAGE_H
  31. #define CAMERA_ATTRIBUTES_STORAGE_H
  32. #include "core/templates/rid_owner.h"
  33. #include "servers/rendering_server.h"
  34. class RendererCameraAttributes {
  35. private:
  36. static RendererCameraAttributes *singleton;
  37. struct CameraAttributes {
  38. float exposure_multiplier = 1.0;
  39. float exposure_normalization = 1.0;
  40. float exposure_sensitivity = 100.0; // In ISO.
  41. bool use_auto_exposure = false;
  42. float auto_exposure_min_sensitivity = 50.0;
  43. float auto_exposure_max_sensitivity = 800.0;
  44. float auto_exposure_adjust_speed = 1.0;
  45. float auto_exposure_scale = 1.0;
  46. uint64_t auto_exposure_version = 0;
  47. bool dof_blur_far_enabled = false;
  48. float dof_blur_far_distance = 10;
  49. float dof_blur_far_transition = 5;
  50. bool dof_blur_near_enabled = false;
  51. float dof_blur_near_distance = 2;
  52. float dof_blur_near_transition = 1;
  53. float dof_blur_amount = 0.1;
  54. };
  55. RS::DOFBlurQuality dof_blur_quality = RS::DOF_BLUR_QUALITY_MEDIUM;
  56. RS::DOFBokehShape dof_blur_bokeh_shape = RS::DOF_BOKEH_HEXAGON;
  57. bool dof_blur_use_jitter = false;
  58. static uint64_t auto_exposure_counter;
  59. mutable RID_Owner<CameraAttributes, true> camera_attributes_owner;
  60. public:
  61. static RendererCameraAttributes *get_singleton() { return singleton; }
  62. RendererCameraAttributes();
  63. ~RendererCameraAttributes();
  64. CameraAttributes *get_camera_attributes(RID p_rid) { return camera_attributes_owner.get_or_null(p_rid); };
  65. bool owns_camera_attributes(RID p_rid) { return camera_attributes_owner.owns(p_rid); };
  66. RID camera_attributes_allocate();
  67. void camera_attributes_initialize(RID p_rid);
  68. void camera_attributes_free(RID p_rid);
  69. void camera_attributes_set_dof_blur_quality(RS::DOFBlurQuality p_quality, bool p_use_jitter);
  70. void camera_attributes_set_dof_blur_bokeh_shape(RS::DOFBokehShape p_shape);
  71. void camera_attributes_set_dof_blur(RID p_camera_attributes, bool p_far_enable, float p_far_distance, float p_far_transition, bool p_near_enable, float p_near_distance, float p_near_transition, float p_amount);
  72. bool camera_attributes_get_dof_far_enabled(RID p_camera_attributes);
  73. float camera_attributes_get_dof_far_distance(RID p_camera_attributes);
  74. float camera_attributes_get_dof_far_transition(RID p_camera_attributes);
  75. bool camera_attributes_get_dof_near_enabled(RID p_camera_attributes);
  76. float camera_attributes_get_dof_near_distance(RID p_camera_attributes);
  77. float camera_attributes_get_dof_near_transition(RID p_camera_attributes);
  78. float camera_attributes_get_dof_blur_amount(RID p_camera_attributes);
  79. _FORCE_INLINE_ bool camera_attributes_uses_dof(RID p_camera_attributes) {
  80. CameraAttributes *cam_attributes = camera_attributes_owner.get_or_null(p_camera_attributes);
  81. return cam_attributes && (cam_attributes->dof_blur_near_enabled || cam_attributes->dof_blur_far_enabled) && cam_attributes->dof_blur_amount > 0.0;
  82. }
  83. void camera_attributes_set_exposure(RID p_camera_attributes, float p_multiplier, float p_exposure_normalization);
  84. float camera_attributes_get_exposure_normalization_factor(RID p_camera_attributes);
  85. void camera_attributes_set_auto_exposure(RID p_camera_attributes, bool p_enable, float p_min_sensitivity, float p_max_sensitivity, float p_speed, float p_scale);
  86. float camera_attributes_get_auto_exposure_min_sensitivity(RID p_camera_attributes);
  87. float camera_attributes_get_auto_exposure_max_sensitivity(RID p_camera_attributes);
  88. float camera_attributes_get_auto_exposure_adjust_speed(RID p_camera_attributes);
  89. float camera_attributes_get_auto_exposure_scale(RID p_camera_attributes);
  90. uint64_t camera_attributes_get_auto_exposure_version(RID p_camera_attributes);
  91. _FORCE_INLINE_ bool camera_attributes_uses_auto_exposure(RID p_camera_attributes) {
  92. CameraAttributes *cam_attributes = camera_attributes_owner.get_or_null(p_camera_attributes);
  93. return cam_attributes && cam_attributes->use_auto_exposure;
  94. }
  95. _FORCE_INLINE_ RS::DOFBlurQuality camera_attributes_get_dof_blur_quality() {
  96. return dof_blur_quality;
  97. }
  98. _FORCE_INLINE_ RS::DOFBokehShape camera_attributes_get_dof_blur_bokeh_shape() {
  99. return dof_blur_bokeh_shape;
  100. }
  101. _FORCE_INLINE_ bool camera_attributes_get_dof_blur_use_jitter() {
  102. return dof_blur_use_jitter;
  103. }
  104. };
  105. #endif // CAMERA_ATTRIBUTES_STORAGE_H