renderer_geometry_instance.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**************************************************************************/
  2. /* renderer_geometry_instance.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 RENDERER_GEOMETRY_INSTANCE_H
  31. #define RENDERER_GEOMETRY_INSTANCE_H
  32. #include "core/math/rect2.h"
  33. #include "core/math/transform_3d.h"
  34. #include "core/math/vector3.h"
  35. #include "core/templates/rid.h"
  36. #include "storage/utilities.h"
  37. // API definition for our RenderGeometryInstance class so we can expose this through GDExtension in the near future
  38. class RenderGeometryInstance {
  39. public:
  40. virtual ~RenderGeometryInstance() {}
  41. virtual void _mark_dirty() = 0;
  42. virtual void set_skeleton(RID p_skeleton) = 0;
  43. virtual void set_material_override(RID p_override) = 0;
  44. virtual void set_material_overlay(RID p_overlay) = 0;
  45. virtual void set_surface_materials(const Vector<RID> &p_materials) = 0;
  46. virtual void set_mesh_instance(RID p_mesh_instance) = 0;
  47. virtual void set_transform(const Transform3D &p_transform, const AABB &p_aabb, const AABB &p_transformed_aabb) = 0;
  48. virtual void set_pivot_data(float p_sorting_offset, bool p_use_aabb_center) = 0;
  49. virtual void set_lod_bias(float p_lod_bias) = 0;
  50. virtual void set_layer_mask(uint32_t p_layer_mask) = 0;
  51. virtual void set_fade_range(bool p_enable_near, float p_near_begin, float p_near_end, bool p_enable_far, float p_far_begin, float p_far_end) = 0;
  52. virtual void set_parent_fade_alpha(float p_alpha) = 0;
  53. virtual void set_transparency(float p_transparency) = 0;
  54. virtual void set_use_baked_light(bool p_enable) = 0;
  55. virtual void set_use_dynamic_gi(bool p_enable) = 0;
  56. virtual void set_use_lightmap(RID p_lightmap_instance, const Rect2 &p_lightmap_uv_scale, int p_lightmap_slice_index) = 0;
  57. virtual void set_lightmap_capture(const Color *p_sh9) = 0;
  58. virtual void set_instance_shader_uniforms_offset(int32_t p_offset) = 0;
  59. virtual void set_cast_double_sided_shadows(bool p_enable) = 0;
  60. virtual Transform3D get_transform() = 0;
  61. virtual AABB get_aabb() = 0;
  62. virtual void pair_light_instances(const RID *p_light_instances, uint32_t p_light_instance_count) = 0;
  63. virtual void pair_reflection_probe_instances(const RID *p_reflection_probe_instances, uint32_t p_reflection_probe_instance_count) = 0;
  64. virtual void pair_decal_instances(const RID *p_decal_instances, uint32_t p_decal_instance_count) = 0;
  65. virtual void pair_voxel_gi_instances(const RID *p_voxel_gi_instances, uint32_t p_voxel_gi_instance_count) = 0;
  66. virtual void set_softshadow_projector_pairing(bool p_softshadow, bool p_projector) = 0;
  67. };
  68. // Base implementation of RenderGeometryInstance shared by internal renderers.
  69. class RenderGeometryInstanceBase : public RenderGeometryInstance {
  70. public:
  71. // setup
  72. uint32_t base_flags = 0;
  73. uint32_t flags_cache = 0;
  74. // used during rendering
  75. float depth = 0;
  76. RID mesh_instance;
  77. Transform3D transform;
  78. bool mirror = false;
  79. AABB transformed_aabb;
  80. bool non_uniform_scale = false;
  81. float lod_model_scale = 1.0;
  82. float lod_bias = 0.0;
  83. float sorting_offset = 0.0;
  84. bool use_aabb_center = true;
  85. uint32_t layer_mask = 1;
  86. bool fade_near = false;
  87. float fade_near_begin = 0;
  88. float fade_near_end = 0;
  89. bool fade_far = false;
  90. float fade_far_begin = 0;
  91. float fade_far_end = 0;
  92. float parent_fade_alpha = 1.0;
  93. float force_alpha = 1.0;
  94. int32_t shader_uniforms_offset = -1;
  95. struct Data {
  96. //data used less often goes into regular heap
  97. RID base;
  98. RS::InstanceType base_type;
  99. RID skeleton;
  100. Vector<RID> surface_materials;
  101. RID material_override;
  102. RID material_overlay;
  103. AABB aabb;
  104. bool use_baked_light = false;
  105. bool use_dynamic_gi = false;
  106. bool cast_double_sided_shadows = false;
  107. bool dirty_dependencies = false;
  108. DependencyTracker dependency_tracker;
  109. };
  110. Data *data = nullptr;
  111. virtual void set_skeleton(RID p_skeleton) override;
  112. virtual void set_material_override(RID p_override) override;
  113. virtual void set_material_overlay(RID p_overlay) override;
  114. virtual void set_surface_materials(const Vector<RID> &p_materials) override;
  115. virtual void set_mesh_instance(RID p_mesh_instance) override;
  116. virtual void set_transform(const Transform3D &p_transform, const AABB &p_aabb, const AABB &p_transformed_aabb) override;
  117. virtual void set_pivot_data(float p_sorting_offset, bool p_use_aabb_center) override;
  118. virtual void set_lod_bias(float p_lod_bias) override;
  119. virtual void set_layer_mask(uint32_t p_layer_mask) override;
  120. virtual void set_fade_range(bool p_enable_near, float p_near_begin, float p_near_end, bool p_enable_far, float p_far_begin, float p_far_end) override;
  121. virtual void set_parent_fade_alpha(float p_alpha) override;
  122. virtual void set_transparency(float p_transparency) override;
  123. virtual void set_use_baked_light(bool p_enable) override;
  124. virtual void set_use_dynamic_gi(bool p_enable) override;
  125. virtual void set_instance_shader_uniforms_offset(int32_t p_offset) override;
  126. virtual void set_cast_double_sided_shadows(bool p_enable) override;
  127. virtual Transform3D get_transform() override;
  128. virtual AABB get_aabb() override;
  129. };
  130. #endif // RENDERER_GEOMETRY_INSTANCE_H