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