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