visual_instance_3d.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /**************************************************************************/
  2. /* visual_instance_3d.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 VISUAL_INSTANCE_3D_H
  31. #define VISUAL_INSTANCE_3D_H
  32. #include "scene/3d/node_3d.h"
  33. class VisualInstance3D : public Node3D {
  34. GDCLASS(VisualInstance3D, Node3D);
  35. RID base;
  36. RID instance;
  37. uint32_t layers = 1;
  38. float sorting_offset = 0.0;
  39. bool sorting_use_aabb_center = true;
  40. protected:
  41. void _update_visibility();
  42. void _notification(int p_what);
  43. static void _bind_methods();
  44. void _validate_property(PropertyInfo &p_property) const;
  45. GDVIRTUAL0RC(AABB, _get_aabb)
  46. public:
  47. enum GetFacesFlags {
  48. FACES_SOLID = 1, // solid geometry
  49. FACES_ENCLOSING = 2,
  50. FACES_DYNAMIC = 4 // dynamic object geometry
  51. };
  52. RID get_instance() const;
  53. virtual AABB get_aabb() const;
  54. void set_base(const RID &p_base);
  55. RID get_base() const;
  56. void set_layer_mask(uint32_t p_mask);
  57. uint32_t get_layer_mask() const;
  58. void set_layer_mask_value(int p_layer_number, bool p_enable);
  59. bool get_layer_mask_value(int p_layer_number) const;
  60. void set_sorting_offset(float p_offset);
  61. float get_sorting_offset() const;
  62. void set_sorting_use_aabb_center(bool p_enabled);
  63. bool is_sorting_use_aabb_center() const;
  64. VisualInstance3D();
  65. ~VisualInstance3D();
  66. };
  67. class GeometryInstance3D : public VisualInstance3D {
  68. GDCLASS(GeometryInstance3D, VisualInstance3D);
  69. public:
  70. enum ShadowCastingSetting {
  71. SHADOW_CASTING_SETTING_OFF = RS::SHADOW_CASTING_SETTING_OFF,
  72. SHADOW_CASTING_SETTING_ON = RS::SHADOW_CASTING_SETTING_ON,
  73. SHADOW_CASTING_SETTING_DOUBLE_SIDED = RS::SHADOW_CASTING_SETTING_DOUBLE_SIDED,
  74. SHADOW_CASTING_SETTING_SHADOWS_ONLY = RS::SHADOW_CASTING_SETTING_SHADOWS_ONLY
  75. };
  76. enum GIMode {
  77. GI_MODE_DISABLED,
  78. GI_MODE_STATIC,
  79. GI_MODE_DYNAMIC
  80. };
  81. enum LightmapScale {
  82. LIGHTMAP_SCALE_1X,
  83. LIGHTMAP_SCALE_2X,
  84. LIGHTMAP_SCALE_4X,
  85. LIGHTMAP_SCALE_8X,
  86. LIGHTMAP_SCALE_MAX,
  87. };
  88. enum VisibilityRangeFadeMode {
  89. VISIBILITY_RANGE_FADE_DISABLED = RS::VISIBILITY_RANGE_FADE_DISABLED,
  90. VISIBILITY_RANGE_FADE_SELF = RS::VISIBILITY_RANGE_FADE_SELF,
  91. VISIBILITY_RANGE_FADE_DEPENDENCIES = RS::VISIBILITY_RANGE_FADE_DEPENDENCIES,
  92. };
  93. private:
  94. ShadowCastingSetting shadow_casting_setting = SHADOW_CASTING_SETTING_ON;
  95. Ref<Material> material_override;
  96. Ref<Material> material_overlay;
  97. float visibility_range_begin = 0.0;
  98. float visibility_range_end = 0.0;
  99. float visibility_range_begin_margin = 0.0;
  100. float visibility_range_end_margin = 0.0;
  101. VisibilityRangeFadeMode visibility_range_fade_mode = VISIBILITY_RANGE_FADE_DISABLED;
  102. float transparency = 0.0f;
  103. float lod_bias = 1.0;
  104. mutable HashMap<StringName, Variant> instance_shader_parameters;
  105. mutable HashMap<StringName, StringName> instance_shader_parameter_property_remap;
  106. float extra_cull_margin = 0.0;
  107. AABB custom_aabb;
  108. LightmapScale lightmap_scale = LIGHTMAP_SCALE_1X;
  109. GIMode gi_mode = GI_MODE_STATIC;
  110. bool ignore_occlusion_culling = false;
  111. const StringName *_instance_uniform_get_remap(const StringName p_name) const;
  112. protected:
  113. bool _set(const StringName &p_name, const Variant &p_value);
  114. bool _get(const StringName &p_name, Variant &r_ret) const;
  115. void _get_property_list(List<PropertyInfo> *p_list) const;
  116. void _validate_property(PropertyInfo &p_property) const;
  117. static void _bind_methods();
  118. public:
  119. void set_cast_shadows_setting(ShadowCastingSetting p_shadow_casting_setting);
  120. ShadowCastingSetting get_cast_shadows_setting() const;
  121. void set_transparency(float p_transparency);
  122. float get_transparency() const;
  123. void set_visibility_range_begin(float p_dist);
  124. float get_visibility_range_begin() const;
  125. void set_visibility_range_end(float p_dist);
  126. float get_visibility_range_end() const;
  127. void set_visibility_range_begin_margin(float p_dist);
  128. float get_visibility_range_begin_margin() const;
  129. void set_visibility_range_end_margin(float p_dist);
  130. float get_visibility_range_end_margin() const;
  131. void set_visibility_range_fade_mode(VisibilityRangeFadeMode p_mode);
  132. VisibilityRangeFadeMode get_visibility_range_fade_mode() const;
  133. void set_material_override(const Ref<Material> &p_material);
  134. Ref<Material> get_material_override() const;
  135. void set_material_overlay(const Ref<Material> &p_material);
  136. Ref<Material> get_material_overlay() const;
  137. void set_extra_cull_margin(float p_margin);
  138. float get_extra_cull_margin() const;
  139. void set_lod_bias(float p_bias);
  140. float get_lod_bias() const;
  141. void set_gi_mode(GIMode p_mode);
  142. GIMode get_gi_mode() const;
  143. void set_lightmap_scale(LightmapScale p_scale);
  144. LightmapScale get_lightmap_scale() const;
  145. void set_instance_shader_parameter(const StringName &p_name, const Variant &p_value);
  146. Variant get_instance_shader_parameter(const StringName &p_name) const;
  147. void set_custom_aabb(AABB p_aabb);
  148. AABB get_custom_aabb() const;
  149. void set_ignore_occlusion_culling(bool p_enabled);
  150. bool is_ignoring_occlusion_culling();
  151. PackedStringArray get_configuration_warnings() const override;
  152. GeometryInstance3D();
  153. virtual ~GeometryInstance3D();
  154. };
  155. VARIANT_ENUM_CAST(GeometryInstance3D::ShadowCastingSetting);
  156. VARIANT_ENUM_CAST(GeometryInstance3D::LightmapScale);
  157. VARIANT_ENUM_CAST(GeometryInstance3D::GIMode);
  158. VARIANT_ENUM_CAST(GeometryInstance3D::VisibilityRangeFadeMode);
  159. #endif // VISUAL_INSTANCE_3D_H