voxel_gi.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /**************************************************************************/
  2. /* voxel_gi.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 VOXEL_GI_H
  31. #define VOXEL_GI_H
  32. #include "scene/3d/visual_instance_3d.h"
  33. class CameraAttributes;
  34. class VoxelGIData : public Resource {
  35. GDCLASS(VoxelGIData, Resource);
  36. RID probe;
  37. void _set_data(const Dictionary &p_data);
  38. Dictionary _get_data() const;
  39. Transform3D to_cell_xform;
  40. AABB bounds;
  41. Vector3 octree_size;
  42. float dynamic_range = 2.0;
  43. float energy = 1.0;
  44. float bias = 1.5;
  45. float normal_bias = 0.0;
  46. float propagation = 0.5;
  47. bool interior = false;
  48. bool use_two_bounces = true;
  49. protected:
  50. static void _bind_methods();
  51. public:
  52. void allocate(const Transform3D &p_to_cell_xform, const AABB &p_aabb, const Vector3 &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts);
  53. AABB get_bounds() const;
  54. Vector3 get_octree_size() const;
  55. Vector<uint8_t> get_octree_cells() const;
  56. Vector<uint8_t> get_data_cells() const;
  57. Vector<uint8_t> get_distance_field() const;
  58. Vector<int> get_level_counts() const;
  59. Transform3D get_to_cell_xform() const;
  60. void set_dynamic_range(float p_range);
  61. float get_dynamic_range() const;
  62. void set_propagation(float p_propagation);
  63. float get_propagation() const;
  64. void set_energy(float p_energy);
  65. float get_energy() const;
  66. void set_bias(float p_bias);
  67. float get_bias() const;
  68. void set_normal_bias(float p_normal_bias);
  69. float get_normal_bias() const;
  70. void set_interior(bool p_enable);
  71. bool is_interior() const;
  72. void set_use_two_bounces(bool p_enable);
  73. bool is_using_two_bounces() const;
  74. virtual RID get_rid() const override;
  75. VoxelGIData();
  76. ~VoxelGIData();
  77. };
  78. class VoxelGI : public VisualInstance3D {
  79. GDCLASS(VoxelGI, VisualInstance3D);
  80. public:
  81. enum Subdiv {
  82. SUBDIV_64,
  83. SUBDIV_128,
  84. SUBDIV_256,
  85. SUBDIV_512,
  86. SUBDIV_MAX
  87. };
  88. typedef void (*BakeBeginFunc)();
  89. typedef bool (*BakeStepFunc)(int, const String &);
  90. typedef void (*BakeEndFunc)();
  91. private:
  92. Ref<VoxelGIData> probe_data;
  93. RID voxel_gi;
  94. Subdiv subdiv = SUBDIV_128;
  95. Vector3 size = Vector3(20, 20, 20);
  96. Ref<CameraAttributes> camera_attributes;
  97. struct PlotMesh {
  98. Ref<Material> override_material;
  99. Vector<Ref<Material>> instance_materials;
  100. Ref<Mesh> mesh;
  101. Transform3D local_xform;
  102. };
  103. void _find_meshes(Node *p_at_node, List<PlotMesh> &plot_meshes);
  104. void _debug_bake();
  105. float _get_camera_exposure_normalization();
  106. protected:
  107. static void _bind_methods();
  108. #ifndef DISABLE_DEPRECATED
  109. bool _set(const StringName &p_name, const Variant &p_value);
  110. bool _get(const StringName &p_name, Variant &r_property) const;
  111. #endif // DISABLE_DEPRECATED
  112. public:
  113. static BakeBeginFunc bake_begin_function;
  114. static BakeStepFunc bake_step_function;
  115. static BakeEndFunc bake_end_function;
  116. void set_probe_data(const Ref<VoxelGIData> &p_data);
  117. Ref<VoxelGIData> get_probe_data() const;
  118. void set_subdiv(Subdiv p_subdiv);
  119. Subdiv get_subdiv() const;
  120. void set_size(const Vector3 &p_size);
  121. Vector3 get_size() const;
  122. void set_camera_attributes(const Ref<CameraAttributes> &p_camera_attributes);
  123. Ref<CameraAttributes> get_camera_attributes() const;
  124. Vector3i get_estimated_cell_size() const;
  125. void bake(Node *p_from_node = nullptr, bool p_create_visual_debug = false);
  126. virtual AABB get_aabb() const override;
  127. PackedStringArray get_configuration_warnings() const override;
  128. VoxelGI();
  129. ~VoxelGI();
  130. };
  131. VARIANT_ENUM_CAST(VoxelGI::Subdiv)
  132. #endif // VOXEL_GI_H