visual_instance_3d.h 7.5 KB

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