gi_probe.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*************************************************************************/
  2. /* gi_probe.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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 GIPROBE_H
  31. #define GIPROBE_H
  32. #include "multimesh_instance.h"
  33. #include "scene/3d/visual_instance.h"
  34. class GIProbeData : public Resource {
  35. GDCLASS(GIProbeData, Resource);
  36. RID probe;
  37. protected:
  38. static void _bind_methods();
  39. public:
  40. void set_bounds(const AABB &p_bounds);
  41. AABB get_bounds() const;
  42. void set_cell_size(float p_size);
  43. float get_cell_size() const;
  44. void set_to_cell_xform(const Transform &p_xform);
  45. Transform get_to_cell_xform() const;
  46. void set_dynamic_data(const PoolVector<int> &p_data);
  47. PoolVector<int> get_dynamic_data() const;
  48. void set_dynamic_range(int p_range);
  49. int get_dynamic_range() const;
  50. void set_propagation(float p_range);
  51. float get_propagation() const;
  52. void set_energy(float p_range);
  53. float get_energy() const;
  54. void set_bias(float p_range);
  55. float get_bias() const;
  56. void set_normal_bias(float p_range);
  57. float get_normal_bias() const;
  58. void set_interior(bool p_enable);
  59. bool is_interior() const;
  60. void set_compress(bool p_enable);
  61. bool is_compressed() const;
  62. virtual RID get_rid() const;
  63. GIProbeData();
  64. ~GIProbeData();
  65. };
  66. class GIProbe : public VisualInstance {
  67. GDCLASS(GIProbe, VisualInstance);
  68. public:
  69. enum Subdiv {
  70. SUBDIV_64,
  71. SUBDIV_128,
  72. SUBDIV_256,
  73. SUBDIV_512,
  74. SUBDIV_MAX
  75. };
  76. typedef void (*BakeBeginFunc)(int);
  77. typedef void (*BakeStepFunc)(int, const String &);
  78. typedef void (*BakeEndFunc)();
  79. private:
  80. Ref<GIProbeData> probe_data;
  81. RID gi_probe;
  82. Subdiv subdiv;
  83. Vector3 extents;
  84. int dynamic_range;
  85. float energy;
  86. float bias;
  87. float normal_bias;
  88. float propagation;
  89. bool interior;
  90. bool compress;
  91. struct PlotMesh {
  92. Ref<Material> override_material;
  93. Vector<Ref<Material> > instance_materials;
  94. Ref<Mesh> mesh;
  95. Transform local_xform;
  96. };
  97. void _find_meshes(Node *p_at_node, List<PlotMesh> &plot_meshes);
  98. void _debug_bake();
  99. protected:
  100. static void _bind_methods();
  101. public:
  102. static BakeBeginFunc bake_begin_function;
  103. static BakeStepFunc bake_step_function;
  104. static BakeEndFunc bake_end_function;
  105. void set_probe_data(const Ref<GIProbeData> &p_data);
  106. Ref<GIProbeData> get_probe_data() const;
  107. void set_subdiv(Subdiv p_subdiv);
  108. Subdiv get_subdiv() const;
  109. void set_extents(const Vector3 &p_extents);
  110. Vector3 get_extents() const;
  111. void set_dynamic_range(int p_dynamic_range);
  112. int get_dynamic_range() const;
  113. void set_energy(float p_energy);
  114. float get_energy() const;
  115. void set_bias(float p_bias);
  116. float get_bias() const;
  117. void set_normal_bias(float p_normal_bias);
  118. float get_normal_bias() const;
  119. void set_propagation(float p_propagation);
  120. float get_propagation() const;
  121. void set_interior(bool p_enable);
  122. bool is_interior() const;
  123. void set_compress(bool p_enable);
  124. bool is_compressed() const;
  125. void bake(Node *p_from_node = NULL, bool p_create_visual_debug = false);
  126. virtual AABB get_aabb() const;
  127. virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
  128. GIProbe();
  129. ~GIProbe();
  130. };
  131. VARIANT_ENUM_CAST(GIProbe::Subdiv)
  132. #endif // GIPROBE_H