visual_instance_3d.h 7.4 KB

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