summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/cpu_particles_2d.cpp6
-rw-r--r--scene/2d/navigation_agent_2d.cpp19
-rw-r--r--scene/2d/navigation_agent_2d.h14
-rw-r--r--scene/2d/navigation_obstacle_2d.cpp4
-rw-r--r--scene/2d/navigation_obstacle_2d.h2
-rw-r--r--scene/2d/navigation_region_2d.cpp11
-rw-r--r--scene/2d/navigation_region_2d.h10
-rw-r--r--scene/2d/physics_body_2d.cpp3
-rw-r--r--scene/2d/polygon_2d.cpp2
-rw-r--r--scene/2d/tile_map.cpp27
-rw-r--r--scene/2d/tile_map.h8
-rw-r--r--scene/2d/visibility_notifier_2d.cpp17
-rw-r--r--scene/3d/audio_stream_player_3d.cpp3
-rw-r--r--scene/3d/baked_lightmap.cpp1628
-rw-r--r--scene/3d/baked_lightmap.h250
-rw-r--r--scene/3d/cpu_particles_3d.cpp6
-rw-r--r--scene/3d/gi_probe.cpp2
-rw-r--r--scene/3d/gpu_particles_3d.cpp3
-rw-r--r--scene/3d/light_3d.cpp12
-rw-r--r--scene/3d/lightmap_probe.cpp4
-rw-r--r--scene/3d/lightmap_probe.h12
-rw-r--r--scene/3d/lightmapper.cpp37
-rw-r--r--scene/3d/lightmapper.h90
-rw-r--r--scene/3d/navigation_agent_3d.cpp20
-rw-r--r--scene/3d/navigation_agent_3d.h16
-rw-r--r--scene/3d/navigation_obstacle_3d.cpp4
-rw-r--r--scene/3d/navigation_obstacle_3d.h2
-rw-r--r--scene/3d/navigation_region_3d.cpp6
-rw-r--r--scene/3d/navigation_region_3d.h8
-rw-r--r--scene/3d/physics_body_3d.cpp22
-rw-r--r--scene/3d/physics_body_3d.h169
-rw-r--r--scene/3d/physics_joint_3d.cpp3
-rw-r--r--scene/3d/physics_joint_3d.h2
-rw-r--r--scene/3d/skeleton_ik_3d.cpp10
-rw-r--r--scene/3d/skeleton_ik_3d.h52
-rw-r--r--scene/3d/soft_body_3d.cpp12
-rw-r--r--scene/3d/soft_body_3d.h16
-rw-r--r--scene/3d/spring_arm_3d.cpp8
-rw-r--r--scene/3d/spring_arm_3d.h12
-rw-r--r--scene/3d/vehicle_body_3d.cpp2
-rw-r--r--scene/3d/visual_instance_3d.cpp93
-rw-r--r--scene/3d/visual_instance_3d.h36
-rw-r--r--scene/3d/voxelizer.cpp190
-rw-r--r--scene/3d/xr_nodes.cpp8
-rw-r--r--scene/3d/xr_nodes.h12
-rw-r--r--scene/animation/animation_blend_space_2d.cpp3
-rw-r--r--scene/animation/animation_player.cpp11
-rw-r--r--scene/animation/animation_player.h65
-rw-r--r--scene/animation/tween.cpp59
-rw-r--r--scene/debugger/scene_debugger.h2
-rw-r--r--scene/gui/file_dialog.cpp3
-rw-r--r--scene/gui/label.cpp17
-rw-r--r--scene/gui/label.h43
-rw-r--r--scene/gui/line_edit.cpp19
-rw-r--r--scene/gui/rich_text_label.cpp28
-rw-r--r--scene/gui/slider.cpp6
-rw-r--r--scene/gui/subviewport_container.cpp2
-rw-r--r--scene/gui/subviewport_container.h2
-rw-r--r--scene/gui/tabs.cpp6
-rw-r--r--scene/gui/text_edit.cpp5
-rw-r--r--scene/gui/tree.cpp18
-rw-r--r--scene/gui/tree.h2
-rw-r--r--scene/main/canvas_item.cpp63
-rw-r--r--scene/main/canvas_item.h14
-rw-r--r--scene/main/node.cpp24
-rw-r--r--scene/main/scene_tree.cpp6
-rw-r--r--scene/main/shader_globals_override.cpp32
-rw-r--r--scene/main/shader_globals_override.h30
-rw-r--r--scene/main/timer.cpp8
-rw-r--r--scene/main/viewport.cpp4
-rw-r--r--scene/register_scene_types.cpp20
-rw-r--r--scene/resources/animation.cpp27
-rw-r--r--scene/resources/audio_stream_sample.cpp36
-rw-r--r--scene/resources/capsule_shape_2d.cpp3
-rw-r--r--scene/resources/environment.cpp8
-rw-r--r--scene/resources/environment.h10
-rw-r--r--scene/resources/material.cpp109
-rw-r--r--scene/resources/mesh.cpp6
-rw-r--r--scene/resources/mesh.h6
-rw-r--r--scene/resources/particles_material.cpp9
-rw-r--r--scene/resources/physics_material.cpp6
-rw-r--r--scene/resources/physics_material.h16
-rw-r--r--scene/resources/shape_3d.cpp12
-rw-r--r--scene/resources/shape_3d.h2
-rw-r--r--scene/resources/texture.cpp487
-rw-r--r--scene/resources/texture.h166
-rw-r--r--scene/resources/theme.cpp2
-rw-r--r--scene/resources/theme.h2
-rw-r--r--scene/resources/tile_set.cpp3
-rw-r--r--scene/resources/tile_set.h38
-rw-r--r--scene/resources/visual_shader.cpp40
-rw-r--r--scene/resources/visual_shader_nodes.cpp154
-rw-r--r--scene/scene_string_names.cpp5
-rw-r--r--scene/scene_string_names.h4
94 files changed, 2813 insertions, 1703 deletions
diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp
index 0a6b091a51..c37cd398c4 100644
--- a/scene/2d/cpu_particles_2d.cpp
+++ b/scene/2d/cpu_particles_2d.cpp
@@ -961,7 +961,8 @@ void CPUParticles2D::_particles_process(float p_delta) {
//scale by scale
float base_scale = tex_scale * Math::lerp(parameters[PARAM_SCALE], 1.0f, p.scale_rand * randomness[PARAM_SCALE]);
- if (base_scale < 0.000001) base_scale = 0.000001;
+ if (base_scale < 0.000001)
+ base_scale = 0.000001;
p.transform.elements[0] *= base_scale;
p.transform.elements[1] *= base_scale;
@@ -1196,7 +1197,8 @@ void CPUParticles2D::convert_from_particles(Node *p_particles) {
set_param(m_param, material->get_param(ParticlesMaterial::m_param)); \
{ \
Ref<CurveTexture> ctex = material->get_param_texture(ParticlesMaterial::m_param); \
- if (ctex.is_valid()) set_param_curve(m_param, ctex->get_curve()); \
+ if (ctex.is_valid()) \
+ set_param_curve(m_param, ctex->get_curve()); \
} \
set_param_randomness(m_param, material->get_param_randomness(ParticlesMaterial::m_param));
diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp
index 32da46e8a8..dfeb5eea45 100644
--- a/scene/2d/navigation_agent_2d.cpp
+++ b/scene/2d/navigation_agent_2d.cpp
@@ -133,15 +133,7 @@ void NavigationAgent2D::_notification(int p_what) {
}
}
-NavigationAgent2D::NavigationAgent2D() :
- agent_parent(nullptr),
- navigation(nullptr),
- agent(RID()),
- target_desired_distance(1.0),
- path_max_distance(3.0),
- velocity_submitted(false),
- target_reached(false),
- navigation_finished(true) {
+NavigationAgent2D::NavigationAgent2D() {
agent = NavigationServer2D::get_singleton()->agent_create();
set_neighbor_dist(500.0);
set_max_neighbors(10);
@@ -288,9 +280,12 @@ String NavigationAgent2D::get_configuration_warning() const {
void NavigationAgent2D::update_navigation() {
- if (agent_parent == nullptr) return;
- if (navigation == nullptr) return;
- if (update_frame_id == Engine::get_singleton()->get_physics_frames()) return;
+ if (agent_parent == nullptr)
+ return;
+ if (navigation == nullptr)
+ return;
+ if (update_frame_id == Engine::get_singleton()->get_physics_frames())
+ return;
update_frame_id = Engine::get_singleton()->get_physics_frames();
diff --git a/scene/2d/navigation_agent_2d.h b/scene/2d/navigation_agent_2d.h
index 26eccfc949..796a85f3f2 100644
--- a/scene/2d/navigation_agent_2d.h
+++ b/scene/2d/navigation_agent_2d.h
@@ -40,29 +40,29 @@ class Navigation2D;
class NavigationAgent2D : public Node {
GDCLASS(NavigationAgent2D, Node);
- Node2D *agent_parent;
- Navigation2D *navigation;
+ Node2D *agent_parent = nullptr;
+ Navigation2D *navigation = nullptr;
RID agent;
- real_t target_desired_distance;
+ real_t target_desired_distance = 1.0;
real_t radius;
real_t neighbor_dist;
int max_neighbors;
real_t time_horizon;
real_t max_speed;
- real_t path_max_distance;
+ real_t path_max_distance = 3.0;
Vector2 target_location;
Vector<Vector2> navigation_path;
int nav_path_index;
- bool velocity_submitted;
+ bool velocity_submitted = false;
Vector2 prev_safe_velocity;
/// The submitted target velocity
Vector2 target_velocity;
- bool target_reached;
- bool navigation_finished;
+ bool target_reached = false;
+ bool navigation_finished = true;
// No initialized on purpose
uint32_t update_frame_id;
diff --git a/scene/2d/navigation_obstacle_2d.cpp b/scene/2d/navigation_obstacle_2d.cpp
index 50d02ca507..3eb3ef332f 100644
--- a/scene/2d/navigation_obstacle_2d.cpp
+++ b/scene/2d/navigation_obstacle_2d.cpp
@@ -78,9 +78,7 @@ void NavigationObstacle2D::_notification(int p_what) {
}
}
-NavigationObstacle2D::NavigationObstacle2D() :
- navigation(nullptr),
- agent(RID()) {
+NavigationObstacle2D::NavigationObstacle2D() {
agent = NavigationServer2D::get_singleton()->agent_create();
}
diff --git a/scene/2d/navigation_obstacle_2d.h b/scene/2d/navigation_obstacle_2d.h
index 3935fe1bc5..bdef6f2843 100644
--- a/scene/2d/navigation_obstacle_2d.h
+++ b/scene/2d/navigation_obstacle_2d.h
@@ -38,7 +38,7 @@ class Navigation2D;
class NavigationObstacle2D : public Node {
GDCLASS(NavigationObstacle2D, Node);
- Navigation2D *navigation;
+ Navigation2D *navigation = nullptr;
RID agent;
diff --git a/scene/2d/navigation_region_2d.cpp b/scene/2d/navigation_region_2d.cpp
index abbfbf83b7..f3f335e66a 100644
--- a/scene/2d/navigation_region_2d.cpp
+++ b/scene/2d/navigation_region_2d.cpp
@@ -367,13 +367,6 @@ void NavigationPolygon::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "outlines", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_outlines", "_get_outlines");
}
-NavigationPolygon::NavigationPolygon() :
- rect_cache_dirty(true) {
-}
-
-NavigationPolygon::~NavigationPolygon() {
-}
-
void NavigationRegion2D::set_enabled(bool p_enabled) {
if (enabled == p_enabled)
@@ -569,12 +562,8 @@ void NavigationRegion2D::_bind_methods() {
}
NavigationRegion2D::NavigationRegion2D() {
-
- enabled = true;
set_notify_transform(true);
region = NavigationServer2D::get_singleton()->region_create();
-
- navigation = nullptr;
}
NavigationRegion2D::~NavigationRegion2D() {
diff --git a/scene/2d/navigation_region_2d.h b/scene/2d/navigation_region_2d.h
index e730df6373..54d2ac11f8 100644
--- a/scene/2d/navigation_region_2d.h
+++ b/scene/2d/navigation_region_2d.h
@@ -46,7 +46,7 @@ class NavigationPolygon : public Resource {
Vector<Vector<Vector2>> outlines;
mutable Rect2 item_rect;
- mutable bool rect_cache_dirty;
+ mutable bool rect_cache_dirty = true;
Mutex navmesh_generation;
// Navigation mesh
@@ -88,8 +88,8 @@ public:
Ref<NavigationMesh> get_mesh();
- NavigationPolygon();
- ~NavigationPolygon();
+ NavigationPolygon() {}
+ ~NavigationPolygon() {}
};
class Navigation2D;
@@ -98,9 +98,9 @@ class NavigationRegion2D : public Node2D {
GDCLASS(NavigationRegion2D, Node2D);
- bool enabled;
+ bool enabled = true;
RID region;
- Navigation2D *navigation;
+ Navigation2D *navigation = nullptr;
Ref<NavigationPolygon> navpoly;
void _navpoly_changed();
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index de15f0efc2..4198eb6c06 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -1394,7 +1394,8 @@ Vector2 KinematicCollision2D::get_remainder() const {
return collision.remainder;
}
Object *KinematicCollision2D::get_local_shape() const {
- if (!owner) return nullptr;
+ if (!owner)
+ return nullptr;
uint32_t ownerid = owner->shape_find_owner(collision.local_shape);
return owner->shape_owner_get_owner(ownerid);
}
diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp
index 84c1828b47..cec598774e 100644
--- a/scene/2d/polygon_2d.cpp
+++ b/scene/2d/polygon_2d.cpp
@@ -723,7 +723,7 @@ void Polygon2D::_bind_methods() {
Polygon2D::Polygon2D() {
- invert = 0;
+ invert = false;
invert_border = 100;
antialiased = false;
tex_rot = 0;
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 86e61fe878..869f290f97 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -40,7 +40,7 @@
int TileMap::_get_quadrant_size() const {
- if (y_sort_mode)
+ if (use_y_sort)
return 1;
else
return quadrant_size;
@@ -1355,7 +1355,8 @@ bool TileMap::get_collision_use_parent() const {
void TileMap::set_collision_use_parent(bool p_use_parent) {
- if (use_parent == p_use_parent) return;
+ if (use_parent == p_use_parent)
+ return;
_clear_quadrants();
@@ -1648,18 +1649,18 @@ Vector2 TileMap::world_to_map(const Vector2 &p_pos) const {
return ret.floor();
}
-void TileMap::set_y_sort_mode(bool p_enable) {
+void TileMap::set_y_sort_enabled(bool p_enable) {
_clear_quadrants();
- y_sort_mode = p_enable;
- RS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), y_sort_mode);
+ use_y_sort = p_enable;
+ RS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), use_y_sort);
_recreate_quadrants();
emit_signal("settings_changed");
}
-bool TileMap::is_y_sort_mode_enabled() const {
+bool TileMap::is_y_sort_enabled() const {
- return y_sort_mode;
+ return use_y_sort;
}
void TileMap::set_compatibility_mode(bool p_enable) {
@@ -1702,7 +1703,7 @@ TypedArray<Vector2i> TileMap::get_used_cells() const {
return a;
}
-TypedArray<Vector2i> TileMap::get_used_cells_by_id(int p_id) const {
+TypedArray<Vector2i> TileMap::get_used_cells_by_index(int p_id) const {
TypedArray<Vector2i> a;
for (Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) {
@@ -1822,8 +1823,8 @@ void TileMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_clip_uv", "enable"), &TileMap::set_clip_uv);
ClassDB::bind_method(D_METHOD("get_clip_uv"), &TileMap::get_clip_uv);
- ClassDB::bind_method(D_METHOD("set_y_sort_mode", "enable"), &TileMap::set_y_sort_mode);
- ClassDB::bind_method(D_METHOD("is_y_sort_mode_enabled"), &TileMap::is_y_sort_mode_enabled);
+ ClassDB::bind_method(D_METHOD("set_y_sort_enabled", "enable"), &TileMap::set_y_sort_enabled);
+ ClassDB::bind_method(D_METHOD("is_y_sort_enabled"), &TileMap::is_y_sort_enabled);
ClassDB::bind_method(D_METHOD("set_compatibility_mode", "enable"), &TileMap::set_compatibility_mode);
ClassDB::bind_method(D_METHOD("is_compatibility_mode_enabled"), &TileMap::is_compatibility_mode_enabled);
@@ -1873,7 +1874,7 @@ void TileMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear"), &TileMap::clear);
ClassDB::bind_method(D_METHOD("get_used_cells"), &TileMap::get_used_cells);
- ClassDB::bind_method(D_METHOD("get_used_cells_by_id", "id"), &TileMap::get_used_cells_by_id);
+ ClassDB::bind_method(D_METHOD("get_used_cells_by_index", "index"), &TileMap::get_used_cells_by_index);
ClassDB::bind_method(D_METHOD("get_used_rect"), &TileMap::get_used_rect);
ClassDB::bind_method(D_METHOD("map_to_world", "map_position", "ignore_half_ofs"), &TileMap::map_to_world, DEFVAL(false));
@@ -1897,7 +1898,7 @@ void TileMap::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "cell_custom_transform"), "set_custom_transform", "get_custom_transform");
ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_half_offset", PROPERTY_HINT_ENUM, "Offset X,Offset Y,Disabled,Offset Negative X,Offset Negative Y"), "set_half_offset", "get_half_offset");
ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_tile_origin", PROPERTY_HINT_ENUM, "Top Left,Center,Bottom Left"), "set_tile_origin", "get_tile_origin");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_y_sort"), "set_y_sort_mode", "is_y_sort_mode_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_y_sort"), "set_y_sort_enabled", "is_y_sort_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "compatibility_mode"), "set_compatibility_mode", "is_compatibility_mode_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "centered_textures"), "set_centered_textures", "is_centered_textures_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_clip_uv"), "set_clip_uv", "get_clip_uv");
@@ -1959,7 +1960,7 @@ TileMap::TileMap() {
collision_parent = nullptr;
use_kinematic = false;
navigation = nullptr;
- y_sort_mode = false;
+ use_y_sort = false;
compatibility_mode = false;
centered_textures = false;
occluder_light_mask = 1;
diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h
index cc1537f583..16784571bf 100644
--- a/scene/2d/tile_map.h
+++ b/scene/2d/tile_map.h
@@ -187,7 +187,7 @@ private:
Rect2 used_size_cache;
bool used_size_cache_dirty;
bool quadrant_order_dirty;
- bool y_sort_mode;
+ bool use_y_sort;
bool compatibility_mode;
bool centered_textures;
bool clip_uv;
@@ -319,8 +319,8 @@ public:
Vector2 map_to_world(const Vector2 &p_pos, bool p_ignore_ofs = false) const;
Vector2 world_to_map(const Vector2 &p_pos) const;
- void set_y_sort_mode(bool p_enable);
- bool is_y_sort_mode_enabled() const;
+ void set_y_sort_enabled(bool p_enable);
+ bool is_y_sort_enabled() const;
void set_compatibility_mode(bool p_enable);
bool is_compatibility_mode_enabled() const;
@@ -329,7 +329,7 @@ public:
bool is_centered_textures_enabled() const;
TypedArray<Vector2i> get_used_cells() const;
- TypedArray<Vector2i> get_used_cells_by_id(int p_id) const;
+ TypedArray<Vector2i> get_used_cells_by_index(int p_index) const;
Rect2 get_used_rect(); // Not const because of cache
void set_occluder_light_mask(int p_mask);
diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp
index c374dd5faa..780d08693d 100644
--- a/scene/2d/visibility_notifier_2d.cpp
+++ b/scene/2d/visibility_notifier_2d.cpp
@@ -248,10 +248,19 @@ void VisibilityEnabler2D::_notification(int p_what) {
_find_nodes(from);
- if (enabler[ENABLER_PARENT_PHYSICS_PROCESS] && get_parent())
- get_parent()->set_physics_process(false);
- if (enabler[ENABLER_PARENT_PROCESS] && get_parent())
- get_parent()->set_process(false);
+ // We need to defer the call of set_process and set_physics_process,
+ // otherwise they are overwritten inside NOTIFICATION_READY.
+ // We can't use call_deferred, because it happens after a physics frame.
+ // The ready signal works as it's emitted immediately after NOTIFICATION_READY.
+
+ if (enabler[ENABLER_PARENT_PHYSICS_PROCESS] && get_parent()) {
+ get_parent()->connect(SceneStringNames::get_singleton()->ready,
+ callable_mp(get_parent(), &Node::set_physics_process), varray(false), CONNECT_ONESHOT);
+ }
+ if (enabler[ENABLER_PARENT_PROCESS] && get_parent()) {
+ get_parent()->connect(SceneStringNames::get_singleton()->ready,
+ callable_mp(get_parent(), &Node::set_process), varray(false), CONNECT_ONESHOT);
+ }
}
if (p_what == NOTIFICATION_EXIT_TREE) {
diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp
index 5701d3cea2..8a00d67e12 100644
--- a/scene/3d/audio_stream_player_3d.cpp
+++ b/scene/3d/audio_stream_player_3d.cpp
@@ -320,7 +320,8 @@ float AudioStreamPlayer3D::_get_attenuation_db(float p_distance) const {
case ATTENUATION_LOGARITHMIC: {
att = -20 * Math::log(p_distance / unit_size + CMP_EPSILON);
} break;
- case ATTENUATION_DISABLED: break;
+ case ATTENUATION_DISABLED:
+ break;
default: {
ERR_PRINT("Unknown attenuation type");
break;
diff --git a/scene/3d/baked_lightmap.cpp b/scene/3d/baked_lightmap.cpp
index 6bde56104e..82a9a1e589 100644
--- a/scene/3d/baked_lightmap.cpp
+++ b/scene/3d/baked_lightmap.cpp
@@ -28,72 +28,25 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#if 0
#include "baked_lightmap.h"
+
#include "core/io/config_file.h"
#include "core/io/resource_saver.h"
+#include "core/math/camera_matrix.h"
+#include "core/math/delaunay_3d.h"
#include "core/os/dir_access.h"
+#include "core/os/file_access.h"
#include "core/os/os.h"
-#include "voxel_light_baker.h"
-
-void BakedLightmapData::set_bounds(const AABB &p_bounds) {
-
- bounds = p_bounds;
- RS::get_singleton()->lightmap_capture_set_bounds(baked_light, p_bounds);
-}
-
-AABB BakedLightmapData::get_bounds() const {
-
- return bounds;
-}
-
-void BakedLightmapData::set_octree(const Vector<uint8_t> &p_octree) {
-
- RS::get_singleton()->lightmap_capture_set_octree(baked_light, p_octree);
-}
-
-Vector<uint8_t> BakedLightmapData::get_octree() const {
-
- return RS::get_singleton()->lightmap_capture_get_octree(baked_light);
-}
-
-void BakedLightmapData::set_cell_space_transform(const Transform &p_xform) {
-
- cell_space_xform = p_xform;
- RS::get_singleton()->lightmap_capture_set_octree_cell_transform(baked_light, p_xform);
-}
-
-Transform BakedLightmapData::get_cell_space_transform() const {
- return cell_space_xform;
-}
-
-void BakedLightmapData::set_cell_subdiv(int p_cell_subdiv) {
- cell_subdiv = p_cell_subdiv;
- RS::get_singleton()->lightmap_capture_set_octree_cell_subdiv(baked_light, p_cell_subdiv);
-}
-
-int BakedLightmapData::get_cell_subdiv() const {
- return cell_subdiv;
-}
+#include "core/sort_array.h"
+#include "lightmap_probe.h"
-void BakedLightmapData::set_energy(float p_energy) {
+void BakedLightmapData::add_user(const NodePath &p_path, const Rect2 &p_uv_scale, int p_slice_index, int32_t p_sub_instance) {
- energy = p_energy;
- RS::get_singleton()->lightmap_capture_set_energy(baked_light, energy);
-}
-
-float BakedLightmapData::get_energy() const {
-
- return energy;
-}
-
-void BakedLightmapData::add_user(const NodePath &p_path, const Ref<Texture2D> &p_lightmap, int p_instance) {
-
- ERR_FAIL_COND_MSG(p_lightmap.is_null(), "It's not a reference to a valid Texture object.");
User user;
user.path = p_path;
- user.lightmap = p_lightmap;
- user.instance_index = p_instance;
+ user.uv_scale = p_uv_scale;
+ user.slice_index = p_slice_index;
+ user.sub_instance = p_sub_instance;
users.push_back(user);
}
@@ -106,16 +59,23 @@ NodePath BakedLightmapData::get_user_path(int p_user) const {
ERR_FAIL_INDEX_V(p_user, users.size(), NodePath());
return users[p_user].path;
}
-Ref<Texture2D> BakedLightmapData::get_user_lightmap(int p_user) const {
- ERR_FAIL_INDEX_V(p_user, users.size(), Ref<Texture2D>());
- return users[p_user].lightmap;
+int32_t BakedLightmapData::get_user_sub_instance(int p_user) const {
+
+ ERR_FAIL_INDEX_V(p_user, users.size(), -1);
+ return users[p_user].sub_instance;
+}
+
+Rect2 BakedLightmapData::get_user_lightmap_uv_scale(int p_user) const {
+
+ ERR_FAIL_INDEX_V(p_user, users.size(), Rect2());
+ return users[p_user].uv_scale;
}
-int BakedLightmapData::get_user_instance(int p_user) const {
+int BakedLightmapData::get_user_lightmap_slice_index(int p_user) const {
ERR_FAIL_INDEX_V(p_user, users.size(), -1);
- return users[p_user].instance_index;
+ return users[p_user].slice_index;
}
void BakedLightmapData::clear_users() {
@@ -124,10 +84,10 @@ void BakedLightmapData::clear_users() {
void BakedLightmapData::_set_user_data(const Array &p_data) {
- ERR_FAIL_COND((p_data.size() % 3) != 0);
+ ERR_FAIL_COND((p_data.size() % 4) != 0);
- for (int i = 0; i < p_data.size(); i += 3) {
- add_user(p_data[i], p_data[i + 1], p_data[i + 2]);
+ for (int i = 0; i < p_data.size(); i += 4) {
+ add_user(p_data[i + 0], p_data[i + 1], p_data[i + 2], p_data[i + 3]);
}
}
@@ -136,522 +96,1132 @@ Array BakedLightmapData::_get_user_data() const {
Array ret;
for (int i = 0; i < users.size(); i++) {
ret.push_back(users[i].path);
- ret.push_back(users[i].lightmap);
- ret.push_back(users[i].instance_index);
+ ret.push_back(users[i].uv_scale);
+ ret.push_back(users[i].slice_index);
+ ret.push_back(users[i].sub_instance);
}
return ret;
}
RID BakedLightmapData::get_rid() const {
- return baked_light;
+ return lightmap;
}
-void BakedLightmapData::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_set_user_data", "data"), &BakedLightmapData::_set_user_data);
- ClassDB::bind_method(D_METHOD("_get_user_data"), &BakedLightmapData::_get_user_data);
+void BakedLightmapData::clear() {
+ users.clear();
+}
- ClassDB::bind_method(D_METHOD("set_bounds", "bounds"), &BakedLightmapData::set_bounds);
- ClassDB::bind_method(D_METHOD("get_bounds"), &BakedLightmapData::get_bounds);
+void BakedLightmapData::set_light_texture(const Ref<TextureLayered> &p_light_texture) {
+ light_texture = p_light_texture;
+ RS::get_singleton()->lightmap_set_textures(lightmap, light_texture.is_valid() ? light_texture->get_rid() : RID(), uses_spherical_harmonics);
+}
- ClassDB::bind_method(D_METHOD("set_cell_space_transform", "xform"), &BakedLightmapData::set_cell_space_transform);
- ClassDB::bind_method(D_METHOD("get_cell_space_transform"), &BakedLightmapData::get_cell_space_transform);
+Ref<TextureLayered> BakedLightmapData::get_light_texture() const {
+ return light_texture;
+}
- ClassDB::bind_method(D_METHOD("set_cell_subdiv", "cell_subdiv"), &BakedLightmapData::set_cell_subdiv);
- ClassDB::bind_method(D_METHOD("get_cell_subdiv"), &BakedLightmapData::get_cell_subdiv);
+void BakedLightmapData::set_uses_spherical_harmonics(bool p_enable) {
+ uses_spherical_harmonics = p_enable;
+ RS::get_singleton()->lightmap_set_textures(lightmap, light_texture.is_valid() ? light_texture->get_rid() : RID(), uses_spherical_harmonics);
+}
- ClassDB::bind_method(D_METHOD("set_octree", "octree"), &BakedLightmapData::set_octree);
- ClassDB::bind_method(D_METHOD("get_octree"), &BakedLightmapData::get_octree);
+bool BakedLightmapData::is_using_spherical_harmonics() const {
+ return uses_spherical_harmonics;
+}
- ClassDB::bind_method(D_METHOD("set_energy", "energy"), &BakedLightmapData::set_energy);
- ClassDB::bind_method(D_METHOD("get_energy"), &BakedLightmapData::get_energy);
+void BakedLightmapData::set_capture_data(const AABB &p_bounds, bool p_interior, const PackedVector3Array &p_points, const PackedColorArray &p_point_sh, const PackedInt32Array &p_tetrahedra, const PackedInt32Array &p_bsp_tree) {
+ if (p_points.size()) {
+ int pc = p_points.size();
+ ERR_FAIL_COND(pc * 9 != p_point_sh.size());
+ ERR_FAIL_COND((p_tetrahedra.size() % 4) != 0);
+ ERR_FAIL_COND((p_bsp_tree.size() % 6) != 0);
+ RS::get_singleton()->lightmap_set_probe_capture_data(lightmap, p_points, p_point_sh, p_tetrahedra, p_bsp_tree);
+ RS::get_singleton()->lightmap_set_probe_bounds(lightmap, p_bounds);
+ RS::get_singleton()->lightmap_set_probe_interior(lightmap, p_interior);
+ } else {
+ RS::get_singleton()->lightmap_set_probe_capture_data(lightmap, PackedVector3Array(), PackedColorArray(), PackedInt32Array(), PackedInt32Array());
+ RS::get_singleton()->lightmap_set_probe_bounds(lightmap, AABB());
+ RS::get_singleton()->lightmap_set_probe_interior(lightmap, false);
+ }
+ interior = p_interior;
+ bounds = p_bounds;
+}
- ClassDB::bind_method(D_METHOD("add_user", "path", "lightmap", "instance"), &BakedLightmapData::add_user);
- ClassDB::bind_method(D_METHOD("get_user_count"), &BakedLightmapData::get_user_count);
- ClassDB::bind_method(D_METHOD("get_user_path", "user_idx"), &BakedLightmapData::get_user_path);
- ClassDB::bind_method(D_METHOD("get_user_lightmap", "user_idx"), &BakedLightmapData::get_user_lightmap);
- ClassDB::bind_method(D_METHOD("clear_users"), &BakedLightmapData::clear_users);
+PackedVector3Array BakedLightmapData::get_capture_points() const {
+ return RS::get_singleton()->lightmap_get_probe_capture_points(lightmap);
+}
+PackedColorArray BakedLightmapData::get_capture_sh() const {
+ return RS::get_singleton()->lightmap_get_probe_capture_sh(lightmap);
+}
+PackedInt32Array BakedLightmapData::get_capture_tetrahedra() const {
+ return RS::get_singleton()->lightmap_get_probe_capture_tetrahedra(lightmap);
+}
- ADD_PROPERTY(PropertyInfo(Variant::AABB, "bounds", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_bounds", "get_bounds");
- ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "cell_space_transform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_cell_space_transform", "get_cell_space_transform");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_subdiv", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_cell_subdiv", "get_cell_subdiv");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "energy", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_energy", "get_energy");
- ADD_PROPERTY(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "octree", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_octree", "get_octree");
- ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "user_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_user_data", "_get_user_data");
+PackedInt32Array BakedLightmapData::get_capture_bsp_tree() const {
+ return RS::get_singleton()->lightmap_get_probe_capture_bsp_tree(lightmap);
}
-BakedLightmapData::BakedLightmapData() {
+AABB BakedLightmapData::get_capture_bounds() const {
+ return bounds;
+}
- baked_light = RS::get_singleton()->lightmap_capture_create();
- energy = 1;
- cell_subdiv = 1;
+bool BakedLightmapData::is_interior() const {
+ return interior;
}
-BakedLightmapData::~BakedLightmapData() {
+void BakedLightmapData::_set_probe_data(const Dictionary &p_data) {
+ ERR_FAIL_COND(!p_data.has("bounds"));
+ ERR_FAIL_COND(!p_data.has("points"));
+ ERR_FAIL_COND(!p_data.has("tetrahedra"));
+ ERR_FAIL_COND(!p_data.has("bsp"));
+ ERR_FAIL_COND(!p_data.has("sh"));
+ ERR_FAIL_COND(!p_data.has("interior"));
+ set_capture_data(p_data["bounds"], p_data["interior"], p_data["points"], p_data["sh"], p_data["tetrahedra"], p_data["bsp"]);
+}
- RS::get_singleton()->free(baked_light);
+Dictionary BakedLightmapData::_get_probe_data() const {
+ Dictionary d;
+ d["bounds"] = get_capture_bounds();
+ d["points"] = get_capture_points();
+ d["tetrahedra"] = get_capture_tetrahedra();
+ d["bsp"] = get_capture_bsp_tree();
+ d["sh"] = get_capture_sh();
+ d["interior"] = is_interior();
+ return d;
}
+void BakedLightmapData::_bind_methods() {
-///////////////////////////
+ ClassDB::bind_method(D_METHOD("_set_user_data", "data"), &BakedLightmapData::_set_user_data);
+ ClassDB::bind_method(D_METHOD("_get_user_data"), &BakedLightmapData::_get_user_data);
-BakedLightmap::BakeBeginFunc BakedLightmap::bake_begin_function = nullptr;
-BakedLightmap::BakeStepFunc BakedLightmap::bake_step_function = nullptr;
-BakedLightmap::BakeEndFunc BakedLightmap::bake_end_function = nullptr;
+ ClassDB::bind_method(D_METHOD("set_light_texture", "light_texture"), &BakedLightmapData::set_light_texture);
+ ClassDB::bind_method(D_METHOD("get_light_texture"), &BakedLightmapData::get_light_texture);
-void BakedLightmap::set_bake_cell_size(float p_cell_size) {
- bake_cell_size = p_cell_size;
-}
+ ClassDB::bind_method(D_METHOD("set_uses_spherical_harmonics", "uses_spherical_harmonics"), &BakedLightmapData::set_uses_spherical_harmonics);
+ ClassDB::bind_method(D_METHOD("is_using_spherical_harmonics"), &BakedLightmapData::is_using_spherical_harmonics);
-float BakedLightmap::get_bake_cell_size() const {
- return bake_cell_size;
-}
+ ClassDB::bind_method(D_METHOD("add_user", "path", "lightmap", "offset"), &BakedLightmapData::add_user);
+ ClassDB::bind_method(D_METHOD("get_user_count"), &BakedLightmapData::get_user_count);
+ ClassDB::bind_method(D_METHOD("get_user_path", "user_idx"), &BakedLightmapData::get_user_path);
+ ClassDB::bind_method(D_METHOD("clear_users"), &BakedLightmapData::clear_users);
-void BakedLightmap::set_capture_cell_size(float p_cell_size) {
- capture_cell_size = p_cell_size;
-}
+ ClassDB::bind_method(D_METHOD("_set_probe_data", "data"), &BakedLightmapData::_set_probe_data);
+ ClassDB::bind_method(D_METHOD("_get_probe_data"), &BakedLightmapData::_get_probe_data);
-float BakedLightmap::get_capture_cell_size() const {
- return capture_cell_size;
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "light_texture", PROPERTY_HINT_RESOURCE_TYPE, "TextureLayered"), "set_light_texture", "get_light_texture");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "uses_spherical_harmonics", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "set_uses_spherical_harmonics", "is_using_spherical_harmonics");
+ ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "user_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_user_data", "_get_user_data");
+ ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "probe_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_probe_data", "_get_probe_data");
}
-void BakedLightmap::set_extents(const Vector3 &p_extents) {
- extents = p_extents;
- update_gizmo();
- _change_notify("bake_extents");
-}
+BakedLightmapData::BakedLightmapData() {
-Vector3 BakedLightmap::get_extents() const {
- return extents;
+ lightmap = RS::get_singleton()->lightmap_create();
}
-void BakedLightmap::set_bake_default_texels_per_unit(const float &p_bake_texels_per_unit) {
- bake_default_texels_per_unit = p_bake_texels_per_unit;
- update_gizmo();
-}
+BakedLightmapData::~BakedLightmapData() {
-float BakedLightmap::get_bake_default_texels_per_unit() const {
- return bake_default_texels_per_unit;
+ RS::get_singleton()->free(lightmap);
}
-void BakedLightmap::_find_meshes_and_lights(Node *p_at_node, List<PlotMesh> &plot_meshes, List<PlotLight> &plot_lights) {
+///////////////////////////
+
+void BakedLightmap::_find_meshes_and_lights(Node *p_at_node, Vector<MeshesFound> &meshes, Vector<LightsFound> &lights, Vector<Vector3> &probes) {
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_at_node);
- if (mi && mi->get_flag(GeometryInstance::FLAG_USE_BAKED_LIGHT) && mi->is_visible_in_tree()) {
+ MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_at_node);
+ if (mi && mi->get_gi_mode() == GeometryInstance3D::GI_MODE_BAKED && mi->is_visible_in_tree()) {
Ref<Mesh> mesh = mi->get_mesh();
if (mesh.is_valid()) {
- bool all_have_uv2 = true;
+ bool all_have_uv2_and_normal = true;
+ bool surfaces_found = false;
for (int i = 0; i < mesh->get_surface_count(); i++) {
+
+ if (mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) {
+ continue;
+ }
if (!(mesh->surface_get_format(i) & Mesh::ARRAY_FORMAT_TEX_UV2)) {
- all_have_uv2 = false;
+ all_have_uv2_and_normal = false;
break;
}
+ if (!(mesh->surface_get_format(i) & Mesh::ARRAY_FORMAT_NORMAL)) {
+ all_have_uv2_and_normal = false;
+ break;
+ }
+ surfaces_found = true;
}
- if (all_have_uv2) {
+ if (surfaces_found && all_have_uv2_and_normal) {
//READY TO BAKE! size hint could be computed if not found, actually..
- AABB aabb = mesh->get_aabb();
-
- Transform xf = get_global_transform().affine_inverse() * mi->get_global_transform();
-
- if (AABB(-extents, extents * 2).intersects(xf.xform(aabb))) {
- PlotMesh pm;
- pm.local_xform = xf;
- pm.mesh = mesh;
- pm.path = get_path_to(mi);
- pm.instance_idx = -1;
- for (int i = 0; i < mesh->get_surface_count(); i++) {
- pm.instance_materials.push_back(mi->get_surface_material(i));
+ MeshesFound mf;
+ mf.xform = get_global_transform().affine_inverse() * mi->get_global_transform();
+ mf.node_path = get_path_to(mi);
+ mf.subindex = -1;
+ mf.mesh = mesh;
+
+ static const int lightmap_scale[GeometryInstance3D::LIGHTMAP_SCALE_MAX] = { 1, 2, 4, 8 };
+ mf.lightmap_scale = lightmap_scale[mi->get_lightmap_scale()];
+
+ Ref<Material> all_override = mi->get_material_override();
+ for (int i = 0; i < mesh->get_surface_count(); i++) {
+ if (all_override.is_valid()) {
+ mf.overrides.push_back(all_override);
+ } else {
+ mf.overrides.push_back(mi->get_surface_material(i));
}
- pm.override_material = mi->get_material_override();
- plot_meshes.push_back(pm);
}
+
+ meshes.push_back(mf);
}
}
}
- Spatial *s = Object::cast_to<Spatial>(p_at_node);
+ Node3D *s = Object::cast_to<Node3D>(p_at_node);
if (!mi && s) {
- Array meshes = p_at_node->call("get_bake_meshes");
- if (meshes.size() && (meshes.size() & 1) == 0) {
+ Array bmeshes = p_at_node->call("get_bake_bmeshes");
+ if (bmeshes.size() && (bmeshes.size() & 1) == 0) {
Transform xf = get_global_transform().affine_inverse() * s->get_global_transform();
- for (int i = 0; i < meshes.size(); i += 2) {
- PlotMesh pm;
- Transform mesh_xf = meshes[i + 1];
- pm.local_xform = xf * mesh_xf;
- pm.mesh = meshes[i];
- pm.instance_idx = i / 2;
- if (!pm.mesh.is_valid())
+ for (int i = 0; i < bmeshes.size(); i += 2) {
+
+ Ref<Mesh> mesh = bmeshes[i];
+ if (!mesh.is_valid())
continue;
- pm.path = get_path_to(s);
- plot_meshes.push_back(pm);
+
+ MeshesFound mf;
+
+ Transform mesh_xf = bmeshes[i + 1];
+ mf.xform = xf * mesh_xf;
+ mf.node_path = get_path_to(s);
+ mf.subindex = i / 2;
+ mf.lightmap_scale = 1;
+ mf.mesh = mesh;
+
+ meshes.push_back(mf);
}
}
}
- Light *light = Object::cast_to<Light>(p_at_node);
+ Light3D *light = Object::cast_to<Light3D>(p_at_node);
+
+ if (light && light->get_bake_mode() != Light3D::BAKE_DISABLED) {
+
+ LightsFound lf;
+ lf.xform = get_global_transform().affine_inverse() * light->get_global_transform();
+ lf.light = light;
+ lights.push_back(lf);
+ }
- if (light && light->get_bake_mode() != Light::BAKE_DISABLED) {
- PlotLight pl;
- Transform xf = get_global_transform().affine_inverse() * light->get_global_transform();
+ LightmapProbe *probe = Object::cast_to<LightmapProbe>(p_at_node);
- pl.local_xform = xf;
- pl.light = light;
- plot_lights.push_back(pl);
+ if (probe) {
+ Transform xf = get_global_transform().affine_inverse() * probe->get_global_transform();
+ probes.push_back(xf.origin);
}
+
for (int i = 0; i < p_at_node->get_child_count(); i++) {
Node *child = p_at_node->get_child(i);
if (!child->get_owner())
continue; //maybe a helper
- _find_meshes_and_lights(child, plot_meshes, plot_lights);
+ _find_meshes_and_lights(child, meshes, lights, probes);
}
}
-void BakedLightmap::set_hdr(bool p_enable) {
- hdr = p_enable;
-}
+int BakedLightmap::_bsp_get_simplex_side(const Vector<Vector3> &p_points, const LocalVector<BSPSimplex> &p_simplices, const Plane &p_plane, uint32_t p_simplex) const {
+
+ int over = 0;
+ int under = 0;
+ int coplanar = 0;
+ const BSPSimplex &s = p_simplices[p_simplex];
+ for (int i = 0; i < 4; i++) {
+ const Vector3 v = p_points[s.vertices[i]];
+ if (p_plane.has_point(v)) { //coplanar
+ coplanar++;
+ } else if (p_plane.is_point_over(v)) {
+ over++;
+ } else {
+ under++;
+ }
+ }
-bool BakedLightmap::is_hdr() const {
- return hdr;
+ ERR_FAIL_COND_V(under == 0 && over == 0, -2); //should never happen, we discarded flat simplices before, but in any case drop it from the bsp tree and throw an error
+ if (under == 0) {
+ return 1; // all over
+ } else if (over == 0) {
+ return -1; // all under
+ } else {
+ return 0; // crossing
+ }
}
-bool BakedLightmap::_bake_time(void *ud, float p_secs, float p_progress) {
+//#define DEBUG_BSP
- uint64_t time = OS::get_singleton()->get_ticks_usec();
- BakeTimeData *btd = (BakeTimeData *)ud;
+int32_t BakedLightmap::_compute_bsp_tree(const Vector<Vector3> &p_points, const LocalVector<Plane> &p_planes, LocalVector<int32_t> &planes_tested, const LocalVector<BSPSimplex> &p_simplices, const LocalVector<int32_t> &p_simplex_indices, LocalVector<BSPNode> &bsp_nodes) {
- if (time - btd->last_step > 1000000) {
+ //if we reach here, it means there is more than one simplex
+ int32_t node_index = (int32_t)bsp_nodes.size();
+ bsp_nodes.push_back(BSPNode());
- int mins_left = p_secs / 60;
- int secs_left = Math::fmod(p_secs, 60.0f);
- int percent = p_progress * 100;
- bool abort = bake_step_function(btd->pass + percent, btd->text + " " + vformat(RTR("%d%%"), percent) + " " + vformat(RTR("(Time Left: %d:%02d s)"), mins_left, secs_left));
- btd->last_step = time;
- if (abort)
- return true;
- }
+ //test with all the simplex planes
+ Plane best_plane;
+ float best_plane_score = -1.0;
- return false;
-}
+ for (uint32_t i = 0; i < p_simplex_indices.size(); i++) {
+ const BSPSimplex &s = p_simplices[p_simplex_indices[i]];
+ for (int j = 0; j < 4; j++) {
+ uint32_t plane_index = s.planes[j];
+ if (planes_tested[plane_index] == node_index) {
+ continue; //tested this plane already
+ }
+
+ planes_tested[plane_index] = node_index;
+
+ static const int face_order[4][3] = {
+ { 0, 1, 2 },
+ { 0, 2, 3 },
+ { 0, 1, 3 },
+ { 1, 2, 3 }
+ };
+
+ // despite getting rid of plane duplicates, we should still use here the actual plane to avoid numerical error
+ // from thinking this same simplex is intersecting rather than on a side
+ Vector3 v0 = p_points[s.vertices[face_order[j][0]]];
+ Vector3 v1 = p_points[s.vertices[face_order[j][1]]];
+ Vector3 v2 = p_points[s.vertices[face_order[j][2]]];
+
+ Plane plane(v0, v1, v2);
+
+ //test with all the simplices
+ int over_count = 0;
+ int under_count = 0;
+
+ for (uint32_t k = 0; k < p_simplex_indices.size(); k++) {
+ int side = _bsp_get_simplex_side(p_points, p_simplices, plane, p_simplex_indices[k]);
+ if (side == -2) {
+ continue; //this simplex is invalid, skip for now
+ } else if (side < 0) {
+ under_count++;
+ } else if (side > 0) {
+ over_count++;
+ }
+ }
+
+ if (under_count == 0 && over_count == 0) {
+ continue; //most likely precision issue with a flat simplex, do not try this plane
+ }
-BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, bool p_create_visual_debug) {
+ if (under_count > over_count) { //make sure under is always less than over, so we can compute the same ratio
+ SWAP(under_count, over_count);
+ }
- String save_path;
+ float score = 0; //by default, score is 0 (worst)
+ if (over_count > 0) {
+ //give score mainly based on ratio (under / over), this means that this plane is splitting simplices a lot, but its balanced
+ score = float(under_count) / over_count;
+ }
- if (image_path.begins_with("res://")) {
- save_path = image_path;
- } else {
- if (get_filename() != "") {
- save_path = get_filename().get_base_dir();
- } else if (get_owner() && get_owner()->get_filename() != "") {
- save_path = get_owner()->get_filename().get_base_dir();
+ //adjusting priority over least splits, probably not a great idea
+ //score *= Math::sqrt(float(over_count + under_count) / p_simplex_indices.size()); //also multiply score
+
+ if (score > best_plane_score) {
+
+ best_plane = plane;
+ best_plane_score = score;
+ }
}
+ }
- if (save_path == "") {
- return BAKE_ERROR_NO_SAVE_PATH;
+ LocalVector<int32_t> indices_over;
+ LocalVector<int32_t> indices_under;
+
+ //split again, but add to list
+ for (uint32_t i = 0; i < p_simplex_indices.size(); i++) {
+
+ uint32_t index = p_simplex_indices[i];
+ int side = _bsp_get_simplex_side(p_points, p_simplices, best_plane, index);
+
+ if (side == -2) {
+ continue; //simplex sits on the plane, does not make sense to use it
}
- if (image_path != "") {
- save_path.plus_file(image_path);
+ if (side <= 0) {
+ indices_under.push_back(index);
}
- }
- {
- //check for valid save path
- DirAccessRef d = DirAccess::open(save_path);
- if (!d) {
- ERR_PRINT("Invalid Save Path '" + save_path + "'.");
- return BAKE_ERROR_NO_SAVE_PATH;
+
+ if (side >= 0) {
+ indices_over.push_back(index);
}
}
- Ref<BakedLightmapData> new_light_data;
- new_light_data.instance();
+#ifdef DEBUG_BSP
+ print_line("node " + itos(node_index) + " found plane: " + best_plane + " score:" + rtos(best_plane_score) + " - over " + itos(indices_over.size()) + " under " + itos(indices_under.size()) + " intersecting " + itos(intersecting));
+#endif
- Voxelizer baker;
+ if (best_plane_score < 0.0 || indices_over.size() == p_simplex_indices.size() || indices_under.size() == p_simplex_indices.size()) {
+ ERR_FAIL_COND_V(p_simplex_indices.size() <= 1, 0); //should not happen, this is a bug
- int bake_subdiv;
- int capture_subdiv;
- AABB bake_bounds;
- {
- bake_bounds = AABB(-extents, extents * 2.0);
- int subdiv = nearest_power_of_2_templated(int(bake_bounds.get_longest_axis_size() / bake_cell_size));
- bake_bounds.size[bake_bounds.get_longest_axis_index()] = subdiv * bake_cell_size;
- bake_subdiv = nearest_shift(subdiv) + 1;
+ // Failed to separate the tetrahedrons using planes
+ // this means Delaunay borked at some point.
+ // Luckily, because we are using tetrahedrons, we can resort to
+ // less precise but still working ways to generate the separating plane
+ // this will most likely look bad when interpolating, but at least it will not crash.
+ // and the arctifact will most likely also be very small, so too difficult to notice.
+
+ //find the longest axis
+
+ WARN_PRINT("Inconsistency found in triangulation while building BSP, probe interpolation quality may degrade a bit.");
+
+ LocalVector<Vector3> centers;
+ AABB bounds_all;
+ for (uint32_t i = 0; i < p_simplex_indices.size(); i++) {
+ AABB bounds;
+ for (uint32_t j = 0; j < 4; j++) {
+
+ Vector3 p = p_points[p_simplices[p_simplex_indices[i]].vertices[j]];
+ if (j == 0) {
+ bounds.position = p;
+ } else {
+ bounds.expand_to(p);
+ }
+ }
+ if (i == 0) {
+ centers.push_back(bounds.position + bounds.size * 0.5);
+ } else {
+ bounds_all.merge_with(bounds);
+ }
+ }
+ Vector3::Axis longest_axis = Vector3::Axis(bounds_all.get_longest_axis_index());
+
+ //find the simplex that will go under
+ uint32_t min_d_idx = 0xFFFFFFFF;
+ float min_d_dist = 1e20;
+
+ for (uint32_t i = 0; i < centers.size(); i++) {
+ if (centers[i][longest_axis] < min_d_dist) {
+ min_d_idx = i;
+ min_d_dist = centers[i][longest_axis];
+ }
+ }
+ //rebuild best_plane and over/under arrays
+ best_plane = Plane();
+ best_plane.normal[longest_axis] = 1.0;
+ best_plane.d = min_d_dist;
+
+ indices_under.clear();
+ indices_under.push_back(min_d_idx);
- capture_subdiv = bake_subdiv;
- float css = bake_cell_size;
- while (css < capture_cell_size && capture_subdiv > 2) {
- capture_subdiv--;
- css *= 2.0;
+ indices_over.clear();
+
+ for (uint32_t i = 0; i < p_simplex_indices.size(); i++) {
+ if (i == min_d_idx) {
+ continue;
+ }
+ indices_over.push_back(p_simplex_indices[i]);
}
}
- baker.begin_bake(bake_subdiv, bake_bounds);
+ BSPNode node;
+ node.plane = best_plane;
+
+ if (indices_under.size() == 0) {
+ //noting to do here
+ node.under = BSPNode::EMPTY_LEAF;
+ } else if (indices_under.size() == 1) {
+ node.under = -(indices_under[0] + 1);
+ } else {
+ node.under = _compute_bsp_tree(p_points, p_planes, planes_tested, p_simplices, indices_under, bsp_nodes);
+ }
+
+ if (indices_over.size() == 0) {
+ //noting to do here
+ node.over = BSPNode::EMPTY_LEAF;
+ } else if (indices_over.size() == 1) {
+ node.over = -(indices_over[0] + 1);
+ } else {
+ node.over = _compute_bsp_tree(p_points, p_planes, planes_tested, p_simplices, indices_over, bsp_nodes);
+ }
+
+ bsp_nodes[node_index] = node;
- List<PlotMesh> mesh_list;
- List<PlotLight> light_list;
+ return node_index;
+}
- _find_meshes_and_lights(p_from_node ? p_from_node : get_parent(), mesh_list, light_list);
+bool BakedLightmap::_lightmap_bake_step_function(float p_completion, const String &p_text, void *ud, bool p_refresh) {
- if (bake_begin_function) {
- bake_begin_function(mesh_list.size() + light_list.size() + 1 + mesh_list.size() * 100);
+ BakeStepUD *bsud = (BakeStepUD *)ud;
+ bool ret = false;
+ if (bsud->func) {
+ ret = bsud->func(bsud->from_percent + p_completion * (bsud->to_percent - bsud->from_percent), p_text, bsud->ud, p_refresh);
}
+ return ret;
+}
- int step = 0;
+void BakedLightmap::_plot_triangle_into_octree(GenProbesOctree *p_cell, float p_cell_size, const Vector3 *p_triangle) {
- int pmc = 0;
+ for (int i = 0; i < 8; i++) {
+ Vector3i pos = p_cell->offset;
+ uint32_t half_size = p_cell->size / 2;
+ if (i & 1) {
+ pos.x += half_size;
+ }
+ if (i & 2) {
+ pos.y += half_size;
+ }
+ if (i & 4) {
+ pos.z += half_size;
+ }
- for (List<PlotMesh>::Element *E = mesh_list.front(); E; E = E->next()) {
+ AABB subcell;
+ subcell.position = Vector3(pos) * p_cell_size;
+ subcell.size = Vector3(half_size, half_size, half_size) * p_cell_size;
- if (bake_step_function) {
- bake_step_function(step++, RTR("Plotting Meshes: ") + " (" + itos(pmc + 1) + "/" + itos(mesh_list.size()) + ")");
+ if (!Geometry::triangle_box_overlap(subcell.position + subcell.size * 0.5, subcell.size * 0.5, p_triangle))
+ continue;
+
+ if (p_cell->children[i] == nullptr) {
+ GenProbesOctree *child = memnew(GenProbesOctree);
+ child->offset = pos;
+ child->size = half_size;
+ p_cell->children[i] = child;
}
- pmc++;
- baker.plot_mesh(E->get().local_xform, E->get().mesh, E->get().instance_materials, E->get().override_material);
+ if (half_size > 1) {
+ //still levels missing
+ _plot_triangle_into_octree(p_cell->children[i], p_cell_size, p_triangle);
+ }
}
+}
+void BakedLightmap::_gen_new_positions_from_octree(const GenProbesOctree *p_cell, float p_cell_size, const Vector<Vector3> &probe_positions, LocalVector<Vector3> &new_probe_positions, HashMap<Vector3i, bool, Vector3iHash> &positions_used, const AABB &p_bounds) {
- pmc = 0;
- baker.begin_bake_light(Voxelizer::BakeQuality(bake_quality), Voxelizer::BakeMode(bake_mode), propagation, energy);
+ for (int i = 0; i < 8; i++) {
- for (List<PlotLight>::Element *E = light_list.front(); E; E = E->next()) {
+ Vector3i pos = p_cell->offset;
+ if (i & 1) {
+ pos.x += p_cell->size;
+ }
+ if (i & 2) {
+ pos.y += p_cell->size;
+ }
+ if (i & 4) {
+ pos.z += p_cell->size;
+ }
- if (bake_step_function) {
- bake_step_function(step++, RTR("Plotting Lights:") + " (" + itos(pmc + 1) + "/" + itos(light_list.size()) + ")");
+ if (p_cell->size == 1 && !positions_used.has(pos)) {
+ //new position to insert!
+ Vector3 real_pos = p_bounds.position + Vector3(pos) * p_cell_size;
+ //see if a user submitted probe is too close
+ int ppcount = probe_positions.size();
+ const Vector3 *pp = probe_positions.ptr();
+ bool exists = false;
+ for (int j = 0; j < ppcount; j++) {
+
+ if (pp[j].distance_to(real_pos) < CMP_EPSILON) {
+ exists = true;
+ break;
+ }
+ }
+
+ if (!exists) {
+ new_probe_positions.push_back(real_pos);
+ }
+
+ positions_used[pos] = true;
}
- pmc++;
- PlotLight pl = E->get();
- switch (pl.light->get_light_type()) {
- case RS::LIGHT_DIRECTIONAL: {
- baker.plot_light_directional(-pl.local_xform.basis.get_axis(2), pl.light->get_color(), pl.light->get_param(Light::PARAM_ENERGY), pl.light->get_param(Light::PARAM_INDIRECT_ENERGY), pl.light->get_bake_mode() == Light::BAKE_ALL);
- } break;
- case RS::LIGHT_OMNI: {
- baker.plot_light_omni(pl.local_xform.origin, pl.light->get_color(), pl.light->get_param(Light::PARAM_ENERGY), pl.light->get_param(Light::PARAM_INDIRECT_ENERGY), pl.light->get_param(Light::PARAM_RANGE), pl.light->get_param(Light::PARAM_ATTENUATION), pl.light->get_bake_mode() == Light::BAKE_ALL);
- } break;
- case RS::LIGHT_SPOT: {
- baker.plot_light_spot(pl.local_xform.origin, pl.local_xform.basis.get_axis(2), pl.light->get_color(), pl.light->get_param(Light::PARAM_ENERGY), pl.light->get_param(Light::PARAM_INDIRECT_ENERGY), pl.light->get_param(Light::PARAM_RANGE), pl.light->get_param(Light::PARAM_ATTENUATION), pl.light->get_param(Light::PARAM_SPOT_ANGLE), pl.light->get_param(Light::PARAM_SPOT_ATTENUATION), pl.light->get_bake_mode() == Light::BAKE_ALL);
+ if (p_cell->children[i] != nullptr) {
+ _gen_new_positions_from_octree(p_cell->children[i], p_cell_size, probe_positions, new_probe_positions, positions_used, p_bounds);
+ }
+ }
+}
+BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_image_data_path, Lightmapper::BakeStepFunc p_bake_step, void *p_bake_userdata) {
- } break;
+ if (p_image_data_path == "" && (get_light_data().is_null() || !get_light_data()->get_path().is_resource_file())) {
+ return BAKE_ERROR_NO_SAVE_PATH;
+ }
+
+ if (p_image_data_path == "") {
+
+ if (get_light_data().is_null()) {
+ return BAKE_ERROR_NO_SAVE_PATH;
+ }
+
+ p_image_data_path = get_light_data()->get_path();
+ if (!p_image_data_path.is_resource_file()) {
+ return BAKE_ERROR_NO_SAVE_PATH;
}
}
- /*if (bake_step_function) {
- bake_step_function(pmc++, RTR("Finishing Plot"));
- }*/
- baker.end_bake();
+ Ref<Lightmapper> lightmapper = Lightmapper::create();
+ ERR_FAIL_COND_V(lightmapper.is_null(), BAKE_ERROR_NO_LIGHTMAPPER);
- Set<String> used_mesh_names;
+ BakeStepUD bsud;
+ bsud.func = p_bake_step;
+ bsud.ud = p_bake_userdata;
+ bsud.from_percent = 0.2;
+ bsud.to_percent = 0.8;
- pmc = 0;
- for (List<PlotMesh>::Element *E = mesh_list.front(); E; E = E->next()) {
+ if (p_bake_step) {
+ p_bake_step(0.0, TTR("Finding meshes, lights and probes"), p_bake_userdata, true);
+ }
+ /* STEP 1, FIND MESHES, LIGHTS AND PROBES */
+ Vector<Lightmapper::MeshData> mesh_data;
+ Vector<LightsFound> lights_found;
+ Vector<Vector3> probes_found;
+ AABB bounds;
+ {
+ Vector<MeshesFound> meshes_found;
+ _find_meshes_and_lights(p_from_node ? p_from_node : get_parent(), meshes_found, lights_found, probes_found);
- String mesh_name = E->get().mesh->get_name();
- if (mesh_name == "" || mesh_name.find(":") != -1 || mesh_name.find("/") != -1) {
- mesh_name = "LightMap";
+ if (meshes_found.size() == 0) {
+ return BAKE_ERROR_NO_MESHES;
}
+ // create mesh data for insert
- if (used_mesh_names.has(mesh_name)) {
- int idx = 2;
- String base = mesh_name;
- while (true) {
- mesh_name = base + itos(idx);
- if (!used_mesh_names.has(mesh_name))
- break;
- idx++;
+ //get the base material textures, help compute altlas size and bounds
+ for (int m_i = 0; m_i < meshes_found.size(); m_i++) {
+
+ if (p_bake_step) {
+ float p = (float)(m_i) / meshes_found.size();
+ p_bake_step(p * 0.1, vformat(TTR("Preparing geometry %d/%d"), m_i, meshes_found.size()), p_bake_userdata, false);
}
- }
- used_mesh_names.insert(mesh_name);
- pmc++;
- Voxelizer::LightMapData lm;
+ MeshesFound &mf = meshes_found.write[m_i];
- Error err;
- if (bake_step_function) {
- BakeTimeData btd;
- btd.text = RTR("Lighting Meshes: ") + mesh_name + " (" + itos(pmc) + "/" + itos(mesh_list.size()) + ")";
- btd.pass = step;
- btd.last_step = 0;
- err = baker.make_lightmap(E->get().local_xform, E->get().mesh, bake_default_texels_per_unit, lm, _bake_time, &btd);
- if (err != OK) {
- bake_end_function();
- if (err == ERR_SKIP)
- return BAKE_ERROR_USER_ABORTED;
- return BAKE_ERROR_CANT_CREATE_IMAGE;
+ Size2i lightmap_size = mf.mesh->get_lightmap_size_hint() * mf.lightmap_scale;
+ Vector<RID> overrides;
+ overrides.resize(mf.overrides.size());
+ for (int i = 0; i < mf.overrides.size(); i++) {
+ if (mf.overrides[i].is_valid()) {
+ overrides.write[i] = mf.overrides[i]->get_rid();
+ }
}
- step += 100;
- } else {
+ TypedArray<Image> images = RS::get_singleton()->bake_render_uv2(mf.mesh->get_rid(), overrides, lightmap_size);
- err = baker.make_lightmap(E->get().local_xform, E->get().mesh, bake_default_texels_per_unit, lm);
- }
+ ERR_FAIL_COND_V(images.empty(), BAKE_ERROR_CANT_CREATE_IMAGE);
+
+ Ref<Image> albedo = images[RS::BAKE_CHANNEL_ALBEDO_ALPHA];
+ Ref<Image> orm = images[RS::BAKE_CHANNEL_ORM];
- if (err == OK) {
+ //multiply albedo by metal
- Ref<Image> image;
- image.instance();
+ Lightmapper::MeshData md;
- if (hdr) {
+ {
+ Dictionary d;
+ d["path"] = mf.node_path;
+ if (mf.subindex >= 0) {
+ d["subindex"] = mf.subindex;
+ }
+ md.userdata = d;
+ }
- //just save a regular image
- Vector<uint8_t> data;
- int s = lm.light.size();
- data.resize(lm.light.size() * 2);
- {
+ {
- uint8_t* w = data.ptrw();
- const float* r = lm.light.ptr();
- uint16_t *hfw = (uint16_t *)w.ptr();
- for (int i = 0; i < s; i++) {
- hfw[i] = Math::make_half_float(r[i]);
- }
+ if (albedo->get_format() != Image::FORMAT_RGBA8) {
+ albedo->convert(Image::FORMAT_RGBA8);
+ }
+ if (orm->get_format() != Image::FORMAT_RGBA8) {
+ orm->convert(Image::FORMAT_RGBA8);
+ }
+ Vector<uint8_t> albedo_alpha = albedo->get_data();
+ Vector<uint8_t> orm_data = orm->get_data();
+
+ Vector<uint8_t> albedom;
+ uint32_t len = albedo_alpha.size();
+ albedom.resize(len);
+ const uint8_t *r_aa = albedo_alpha.ptr();
+ const uint8_t *r_orm = orm_data.ptr();
+ uint8_t *w_albedo = albedom.ptrw();
+
+ for (uint32_t i = 0; i < len; i += 4) {
+ w_albedo[i + 0] = uint8_t(CLAMP(float(r_aa[i + 0]) * (1.0 - float(r_orm[i + 2] / 255.0)), 0, 255));
+ w_albedo[i + 1] = uint8_t(CLAMP(float(r_aa[i + 1]) * (1.0 - float(r_orm[i + 2] / 255.0)), 0, 255));
+ w_albedo[i + 2] = uint8_t(CLAMP(float(r_aa[i + 2]) * (1.0 - float(r_orm[i + 2] / 255.0)), 0, 255));
+ w_albedo[i + 3] = 255;
}
- image->create(lm.width, lm.height, false, Image::FORMAT_RGBH, data);
+ md.albedo_on_uv2.instance();
+ md.albedo_on_uv2->create(lightmap_size.width, lightmap_size.height, false, Image::FORMAT_RGBA8, albedom);
+ }
- } else {
+ md.emission_on_uv2 = images[RS::BAKE_CHANNEL_EMISSION];
+ if (md.emission_on_uv2->get_format() != Image::FORMAT_RGBAH) {
+ md.emission_on_uv2->convert(Image::FORMAT_RGBAH);
+ }
- //just save a regular image
- Vector<uint8_t> data;
- int s = lm.light.size();
- data.resize(lm.light.size());
- {
-
- uint8_t* w = data.ptrw();
- const float* r = lm.light.ptr();
- for (int i = 0; i < s; i += 3) {
- Color c(r[i + 0], r[i + 1], r[i + 2]);
- c = c.to_srgb();
- w[i + 0] = CLAMP(c.r * 255, 0, 255);
- w[i + 1] = CLAMP(c.g * 255, 0, 255);
- w[i + 2] = CLAMP(c.b * 255, 0, 255);
- }
+ //get geometry
+
+ Basis normal_xform = mf.xform.basis.inverse().transposed();
+
+ for (int i = 0; i < mf.mesh->get_surface_count(); i++) {
+ if (mf.mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) {
+ continue;
}
+ Array a = mf.mesh->surface_get_arrays(i);
- image->create(lm.width, lm.height, false, Image::FORMAT_RGB8, data);
+ Vector<Vector3> vertices = a[Mesh::ARRAY_VERTEX];
+ const Vector3 *vr = vertices.ptr();
+ Vector<Vector2> uv = a[Mesh::ARRAY_TEX_UV2];
+ const Vector2 *uvr = nullptr;
+ Vector<Vector3> normals = a[Mesh::ARRAY_NORMAL];
+ const Vector3 *nr = nullptr;
+ Vector<int> index = a[Mesh::ARRAY_INDEX];
- //This texture is saved to SRGB for two reasons:
- // 1) first is so it looks better when doing the LINEAR->SRGB conversion (more accurate)
- // 2) So it can be used in the GLES2 backend, which does not support linkear workflow
- }
+ ERR_CONTINUE(uv.size() == 0);
+ ERR_CONTINUE(normals.size() == 0);
- String image_path = save_path.plus_file(mesh_name);
- Ref<Texture2D> texture;
+ uvr = uv.ptr();
+ nr = normals.ptr();
- if (ResourceLoader::import) {
+ int facecount;
+ const int *ir = nullptr;
- bool srgb = false;
- if (false && hdr) {
- //save hdr
+ if (index.size()) {
+
+ facecount = index.size() / 3;
+ ir = index.ptr();
} else {
- image_path += ".png";
- print_line("image path saving png: " + image_path);
- image->save_png(image_path);
- srgb = true;
+ facecount = vertices.size() / 3;
}
- if (!FileAccess::exists(image_path + ".import")) {
- Ref<ConfigFile> config;
- config.instance();
- config->set_value("remap", "importer", "texture");
- config->set_value("remap", "type", "StreamTexture");
- config->set_value("params", "compress/mode", 2);
- config->set_value("params", "detect_3d", false);
- config->set_value("params", "flags/repeat", false);
- config->set_value("params", "flags/filter", true);
- config->set_value("params", "flags/mipmaps", false);
- config->set_value("params", "flags/srgb", srgb);
-
- config->save(image_path + ".import");
- }
+ for (int j = 0; j < facecount; j++) {
- ResourceLoader::import(image_path);
- texture = ResourceLoader::load(image_path); //if already loaded, it will be updated on refocus?
- } else {
+ uint32_t vidx[3];
- image_path += ".text";
- Ref<ImageTexture> tex;
- bool set_path = true;
- if (ResourceCache::has(image_path)) {
- tex = Ref<Resource>((Resource *)ResourceCache::get(image_path));
- set_path = false;
- }
+ if (ir) {
+ for (int k = 0; k < 3; k++) {
+ vidx[k] = ir[j * 3 + k];
+ }
+ } else {
+ for (int k = 0; k < 3; k++) {
+ vidx[k] = j * 3 + k;
+ }
+ }
- if (!tex.is_valid()) {
- tex.instance();
+ for (int k = 0; k < 3; k++) {
+ Vector3 v = mf.xform.xform(vr[vidx[k]]);
+ if (bounds == AABB()) {
+ bounds.position = v;
+ } else {
+ bounds.expand_to(v);
+ }
+ md.points.push_back(v);
+
+ md.uv2.push_back(uvr[vidx[k]]);
+ md.normal.push_back(normal_xform.xform(nr[vidx[k]]).normalized());
+ }
}
+ }
- tex->create_from_image(image);
+ mesh_data.push_back(md);
+ }
+ }
- err = ResourceSaver::save(image_path, tex, ResourceSaver::FLAG_CHANGE_PATH);
- if (set_path) {
- tex->set_path(image_path);
- }
- texture = tex;
+ /* STEP 2, CREATE PROBES */
+
+ if (p_bake_step) {
+ p_bake_step(0.3, TTR("Creating probes"), p_bake_userdata, true);
+ }
+
+ //bounds need to include the user probes
+ for (int i = 0; i < probes_found.size(); i++) {
+ bounds.expand_to(probes_found[i]);
+ }
+
+ bounds.grow_by(bounds.size.length() * 0.001);
+
+ if (gen_probes == GENERATE_PROBES_DISABLED) {
+ // generate 8 probes on bound endpoints
+ for (int i = 0; i < 8; i++) {
+ probes_found.push_back(bounds.get_endpoint(i));
+ }
+ } else {
+ // detect probes from geometry
+ static const int subdiv_values[6] = { 0, 4, 8, 16, 32 };
+ int subdiv = subdiv_values[gen_probes];
+
+ float subdiv_cell_size;
+ Vector3i bound_limit;
+ {
+ int longest_axis = bounds.get_longest_axis_index();
+ subdiv_cell_size = bounds.size[longest_axis] / subdiv;
+ int axis_n1 = (longest_axis + 1) % 3;
+ int axis_n2 = (longest_axis + 2) % 3;
+
+ bound_limit[longest_axis] = subdiv;
+ bound_limit[axis_n1] = int(Math::ceil(bounds.size[axis_n1] / subdiv_cell_size));
+ bound_limit[axis_n2] = int(Math::ceil(bounds.size[axis_n2] / subdiv_cell_size));
+ //compensate bounds
+ bounds.size[axis_n1] = bound_limit[axis_n1] * subdiv_cell_size;
+ bounds.size[axis_n2] = bound_limit[axis_n2] * subdiv_cell_size;
+ }
+
+ GenProbesOctree octree;
+ octree.size = subdiv;
+
+ for (int i = 0; i < mesh_data.size(); i++) {
+ if (p_bake_step) {
+ float p = (float)(i) / mesh_data.size();
+ p_bake_step(0.3 + p * 0.1, vformat(TTR("Creating probes from mesh %d/%d"), i, mesh_data.size()), p_bake_userdata, false);
}
- if (err != OK) {
- if (bake_end_function) {
- bake_end_function();
- }
- ERR_FAIL_COND_V(err != OK, BAKE_ERROR_CANT_CREATE_IMAGE);
+
+ for (int j = 0; j < mesh_data[i].points.size(); j += 3) {
+ Vector3 points[3] = { mesh_data[i].points[j + 0] - bounds.position, mesh_data[i].points[j + 1] - bounds.position, mesh_data[i].points[j + 2] - bounds.position };
+ _plot_triangle_into_octree(&octree, subdiv_cell_size, points);
+ }
+ }
+
+ LocalVector<Vector3> new_probe_positions;
+ HashMap<Vector3i, bool, Vector3iHash> positions_used;
+ for (uint32_t i = 0; i < 8; i++) { //insert bounding endpoints
+ Vector3i pos;
+ if (i & 1) {
+ pos.x += bound_limit.x;
+ }
+ if (i & 2) {
+ pos.y += bound_limit.y;
+ }
+ if (i & 4) {
+ pos.z += bound_limit.z;
+ }
+
+ positions_used[pos] = true;
+ Vector3 real_pos = bounds.position + Vector3(pos) * subdiv_cell_size; //use same formula for numerical stability
+ new_probe_positions.push_back(real_pos);
+ }
+ //skip first level, since probes are always added at bounds endpoints anyway (code above this)
+ for (int i = 0; i < 8; i++) {
+
+ if (octree.children[i]) {
+ _gen_new_positions_from_octree(octree.children[i], subdiv_cell_size, probes_found, new_probe_positions, positions_used, bounds);
}
+ }
- new_light_data->add_user(E->get().path, texture, E->get().instance_idx);
+ for (uint32_t i = 0; i < new_probe_positions.size(); i++) {
+ probes_found.push_back(new_probe_positions[i]);
}
}
- AABB bounds = AABB(-extents, extents * 2);
- new_light_data->set_cell_subdiv(capture_subdiv);
- new_light_data->set_bounds(bounds);
- new_light_data->set_octree(baker.create_capture_octree(capture_subdiv));
+ // Add everything to lightmapper
+ if (p_bake_step) {
+ p_bake_step(0.4, TTR("Preparing Lightmapper"), p_bake_userdata, true);
+ }
+
{
- float bake_bound_size = bake_bounds.get_longest_axis_size();
- Transform to_bounds;
- to_bounds.basis.scale(Vector3(bake_bound_size, bake_bound_size, bake_bound_size));
- to_bounds.origin = bounds.position;
+ for (int i = 0; i < mesh_data.size(); i++) {
+ lightmapper->add_mesh(mesh_data[i]);
+ }
+ for (int i = 0; i < lights_found.size(); i++) {
+ Light3D *light = lights_found[i].light;
+ Transform xf = lights_found[i].xform;
+
+ if (Object::cast_to<DirectionalLight3D>(light)) {
+ DirectionalLight3D *l = Object::cast_to<DirectionalLight3D>(light);
+ lightmapper->add_directional_light(light->get_bake_mode() == Light3D::BAKE_ALL, -xf.basis.get_axis(Vector3::AXIS_Z).normalized(), l->get_color(), l->get_param(Light3D::PARAM_ENERGY), l->get_param(Light3D::PARAM_SIZE));
+ } else if (Object::cast_to<OmniLight3D>(light)) {
+ OmniLight3D *l = Object::cast_to<OmniLight3D>(light);
+ lightmapper->add_omni_light(light->get_bake_mode() == Light3D::BAKE_ALL, xf.origin, l->get_color(), l->get_param(Light3D::PARAM_ENERGY), l->get_param(Light3D::PARAM_RANGE), l->get_param(Light3D::PARAM_ATTENUATION), l->get_param(Light3D::PARAM_SIZE));
+ } else if (Object::cast_to<SpotLight3D>(light)) {
+ SpotLight3D *l = Object::cast_to<SpotLight3D>(light);
+ lightmapper->add_spot_light(light->get_bake_mode() == Light3D::BAKE_ALL, xf.origin, -xf.basis.get_axis(Vector3::AXIS_Z).normalized(), l->get_color(), l->get_param(Light3D::PARAM_ENERGY), l->get_param(Light3D::PARAM_RANGE), l->get_param(Light3D::PARAM_ATTENUATION), l->get_param(Light3D::PARAM_SPOT_ANGLE), l->get_param(Light3D::PARAM_SPOT_ATTENUATION), l->get_param(Light3D::PARAM_SIZE));
+ }
+ }
+ for (int i = 0; i < probes_found.size(); i++) {
+ lightmapper->add_probe(probes_found[i]);
+ }
+ }
+
+ Ref<Image> environment_image;
+ Basis environment_transform;
+
+ // Add everything to lightmapper
+ if (environment_mode != ENVIRONMENT_MODE_DISABLED) {
+ if (p_bake_step) {
+ p_bake_step(4.1, TTR("Preparing Environment"), p_bake_userdata, true);
+ }
+
+ environment_transform = get_global_transform().basis;
- Transform to_grid;
- to_grid.basis.scale(Vector3(1 << (capture_subdiv - 1), 1 << (capture_subdiv - 1), 1 << (capture_subdiv - 1)));
+ switch (environment_mode) {
+ case ENVIRONMENT_MODE_DISABLED: {
+ //nothing
+ } break;
+ case ENVIRONMENT_MODE_SCENE: {
+ Ref<World3D> world = get_world_3d();
+ if (world.is_valid()) {
+ Ref<Environment> env = world->get_environment();
+ if (env.is_null()) {
+ env = world->get_fallback_environment();
+ }
+
+ if (env.is_valid()) {
+ environment_image = RS::get_singleton()->environment_bake_panorama(env->get_rid(), true, Size2i(128, 64));
+ }
+ }
+ } break;
+ case ENVIRONMENT_MODE_CUSTOM_SKY: {
+ if (environment_custom_sky.is_valid()) {
+ environment_image = RS::get_singleton()->sky_bake_panorama(environment_custom_sky->get_rid(), environment_custom_energy, true, Size2i(128, 64));
+ }
+
+ } break;
+ case ENVIRONMENT_MODE_CUSTOM_COLOR: {
+ environment_image.instance();
+ environment_image->create(128, 64, false, Image::FORMAT_RGBAF);
+ Color c = environment_custom_color;
+ c.r *= environment_custom_energy;
+ c.g *= environment_custom_energy;
+ c.b *= environment_custom_energy;
+ for (int i = 0; i < 128; i++) {
+ for (int j = 0; j < 64; j++) {
+ environment_image->set_pixel(i, j, c);
+ }
+ }
- Transform to_cell_space = to_grid * to_bounds.affine_inverse();
- new_light_data->set_cell_space_transform(to_cell_space);
+ } break;
+ }
}
- if (bake_end_function) {
- bake_end_function();
+ Lightmapper::BakeError bake_err = lightmapper->bake(Lightmapper::BakeQuality(bake_quality), use_denoiser, bounces, bias, max_texture_size, directional, Lightmapper::GenerateProbes(gen_probes), environment_image, environment_transform, _lightmap_bake_step_function, &bsud);
+
+ if (bake_err == Lightmapper::BAKE_ERROR_LIGHTMAP_CANT_PRE_BAKE_MESHES) {
+ return BAKE_ERROR_MESHES_INVALID;
}
- //create the data for visual server
+ /* POSTBAKE: Save Textures */
- if (p_create_visual_debug) {
- MultiMeshInstance *mmi = memnew(MultiMeshInstance);
- mmi->set_multimesh(baker.create_debug_multimesh(Voxelizer::DEBUG_LIGHT));
- add_child(mmi);
-#ifdef TOOLS_ENABLED
- if (get_tree()->get_edited_scene_root() == this) {
- mmi->set_owner(this);
- } else {
- mmi->set_owner(get_owner());
+ Ref<TextureLayered> texture;
+ {
+
+ Vector<Ref<Image>> images;
+ for (int i = 0; i < lightmapper->get_bake_texture_count(); i++) {
+ images.push_back(lightmapper->get_bake_texture(i));
+ }
+ //we assume they are all the same, so lets create a large one for saving
+ Ref<Image> large_image;
+ large_image.instance();
+
+ large_image->create(images[0]->get_width(), images[0]->get_height() * images.size(), false, images[0]->get_format());
+
+ for (int i = 0; i < lightmapper->get_bake_texture_count(); i++) {
+ large_image->blit_rect(images[i], Rect2(0, 0, images[i]->get_width(), images[i]->get_height()), Point2(0, images[i]->get_height() * i));
+ }
+
+ String base_path = p_image_data_path.get_basename() + ".exr";
+
+ Ref<ConfigFile> config;
+
+ config.instance();
+ if (FileAccess::exists(base_path + ".import")) {
+
+ config->load(base_path + ".import");
+ }
+
+ config->set_value("remap", "importer", "2d_array_texture");
+ config->set_value("remap", "type", "StreamTexture2DArray");
+ if (!config->has_section_key("params", "compress/mode")) {
+ config->set_value("params", "compress/mode", 2); //user may want another compression, so leave it be
+ }
+ config->set_value("params", "compress/channel_pack", 1);
+ config->set_value("params", "mipmaps/generate", false);
+ config->set_value("params", "slices/horizontal", 1);
+ config->set_value("params", "slices/vertical", images.size());
+
+ config->save(base_path + ".import");
+
+ Error err = large_image->save_exr(base_path, false);
+ ERR_FAIL_COND_V(err, BAKE_ERROR_CANT_CREATE_IMAGE);
+ ResourceLoader::import(base_path);
+ Ref<Texture> t = ResourceLoader::load(base_path); //if already loaded, it will be updated on refocus?
+ ERR_FAIL_COND_V(t.is_null(), BAKE_ERROR_CANT_CREATE_IMAGE);
+ texture = t;
+ }
+
+ /* POSTBAKE: Save Light Data */
+
+ Ref<BakedLightmapData> data;
+ if (get_light_data().is_valid()) {
+ data = get_light_data();
+ set_light_data(Ref<BakedLightmapData>()); //clear
+ data->clear();
+ } else {
+ data.instance();
+ }
+
+ data->set_light_texture(texture);
+ data->set_uses_spherical_harmonics(directional);
+
+ for (int i = 0; i < lightmapper->get_bake_mesh_count(); i++) {
+ Dictionary d = lightmapper->get_bake_mesh_userdata(i);
+ NodePath np = d["path"];
+ int32_t subindex = -1;
+ if (d.has("subindex")) {
+ subindex = d["subindex"];
}
-#else
- mmi->set_owner(get_owner());
+
+ Rect2 uv_scale = lightmapper->get_bake_mesh_uv_scale(i);
+ int slice_index = lightmapper->get_bake_mesh_texture_slice(i);
+ data->add_user(np, uv_scale, slice_index, subindex);
+ }
+
+ {
+ // create tetrahedrons
+ Vector<Vector3> points;
+ Vector<Color> sh;
+ points.resize(lightmapper->get_bake_probe_count());
+ sh.resize(lightmapper->get_bake_probe_count() * 9);
+ for (int i = 0; i < lightmapper->get_bake_probe_count(); i++) {
+ points.write[i] = lightmapper->get_bake_probe_point(i);
+ Vector<Color> colors = lightmapper->get_bake_probe_sh(i);
+ ERR_CONTINUE(colors.size() != 9);
+ for (int j = 0; j < 9; j++) {
+ sh.write[i * 9 + j] = colors[j];
+ }
+ }
+
+ //Obtain solved simplices
+
+ if (p_bake_step) {
+ p_bake_step(0.8, TTR("Generating Probe Volumes"), p_bake_userdata, true);
+ }
+ Vector<Delaunay3D::OutputSimplex> solved_simplices = Delaunay3D::tetrahedralize(points);
+
+ LocalVector<BSPSimplex> bsp_simplices;
+ LocalVector<Plane> bsp_planes;
+ LocalVector<int32_t> bsp_simplex_indices;
+ PackedInt32Array tetrahedrons;
+
+ for (int i = 0; i < solved_simplices.size(); i++) {
+
+ //Prepare a special representation of the simplex, which uses a BSP Tree
+ BSPSimplex bsp_simplex;
+ for (int j = 0; j < 4; j++) {
+ bsp_simplex.vertices[j] = solved_simplices[i].points[j];
+ }
+ for (int j = 0; j < 4; j++) {
+ static const int face_order[4][3] = {
+ { 0, 1, 2 },
+ { 0, 2, 3 },
+ { 0, 1, 3 },
+ { 1, 2, 3 }
+ };
+ Vector3 a = points[solved_simplices[i].points[face_order[j][0]]];
+ Vector3 b = points[solved_simplices[i].points[face_order[j][1]]];
+ Vector3 c = points[solved_simplices[i].points[face_order[j][2]]];
+
+ //store planes in an array, but ensure they are reused, to speed up processing
+
+ Plane p(a, b, c);
+ int plane_index = -1;
+ for (uint32_t k = 0; k < bsp_planes.size(); k++) {
+
+ if (bsp_planes[k].is_equal_approx_any_side(p)) {
+ plane_index = k;
+ break;
+ }
+ }
+
+ if (plane_index == -1) {
+ plane_index = bsp_planes.size();
+ bsp_planes.push_back(p);
+ }
+
+ bsp_simplex.planes[j] = plane_index;
+
+ //also fill simplex array
+ tetrahedrons.push_back(solved_simplices[i].points[j]);
+ }
+
+ bsp_simplex_indices.push_back(bsp_simplices.size());
+ bsp_simplices.push_back(bsp_simplex);
+ }
+
+//#define DEBUG_SIMPLICES_AS_OBJ_FILE
+#ifdef DEBUG_SIMPLICES_AS_OBJ_FILE
+ {
+ FileAccessRef f = FileAccess::open("res://bsp.obj", FileAccess::WRITE);
+ for (uint32_t i = 0; i < bsp_simplices.size(); i++) {
+ f->store_line("o Simplex" + itos(i));
+ for (int j = 0; j < 4; j++) {
+ f->store_line(vformat("v %f %f %f", points[bsp_simplices[i].vertices[j]].x, points[bsp_simplices[i].vertices[j]].y, points[bsp_simplices[i].vertices[j]].z));
+ }
+ static const int face_order[4][3] = {
+ { 1, 2, 3 },
+ { 1, 3, 4 },
+ { 1, 2, 4 },
+ { 2, 3, 4 }
+ };
+
+ for (int j = 0; j < 4; j++) {
+ f->store_line(vformat("f %d %d %d", 4 * i + face_order[j][0], 4 * i + face_order[j][1], 4 * i + face_order[j][2]));
+ }
+ }
+ f->close();
+ }
+#endif
+
+ LocalVector<BSPNode> bsp_nodes;
+ LocalVector<int32_t> planes_tested;
+ planes_tested.resize(bsp_planes.size());
+ for (uint32_t i = 0; i < planes_tested.size(); i++) {
+ planes_tested[i] = 0x7FFFFFFF;
+ }
+
+ if (p_bake_step) {
+ p_bake_step(0.9, TTR("Generating Probe Acceleration Structures"), p_bake_userdata, true);
+ }
+
+ _compute_bsp_tree(points, bsp_planes, planes_tested, bsp_simplices, bsp_simplex_indices, bsp_nodes);
+
+ PackedInt32Array bsp_array;
+ bsp_array.resize(bsp_nodes.size() * 6); // six 32 bits values used for each BSP node
+ {
+ float *fptr = (float *)bsp_array.ptrw();
+ int32_t *iptr = (int32_t *)bsp_array.ptrw();
+ for (uint32_t i = 0; i < bsp_nodes.size(); i++) {
+ fptr[i * 6 + 0] = bsp_nodes[i].plane.normal.x;
+ fptr[i * 6 + 1] = bsp_nodes[i].plane.normal.y;
+ fptr[i * 6 + 2] = bsp_nodes[i].plane.normal.z;
+ fptr[i * 6 + 3] = bsp_nodes[i].plane.d;
+ iptr[i * 6 + 4] = bsp_nodes[i].over;
+ iptr[i * 6 + 5] = bsp_nodes[i].under;
+ }
+//#define DEBUG_BSP_TREE
+#ifdef DEBUG_BSP_TREE
+ FileAccessRef f = FileAccess::open("res://bsp.txt", FileAccess::WRITE);
+ for (uint32_t i = 0; i < bsp_nodes.size(); i++) {
+ f->store_line(itos(i) + " - plane: " + bsp_nodes[i].plane + " over: " + itos(bsp_nodes[i].over) + " under: " + itos(bsp_nodes[i].under));
+ }
#endif
+ }
+
+ /* Obtain the colors from the images, they will be re-created as cubemaps on the server, depending on the driver */
+
+ data->set_capture_data(bounds, interior, points, sh, tetrahedrons, bsp_array);
+ /* Compute a BSP tree of the simplices, so it's easy to find the exact one */
+ }
+
+ Error err = ResourceSaver::save(p_image_data_path, data);
+ data->set_path(p_image_data_path);
+
+ if (err != OK) {
+ return BAKE_ERROR_CANT_CREATE_IMAGE;
}
- set_light_data(new_light_data);
+ set_light_data(data);
return BAKE_ERROR_OK;
}
void BakedLightmap::_notification(int p_what) {
- if (p_what == NOTIFICATION_READY) {
+ if (p_what == NOTIFICATION_POST_ENTER_TREE) {
if (light_data.is_valid()) {
_assign_lightmaps();
}
- request_ready(); //will need ready again if re-enters tree
}
if (p_what == NOTIFICATION_EXIT_TREE) {
@@ -667,20 +1237,18 @@ void BakedLightmap::_assign_lightmaps() {
ERR_FAIL_COND(!light_data.is_valid());
for (int i = 0; i < light_data->get_user_count(); i++) {
- Ref<Texture2D> lightmap = light_data->get_user_lightmap(i);
- ERR_CONTINUE(!lightmap.is_valid());
Node *node = get_node(light_data->get_user_path(i));
- int instance_idx = light_data->get_user_instance(i);
+ int instance_idx = light_data->get_user_sub_instance(i);
if (instance_idx >= 0) {
RID instance = node->call("get_bake_mesh_instance", instance_idx);
if (instance.is_valid()) {
- RS::get_singleton()->instance_set_use_lightmap(instance, get_instance(), lightmap->get_rid());
+ RS::get_singleton()->instance_geometry_set_lightmap(instance, get_instance(), light_data->get_user_lightmap_uv_scale(i), light_data->get_user_lightmap_slice_index(i));
}
} else {
- VisualInstance *vi = Object::cast_to<VisualInstance>(node);
+ VisualInstance3D *vi = Object::cast_to<VisualInstance3D>(node);
ERR_CONTINUE(!vi);
- RS::get_singleton()->instance_set_use_lightmap(vi->get_instance(), get_instance(), lightmap->get_rid());
+ RS::get_singleton()->instance_geometry_set_lightmap(vi->get_instance(), get_instance(), light_data->get_user_lightmap_uv_scale(i), light_data->get_user_lightmap_slice_index(i));
}
}
}
@@ -689,16 +1257,16 @@ void BakedLightmap::_clear_lightmaps() {
ERR_FAIL_COND(!light_data.is_valid());
for (int i = 0; i < light_data->get_user_count(); i++) {
Node *node = get_node(light_data->get_user_path(i));
- int instance_idx = light_data->get_user_instance(i);
+ int instance_idx = light_data->get_user_sub_instance(i);
if (instance_idx >= 0) {
RID instance = node->call("get_bake_mesh_instance", instance_idx);
if (instance.is_valid()) {
- RS::get_singleton()->instance_set_use_lightmap(instance, get_instance(), RID());
+ RS::get_singleton()->instance_geometry_set_lightmap(instance, RID(), Rect2(), 0);
}
} else {
- VisualInstance *vi = Object::cast_to<VisualInstance>(node);
+ VisualInstance3D *vi = Object::cast_to<VisualInstance3D>(node);
ERR_CONTINUE(!vi);
- RS::get_singleton()->instance_set_use_lightmap(vi->get_instance(), get_instance(), RID());
+ RS::get_singleton()->instance_geometry_set_lightmap(vi->get_instance(), RID(), Rect2(), 0);
}
}
}
@@ -719,6 +1287,8 @@ void BakedLightmap::set_light_data(const Ref<BakedLightmapData> &p_data) {
_assign_lightmaps();
}
}
+
+ update_gizmo();
}
Ref<BakedLightmapData> BakedLightmap::get_light_data() const {
@@ -726,57 +1296,122 @@ Ref<BakedLightmapData> BakedLightmap::get_light_data() const {
return light_data;
}
-void BakedLightmap::_debug_bake() {
- bake(get_parent(), true);
+void BakedLightmap::set_bake_quality(BakeQuality p_quality) {
+ bake_quality = p_quality;
+}
+
+BakedLightmap::BakeQuality BakedLightmap::get_bake_quality() const {
+ return bake_quality;
}
-void BakedLightmap::set_propagation(float p_propagation) {
- propagation = p_propagation;
+AABB BakedLightmap::get_aabb() const {
+ return AABB();
+}
+Vector<Face3> BakedLightmap::get_faces(uint32_t p_usage_flags) const {
+ return Vector<Face3>();
}
-float BakedLightmap::get_propagation() const {
+void BakedLightmap::set_use_denoiser(bool p_enable) {
- return propagation;
+ use_denoiser = p_enable;
}
-void BakedLightmap::set_energy(float p_energy) {
- energy = p_energy;
+bool BakedLightmap::is_using_denoiser() const {
+
+ return use_denoiser;
}
-float BakedLightmap::get_energy() const {
+void BakedLightmap::set_directional(bool p_enable) {
+ directional = p_enable;
+}
- return energy;
+bool BakedLightmap::is_directional() const {
+ return directional;
}
-void BakedLightmap::set_bake_quality(BakeQuality p_quality) {
- bake_quality = p_quality;
+void BakedLightmap::set_interior(bool p_enable) {
+ interior = p_enable;
+}
+bool BakedLightmap::is_interior() const {
+ return interior;
}
-BakedLightmap::BakeQuality BakedLightmap::get_bake_quality() const {
- return bake_quality;
+void BakedLightmap::set_environment_mode(EnvironmentMode p_mode) {
+ environment_mode = p_mode;
+ _change_notify();
}
-void BakedLightmap::set_bake_mode(BakeMode p_mode) {
- bake_mode = p_mode;
+BakedLightmap::EnvironmentMode BakedLightmap::get_environment_mode() const {
+ return environment_mode;
}
-BakedLightmap::BakeMode BakedLightmap::get_bake_mode() const {
- return bake_mode;
+void BakedLightmap::set_environment_custom_sky(const Ref<Sky> &p_sky) {
+ environment_custom_sky = p_sky;
}
-void BakedLightmap::set_image_path(const String &p_path) {
- image_path = p_path;
+Ref<Sky> BakedLightmap::get_environment_custom_sky() const {
+ return environment_custom_sky;
}
-String BakedLightmap::get_image_path() const {
- return image_path;
+void BakedLightmap::set_environment_custom_color(const Color &p_color) {
+ environment_custom_color = p_color;
+}
+Color BakedLightmap::get_environment_custom_color() const {
+ return environment_custom_color;
}
-AABB BakedLightmap::get_aabb() const {
- return AABB(-extents, extents * 2);
+void BakedLightmap::set_environment_custom_energy(float p_energy) {
+ environment_custom_energy = p_energy;
}
-Vector<Face3> BakedLightmap::get_faces(uint32_t p_usage_flags) const {
- return Vector<Face3>();
+float BakedLightmap::get_environment_custom_energy() const {
+ return environment_custom_energy;
+}
+
+void BakedLightmap::set_bounces(int p_bounces) {
+ ERR_FAIL_COND(p_bounces < 0 || p_bounces > 16);
+ bounces = p_bounces;
+}
+
+int BakedLightmap::get_bounces() const {
+ return bounces;
+}
+
+void BakedLightmap::set_bias(float p_bias) {
+ ERR_FAIL_COND(p_bias < 0.00001);
+ bias = p_bias;
+}
+
+float BakedLightmap::get_bias() const {
+ return bias;
+}
+
+void BakedLightmap::set_max_texture_size(int p_size) {
+ ERR_FAIL_COND(p_size < 2048);
+ max_texture_size = p_size;
+}
+
+int BakedLightmap::get_max_texture_size() const {
+ return max_texture_size;
+}
+
+void BakedLightmap::set_generate_probes(GenerateProbes p_generate_probes) {
+ gen_probes = p_generate_probes;
+}
+
+BakedLightmap::GenerateProbes BakedLightmap::get_generate_probes() const {
+ return gen_probes;
+}
+
+void BakedLightmap::_validate_property(PropertyInfo &property) const {
+ if (property.name == "environment_custom_sky" && environment_mode != ENVIRONMENT_MODE_CUSTOM_SKY) {
+ property.usage = 0;
+ }
+ if (property.name == "environment_custom_color" && environment_mode != ENVIRONMENT_MODE_CUSTOM_COLOR) {
+ property.usage = 0;
+ }
+ if (property.name == "environment_custom_energy" && environment_mode != ENVIRONMENT_MODE_CUSTOM_COLOR && environment_mode != ENVIRONMENT_MODE_CUSTOM_SKY) {
+ property.usage = 0;
+ }
}
void BakedLightmap::_bind_methods() {
@@ -784,81 +1419,100 @@ void BakedLightmap::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_light_data", "data"), &BakedLightmap::set_light_data);
ClassDB::bind_method(D_METHOD("get_light_data"), &BakedLightmap::get_light_data);
- ClassDB::bind_method(D_METHOD("set_bake_cell_size", "bake_cell_size"), &BakedLightmap::set_bake_cell_size);
- ClassDB::bind_method(D_METHOD("get_bake_cell_size"), &BakedLightmap::get_bake_cell_size);
-
- ClassDB::bind_method(D_METHOD("set_capture_cell_size", "capture_cell_size"), &BakedLightmap::set_capture_cell_size);
- ClassDB::bind_method(D_METHOD("get_capture_cell_size"), &BakedLightmap::get_capture_cell_size);
-
ClassDB::bind_method(D_METHOD("set_bake_quality", "bake_quality"), &BakedLightmap::set_bake_quality);
ClassDB::bind_method(D_METHOD("get_bake_quality"), &BakedLightmap::get_bake_quality);
- ClassDB::bind_method(D_METHOD("set_bake_mode", "bake_mode"), &BakedLightmap::set_bake_mode);
- ClassDB::bind_method(D_METHOD("get_bake_mode"), &BakedLightmap::get_bake_mode);
+ ClassDB::bind_method(D_METHOD("set_bounces", "bounces"), &BakedLightmap::set_bounces);
+ ClassDB::bind_method(D_METHOD("get_bounces"), &BakedLightmap::get_bounces);
+
+ ClassDB::bind_method(D_METHOD("set_generate_probes", "subdivision"), &BakedLightmap::set_generate_probes);
+ ClassDB::bind_method(D_METHOD("get_generate_probes"), &BakedLightmap::get_generate_probes);
+
+ ClassDB::bind_method(D_METHOD("set_bias", "bias"), &BakedLightmap::set_bias);
+ ClassDB::bind_method(D_METHOD("get_bias"), &BakedLightmap::get_bias);
- ClassDB::bind_method(D_METHOD("set_extents", "extents"), &BakedLightmap::set_extents);
- ClassDB::bind_method(D_METHOD("get_extents"), &BakedLightmap::get_extents);
+ ClassDB::bind_method(D_METHOD("set_environment_mode", "mode"), &BakedLightmap::set_environment_mode);
+ ClassDB::bind_method(D_METHOD("get_environment_mode"), &BakedLightmap::get_environment_mode);
- ClassDB::bind_method(D_METHOD("set_bake_default_texels_per_unit", "texels"), &BakedLightmap::set_bake_default_texels_per_unit);
- ClassDB::bind_method(D_METHOD("get_bake_default_texels_per_unit"), &BakedLightmap::get_bake_default_texels_per_unit);
+ ClassDB::bind_method(D_METHOD("set_environment_custom_sky", "sky"), &BakedLightmap::set_environment_custom_sky);
+ ClassDB::bind_method(D_METHOD("get_environment_custom_sky"), &BakedLightmap::get_environment_custom_sky);
- ClassDB::bind_method(D_METHOD("set_propagation", "propagation"), &BakedLightmap::set_propagation);
- ClassDB::bind_method(D_METHOD("get_propagation"), &BakedLightmap::get_propagation);
+ ClassDB::bind_method(D_METHOD("set_environment_custom_color", "color"), &BakedLightmap::set_environment_custom_color);
+ ClassDB::bind_method(D_METHOD("get_environment_custom_color"), &BakedLightmap::get_environment_custom_color);
- ClassDB::bind_method(D_METHOD("set_energy", "energy"), &BakedLightmap::set_energy);
- ClassDB::bind_method(D_METHOD("get_energy"), &BakedLightmap::get_energy);
+ ClassDB::bind_method(D_METHOD("set_environment_custom_energy", "energy"), &BakedLightmap::set_environment_custom_energy);
+ ClassDB::bind_method(D_METHOD("get_environment_custom_energy"), &BakedLightmap::get_environment_custom_energy);
- ClassDB::bind_method(D_METHOD("set_hdr", "hdr"), &BakedLightmap::set_hdr);
- ClassDB::bind_method(D_METHOD("is_hdr"), &BakedLightmap::is_hdr);
+ ClassDB::bind_method(D_METHOD("set_max_texture_size", "max_texture_size"), &BakedLightmap::set_max_texture_size);
+ ClassDB::bind_method(D_METHOD("get_max_texture_size"), &BakedLightmap::get_max_texture_size);
- ClassDB::bind_method(D_METHOD("set_image_path", "image_path"), &BakedLightmap::set_image_path);
- ClassDB::bind_method(D_METHOD("get_image_path"), &BakedLightmap::get_image_path);
+ ClassDB::bind_method(D_METHOD("set_use_denoiser", "use_denoiser"), &BakedLightmap::set_use_denoiser);
+ ClassDB::bind_method(D_METHOD("is_using_denoiser"), &BakedLightmap::is_using_denoiser);
- ClassDB::bind_method(D_METHOD("bake", "from_node", "create_visual_debug"), &BakedLightmap::bake, DEFVAL(Variant()), DEFVAL(false));
- ClassDB::bind_method(D_METHOD("debug_bake"), &BakedLightmap::_debug_bake);
- ClassDB::set_method_flags(get_class_static(), _scs_create("debug_bake"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);
+ ClassDB::bind_method(D_METHOD("set_interior", "enable"), &BakedLightmap::set_interior);
+ ClassDB::bind_method(D_METHOD("is_interior"), &BakedLightmap::is_interior);
- ADD_GROUP("Bake", "bake_");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bake_cell_size", PROPERTY_HINT_RANGE, "0.01,64,0.01"), "set_bake_cell_size", "get_bake_cell_size");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "bake_quality", PROPERTY_HINT_ENUM, "Low,Medium,High"), "set_bake_quality", "get_bake_quality");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "bake_mode", PROPERTY_HINT_ENUM, "ConeTrace,RayTrace"), "set_bake_mode", "get_bake_mode");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bake_propagation", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_propagation", "get_propagation");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bake_energy", PROPERTY_HINT_RANGE, "0,32,0.01"), "set_energy", "get_energy");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bake_hdr"), "set_hdr", "is_hdr");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "bake_extents"), "set_extents", "get_extents");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bake_default_texels_per_unit"), "set_bake_default_texels_per_unit", "get_bake_default_texels_per_unit");
- ADD_GROUP("Capture", "capture_");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "capture_cell_size", PROPERTY_HINT_RANGE, "0.01,64,0.01"), "set_capture_cell_size", "get_capture_cell_size");
+ ClassDB::bind_method(D_METHOD("set_directional", "directional"), &BakedLightmap::set_directional);
+ ClassDB::bind_method(D_METHOD("is_directional"), &BakedLightmap::is_directional);
+
+ // ClassDB::bind_method(D_METHOD("bake", "from_node"), &BakedLightmap::bake, DEFVAL(Variant()));
+
+ ADD_GROUP("Tweaks", "");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "quality", PROPERTY_HINT_ENUM, "Low,Medium,High,Ultra"), "set_bake_quality", "get_bake_quality");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "bounces", PROPERTY_HINT_RANGE, "0,16,1"), "set_bounces", "get_bounces");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "directional"), "set_directional", "is_directional");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interior"), "set_interior", "is_interior");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_denoiser"), "set_use_denoiser", "is_using_denoiser");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bias", PROPERTY_HINT_RANGE, "0.00001,0.1,0.00001,or_greater"), "set_bias", "get_bias");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "max_texture_size"), "set_max_texture_size", "get_max_texture_size");
+ ADD_GROUP("Environment", "environment_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "environment_mode", PROPERTY_HINT_ENUM, "Disabled,Scene,Custom Sky,Custom Color"), "set_environment_mode", "get_environment_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment_custom_sky", PROPERTY_HINT_RESOURCE_TYPE, "Sky"), "set_environment_custom_sky", "get_environment_custom_sky");
+ ADD_PROPERTY(PropertyInfo(Variant::COLOR, "environment_custom_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_environment_custom_color", "get_environment_custom_color");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "environment_custom_energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_environment_custom_energy", "get_environment_custom_energy");
+ ADD_GROUP("Gen Probes", "generate_probes_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "generate_probes_subdiv", PROPERTY_HINT_ENUM, "Disabled,4,8,16,32"), "set_generate_probes", "get_generate_probes");
ADD_GROUP("Data", "");
- ADD_PROPERTY(PropertyInfo(Variant::STRING, "image_path", PROPERTY_HINT_DIR), "set_image_path", "get_image_path");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "light_data", PROPERTY_HINT_RESOURCE_TYPE, "BakedLightmapData"), "set_light_data", "get_light_data");
BIND_ENUM_CONSTANT(BAKE_QUALITY_LOW);
BIND_ENUM_CONSTANT(BAKE_QUALITY_MEDIUM);
BIND_ENUM_CONSTANT(BAKE_QUALITY_HIGH);
- BIND_ENUM_CONSTANT(BAKE_MODE_CONE_TRACE);
- BIND_ENUM_CONSTANT(BAKE_MODE_RAY_TRACE);
+ BIND_ENUM_CONSTANT(BAKE_QUALITY_ULTRA);
+
+ BIND_ENUM_CONSTANT(GENERATE_PROBES_DISABLED);
+ BIND_ENUM_CONSTANT(GENERATE_PROBES_SUBDIV_4);
+ BIND_ENUM_CONSTANT(GENERATE_PROBES_SUBDIV_8);
+ BIND_ENUM_CONSTANT(GENERATE_PROBES_SUBDIV_16);
+ BIND_ENUM_CONSTANT(GENERATE_PROBES_SUBDIV_32);
BIND_ENUM_CONSTANT(BAKE_ERROR_OK);
+ BIND_ENUM_CONSTANT(BAKE_ERROR_NO_LIGHTMAPPER);
BIND_ENUM_CONSTANT(BAKE_ERROR_NO_SAVE_PATH);
BIND_ENUM_CONSTANT(BAKE_ERROR_NO_MESHES);
+ BIND_ENUM_CONSTANT(BAKE_ERROR_MESHES_INVALID);
BIND_ENUM_CONSTANT(BAKE_ERROR_CANT_CREATE_IMAGE);
BIND_ENUM_CONSTANT(BAKE_ERROR_USER_ABORTED);
+
+ BIND_ENUM_CONSTANT(ENVIRONMENT_MODE_DISABLED);
+ BIND_ENUM_CONSTANT(ENVIRONMENT_MODE_SCENE);
+ BIND_ENUM_CONSTANT(ENVIRONMENT_MODE_CUSTOM_SKY);
+ BIND_ENUM_CONSTANT(ENVIRONMENT_MODE_CUSTOM_COLOR);
}
BakedLightmap::BakedLightmap() {
- extents = Vector3(10, 10, 10);
- bake_default_texels_per_unit = 20;
- bake_cell_size = 0.25;
- capture_cell_size = 0.5;
+ environment_mode = ENVIRONMENT_MODE_DISABLED;
+ environment_custom_color = Color(0.2, 0.7, 1.0);
+ environment_custom_energy = 1.0;
bake_quality = BAKE_QUALITY_MEDIUM;
- bake_mode = BAKE_MODE_CONE_TRACE;
- energy = 1;
- propagation = 1;
- hdr = false;
- image_path = ".";
- set_disable_scale(true);
+ interior = false;
+ directional = false;
+
+ gen_probes = GENERATE_PROBES_DISABLED;
+ use_denoiser = true;
+ bounces = 1;
+ bias = 0.0005;
+ max_texture_size = 16384;
}
-#endif
diff --git a/scene/3d/baked_lightmap.h b/scene/3d/baked_lightmap.h
index bc9e3f55ea..748fdf913f 100644
--- a/scene/3d/baked_lightmap.h
+++ b/scene/3d/baked_lightmap.h
@@ -28,189 +28,257 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#if 0
-#ifndef BAKED_INDIRECT_LIGHT_H
-#define BAKED_INDIRECT_LIGHT_H
+#ifndef BAKED_LIGHTMAP_H
+#define BAKED_LIGHTMAP_H
-#include "multimesh_instance.h"
-#include "scene/3d/light.h"
-#include "scene/3d/visual_instance.h"
+#include "core/local_vector.h"
+#include "scene/3d/light_3d.h"
+#include "scene/3d/lightmapper.h"
+#include "scene/3d/mesh_instance_3d.h"
+#include "scene/3d/multimesh_instance_3d.h"
+#include "scene/3d/visual_instance_3d.h"
+#include "scene/resources/sky.h"
class BakedLightmapData : public Resource {
GDCLASS(BakedLightmapData, Resource);
+ RES_BASE_EXTENSION("lmbake")
- RID baked_light;
+ Ref<TextureLayered> light_texture;
+
+ bool uses_spherical_harmonics = false;
+ bool interior = false;
+
+ RID lightmap;
AABB bounds;
- float energy;
- int cell_subdiv;
- Transform cell_space_xform;
struct User {
NodePath path;
- Ref<Texture2D> lightmap;
- int instance_index;
+ int32_t sub_instance;
+ Rect2 uv_scale;
+ int slice_index;
};
Vector<User> users;
void _set_user_data(const Array &p_data);
Array _get_user_data() const;
+ void _set_probe_data(const Dictionary &p_data);
+ Dictionary _get_probe_data() const;
protected:
static void _bind_methods();
public:
- void set_bounds(const AABB &p_bounds);
- AABB get_bounds() const;
+ void add_user(const NodePath &p_path, const Rect2 &p_uv_scale, int p_slice_index, int32_t p_sub_instance = -1);
+ int get_user_count() const;
+ NodePath get_user_path(int p_user) const;
+ int32_t get_user_sub_instance(int p_user) const;
+ Rect2 get_user_lightmap_uv_scale(int p_user) const;
+ int get_user_lightmap_slice_index(int p_user) const;
+ void clear_users();
- void set_octree(const Vector<uint8_t> &p_octree);
- Vector<uint8_t> get_octree() const;
+ void set_light_texture(const Ref<TextureLayered> &p_light_texture);
+ Ref<TextureLayered> get_light_texture() const;
- void set_cell_space_transform(const Transform &p_xform);
- Transform get_cell_space_transform() const;
+ void set_uses_spherical_harmonics(bool p_enable);
+ bool is_using_spherical_harmonics() const;
- void set_cell_subdiv(int p_cell_subdiv);
- int get_cell_subdiv() const;
+ bool is_interior() const;
- void set_energy(float p_energy);
- float get_energy() const;
+ void set_capture_data(const AABB &p_bounds, bool p_interior, const PackedVector3Array &p_points, const PackedColorArray &p_point_sh, const PackedInt32Array &p_tetrahedra, const PackedInt32Array &p_bsp_tree);
+ PackedVector3Array get_capture_points() const;
+ PackedColorArray get_capture_sh() const;
+ PackedInt32Array get_capture_tetrahedra() const;
+ PackedInt32Array get_capture_bsp_tree() const;
+ AABB get_capture_bounds() const;
- void add_user(const NodePath &p_path, const Ref<Texture2D> &p_lightmap, int p_instance = -1);
- int get_user_count() const;
- NodePath get_user_path(int p_user) const;
- Ref<Texture2D> get_user_lightmap(int p_user) const;
- int get_user_instance(int p_user) const;
- void clear_users();
+ void clear();
virtual RID get_rid() const;
BakedLightmapData();
~BakedLightmapData();
};
-class BakedLightmap : public VisualInstance {
- GDCLASS(BakedLightmap, VisualInstance);
+class BakedLightmap : public VisualInstance3D {
+ GDCLASS(BakedLightmap, VisualInstance3D);
public:
enum BakeQuality {
BAKE_QUALITY_LOW,
BAKE_QUALITY_MEDIUM,
- BAKE_QUALITY_HIGH
+ BAKE_QUALITY_HIGH,
+ BAKE_QUALITY_ULTRA,
};
- enum BakeMode {
- BAKE_MODE_CONE_TRACE,
- BAKE_MODE_RAY_TRACE,
+ enum GenerateProbes {
+ GENERATE_PROBES_DISABLED,
+ GENERATE_PROBES_SUBDIV_4,
+ GENERATE_PROBES_SUBDIV_8,
+ GENERATE_PROBES_SUBDIV_16,
+ GENERATE_PROBES_SUBDIV_32,
};
enum BakeError {
BAKE_ERROR_OK,
+ BAKE_ERROR_NO_LIGHTMAPPER,
BAKE_ERROR_NO_SAVE_PATH,
BAKE_ERROR_NO_MESHES,
+ BAKE_ERROR_MESHES_INVALID,
BAKE_ERROR_CANT_CREATE_IMAGE,
- BAKE_ERROR_USER_ABORTED
-
+ BAKE_ERROR_USER_ABORTED,
};
- typedef void (*BakeBeginFunc)(int);
- typedef bool (*BakeStepFunc)(int, const String &);
- typedef void (*BakeEndFunc)();
+ enum EnvironmentMode {
+ ENVIRONMENT_MODE_DISABLED,
+ ENVIRONMENT_MODE_SCENE,
+ ENVIRONMENT_MODE_CUSTOM_SKY,
+ ENVIRONMENT_MODE_CUSTOM_COLOR,
+ };
private:
- float bake_cell_size;
- float capture_cell_size;
- Vector3 extents;
- float bake_default_texels_per_unit;
- float propagation;
- float energy;
BakeQuality bake_quality;
- BakeMode bake_mode;
- bool hdr;
- String image_path;
+ bool use_denoiser;
+ int bounces;
+ float bias;
+ int max_texture_size;
+ bool interior;
+ EnvironmentMode environment_mode;
+ Ref<Sky> environment_custom_sky;
+ Color environment_custom_color;
+ float environment_custom_energy;
+ bool directional;
+ GenerateProbes gen_probes;
Ref<BakedLightmapData> light_data;
- struct PlotMesh {
- Ref<Material> override_material;
- Vector<Ref<Material> > instance_materials;
- Ref<Mesh> mesh;
- Transform local_xform;
- NodePath path;
- int instance_idx;
+ struct LightsFound {
+ Transform xform;
+ Light3D *light;
};
- struct PlotLight {
- Light *light;
- Transform local_xform;
+ struct MeshesFound {
+ Transform xform;
+ NodePath node_path;
+ int32_t subindex;
+ Ref<Mesh> mesh;
+ int32_t lightmap_scale;
+ Vector<Ref<Material>> overrides;
};
- void _find_meshes_and_lights(Node *p_at_node, List<PlotMesh> &plot_meshes, List<PlotLight> &plot_lights);
-
- void _debug_bake();
+ void _find_meshes_and_lights(Node *p_at_node, Vector<MeshesFound> &meshes, Vector<LightsFound> &lights, Vector<Vector3> &probes);
void _assign_lightmaps();
void _clear_lightmaps();
- static bool _bake_time(void *ud, float p_secs, float p_progress);
-
struct BakeTimeData {
String text;
int pass;
uint64_t last_step;
};
+ struct BSPSimplex {
+ int vertices[4];
+ int planes[4];
+ };
+
+ struct BSPNode {
+ static const int32_t EMPTY_LEAF = INT32_MIN;
+ Plane plane;
+ int32_t over = EMPTY_LEAF, under = EMPTY_LEAF;
+ };
+
+ int _bsp_get_simplex_side(const Vector<Vector3> &p_points, const LocalVector<BSPSimplex> &p_simplices, const Plane &p_plane, uint32_t p_simplex) const;
+ int32_t _compute_bsp_tree(const Vector<Vector3> &p_points, const LocalVector<Plane> &p_planes, LocalVector<int32_t> &planes_tested, const LocalVector<BSPSimplex> &p_simplices, const LocalVector<int32_t> &p_simplex_indices, LocalVector<BSPNode> &bsp_nodes);
+
+ struct BakeStepUD {
+ Lightmapper::BakeStepFunc func;
+ void *ud;
+ float from_percent;
+ float to_percent;
+ };
+
+ static bool _lightmap_bake_step_function(float p_completion, const String &p_text, void *ud, bool p_refresh);
+
+ struct GenProbesOctree {
+ Vector3i offset;
+ uint32_t size;
+ GenProbesOctree *children[8] = { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
+ ~GenProbesOctree() {
+ for (int i = 0; i < 8; i++) {
+ if (children[i] != nullptr) {
+ memdelete(children[i]);
+ }
+ }
+ }
+ };
+
+ struct Vector3iHash {
+ _FORCE_INLINE_ static uint32_t hash(const Vector3i &p_vtx) {
+ uint32_t h = hash_djb2_one_32(p_vtx.x);
+ h = hash_djb2_one_32(p_vtx.y, h);
+ return hash_djb2_one_32(p_vtx.z, h);
+ }
+ };
+
+ void _plot_triangle_into_octree(GenProbesOctree *p_cell, float p_cell_size, const Vector3 *p_triangle);
+ void _gen_new_positions_from_octree(const GenProbesOctree *p_cell, float p_cell_size, const Vector<Vector3> &probe_positions, LocalVector<Vector3> &new_probe_positions, HashMap<Vector3i, bool, Vector3iHash> &positions_used, const AABB &p_bounds);
+
protected:
+ void _validate_property(PropertyInfo &property) const;
static void _bind_methods();
void _notification(int p_what);
public:
- static BakeBeginFunc bake_begin_function;
- static BakeStepFunc bake_step_function;
- static BakeEndFunc bake_end_function;
-
void set_light_data(const Ref<BakedLightmapData> &p_data);
Ref<BakedLightmapData> get_light_data() const;
- void set_bake_cell_size(float p_cell_size);
- float get_bake_cell_size() const;
+ void set_bake_quality(BakeQuality p_quality);
+ BakeQuality get_bake_quality() const;
+
+ void set_use_denoiser(bool p_enable);
+ bool is_using_denoiser() const;
- void set_capture_cell_size(float p_cell_size);
- float get_capture_cell_size() const;
+ void set_directional(bool p_enable);
+ bool is_directional() const;
- void set_extents(const Vector3 &p_extents);
- Vector3 get_extents() const;
+ void set_interior(bool p_interior);
+ bool is_interior() const;
- void set_bake_default_texels_per_unit(const float &p_bake_texels_per_unit);
- float get_bake_default_texels_per_unit() const;
+ void set_environment_mode(EnvironmentMode p_mode);
+ EnvironmentMode get_environment_mode() const;
- void set_propagation(float p_propagation);
- float get_propagation() const;
+ void set_environment_custom_sky(const Ref<Sky> &p_sky);
+ Ref<Sky> get_environment_custom_sky() const;
- void set_energy(float p_energy);
- float get_energy() const;
+ void set_environment_custom_color(const Color &p_color);
+ Color get_environment_custom_color() const;
- void set_bake_quality(BakeQuality p_quality);
- BakeQuality get_bake_quality() const;
+ void set_environment_custom_energy(float p_energy);
+ float get_environment_custom_energy() const;
+
+ void set_bounces(int p_bounces);
+ int get_bounces() const;
- void set_bake_mode(BakeMode p_mode);
- BakeMode get_bake_mode() const;
+ void set_bias(float p_bias);
+ float get_bias() const;
- void set_hdr(bool p_enable);
- bool is_hdr() const;
+ void set_max_texture_size(int p_size);
+ int get_max_texture_size() const;
- void set_image_path(const String &p_path);
- String get_image_path() const;
+ void set_generate_probes(GenerateProbes p_generate_probes);
+ GenerateProbes get_generate_probes() const;
AABB get_aabb() const;
Vector<Face3> get_faces(uint32_t p_usage_flags) const;
- BakeError bake(Node *p_from_node, bool p_create_visual_debug = false);
+ BakeError bake(Node *p_from_node, String p_image_data_path = "", Lightmapper::BakeStepFunc p_bake_step = nullptr, void *p_bake_userdata = nullptr);
BakedLightmap();
};
VARIANT_ENUM_CAST(BakedLightmap::BakeQuality);
-VARIANT_ENUM_CAST(BakedLightmap::BakeMode);
+VARIANT_ENUM_CAST(BakedLightmap::GenerateProbes);
VARIANT_ENUM_CAST(BakedLightmap::BakeError);
+VARIANT_ENUM_CAST(BakedLightmap::EnvironmentMode);
-#endif
-#endif // BAKED_INDIRECT_LIGHT_H
+#endif // BAKED_LIGHTMAP_H
diff --git a/scene/3d/cpu_particles_3d.cpp b/scene/3d/cpu_particles_3d.cpp
index 4c25f55f0b..414dc6f97b 100644
--- a/scene/3d/cpu_particles_3d.cpp
+++ b/scene/3d/cpu_particles_3d.cpp
@@ -1004,7 +1004,8 @@ void CPUParticles3D::_particles_process(float p_delta) {
//scale by scale
float base_scale = tex_scale * Math::lerp(parameters[PARAM_SCALE], 1.0f, p.scale_rand * randomness[PARAM_SCALE]);
- if (base_scale < 0.000001) base_scale = 0.000001;
+ if (base_scale < 0.000001)
+ base_scale = 0.000001;
p.transform.basis.scale(Vector3(1, 1, 1) * base_scale);
@@ -1253,7 +1254,8 @@ void CPUParticles3D::convert_from_particles(Node *p_particles) {
set_param(m_param, material->get_param(ParticlesMaterial::m_param)); \
{ \
Ref<CurveTexture> ctex = material->get_param_texture(ParticlesMaterial::m_param); \
- if (ctex.is_valid()) set_param_curve(m_param, ctex->get_curve()); \
+ if (ctex.is_valid()) \
+ set_param_curve(m_param, ctex->get_curve()); \
} \
set_param_randomness(m_param, material->get_param_randomness(ParticlesMaterial::m_param));
diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp
index 6d571ee4f2..65a330ddc0 100644
--- a/scene/3d/gi_probe.cpp
+++ b/scene/3d/gi_probe.cpp
@@ -349,7 +349,7 @@ Vector3 GIProbe::get_extents() const {
void GIProbe::_find_meshes(Node *p_at_node, List<PlotMesh> &plot_meshes) {
MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_at_node);
- if (mi && mi->get_flag(GeometryInstance3D::FLAG_USE_BAKED_LIGHT) && mi->is_visible_in_tree()) {
+ if (mi && mi->get_gi_mode() == GeometryInstance3D::GI_MODE_BAKED && mi->is_visible_in_tree()) {
Ref<Mesh> mesh = mi->get_mesh();
if (mesh.is_valid()) {
diff --git a/scene/3d/gpu_particles_3d.cpp b/scene/3d/gpu_particles_3d.cpp
index 7744c477cb..01886a730f 100644
--- a/scene/3d/gpu_particles_3d.cpp
+++ b/scene/3d/gpu_particles_3d.cpp
@@ -257,7 +257,8 @@ String GPUParticles3D::get_configuration_warning() const {
StandardMaterial3D *spat = Object::cast_to<StandardMaterial3D>(draw_passes[i]->surface_get_material(j).ptr());
anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == StandardMaterial3D::BILLBOARD_PARTICLES);
}
- if (anim_material_found) break;
+ if (anim_material_found)
+ break;
}
}
diff --git a/scene/3d/light_3d.cpp b/scene/3d/light_3d.cpp
index c048f60ebd..0aa0f7e5ac 100644
--- a/scene/3d/light_3d.cpp
+++ b/scene/3d/light_3d.cpp
@@ -326,9 +326,15 @@ Light3D::Light3D(RenderingServer::LightType p_type) {
type = p_type;
switch (p_type) {
- case RS::LIGHT_DIRECTIONAL: light = RenderingServer::get_singleton()->directional_light_create(); break;
- case RS::LIGHT_OMNI: light = RenderingServer::get_singleton()->omni_light_create(); break;
- case RS::LIGHT_SPOT: light = RenderingServer::get_singleton()->spot_light_create(); break;
+ case RS::LIGHT_DIRECTIONAL:
+ light = RenderingServer::get_singleton()->directional_light_create();
+ break;
+ case RS::LIGHT_OMNI:
+ light = RenderingServer::get_singleton()->omni_light_create();
+ break;
+ case RS::LIGHT_SPOT:
+ light = RenderingServer::get_singleton()->spot_light_create();
+ break;
default: {
};
}
diff --git a/scene/3d/lightmap_probe.cpp b/scene/3d/lightmap_probe.cpp
new file mode 100644
index 0000000000..2da81337f0
--- /dev/null
+++ b/scene/3d/lightmap_probe.cpp
@@ -0,0 +1,4 @@
+#include "lightmap_probe.h"
+
+LightmapProbe::LightmapProbe() {
+}
diff --git a/scene/3d/lightmap_probe.h b/scene/3d/lightmap_probe.h
new file mode 100644
index 0000000000..65bc6914f4
--- /dev/null
+++ b/scene/3d/lightmap_probe.h
@@ -0,0 +1,12 @@
+#ifndef LIGHTMAP_PROBE_H
+#define LIGHTMAP_PROBE_H
+
+#include "scene/3d/node_3d.h"
+
+class LightmapProbe : public Node3D {
+ GDCLASS(LightmapProbe, Node3D)
+public:
+ LightmapProbe();
+};
+
+#endif // LIGHTMAP_PROBE_H
diff --git a/scene/3d/lightmapper.cpp b/scene/3d/lightmapper.cpp
new file mode 100644
index 0000000000..53ebd5ee2e
--- /dev/null
+++ b/scene/3d/lightmapper.cpp
@@ -0,0 +1,37 @@
+#include "lightmapper.h"
+
+LightmapDenoiser *(*LightmapDenoiser::create_function)() = nullptr;
+
+Ref<LightmapDenoiser> LightmapDenoiser::create() {
+ if (create_function) {
+ return Ref<LightmapDenoiser>(create_function());
+ }
+ return Ref<LightmapDenoiser>();
+}
+
+Lightmapper::CreateFunc Lightmapper::create_custom = nullptr;
+Lightmapper::CreateFunc Lightmapper::create_gpu = nullptr;
+Lightmapper::CreateFunc Lightmapper::create_cpu = nullptr;
+
+Ref<Lightmapper> Lightmapper::create() {
+ Lightmapper *lm = nullptr;
+ if (create_custom) {
+ lm = create_custom();
+ }
+
+ if (!lm && create_gpu) {
+ lm = create_gpu();
+ }
+
+ if (!lm && create_cpu) {
+ lm = create_cpu();
+ }
+ if (!lm) {
+ return Ref<Lightmapper>();
+ } else {
+ return Ref<Lightmapper>(lm);
+ }
+}
+
+Lightmapper::Lightmapper() {
+}
diff --git a/scene/3d/lightmapper.h b/scene/3d/lightmapper.h
new file mode 100644
index 0000000000..7c052a30a0
--- /dev/null
+++ b/scene/3d/lightmapper.h
@@ -0,0 +1,90 @@
+#ifndef LIGHTMAPPER_H
+#define LIGHTMAPPER_H
+
+#include "scene/resources/mesh.h"
+#include "servers/rendering/rendering_device.h"
+
+class LightmapDenoiser : public Reference {
+ GDCLASS(LightmapDenoiser, Reference)
+protected:
+ static LightmapDenoiser *(*create_function)();
+
+public:
+ virtual Ref<Image> denoise_image(const Ref<Image> &p_image) = 0;
+ static Ref<LightmapDenoiser> create();
+};
+
+class Lightmapper : public Reference {
+ GDCLASS(Lightmapper, Reference)
+public:
+ enum GenerateProbes {
+ GENERATE_PROBES_DISABLED,
+ GENERATE_PROBES_SUBDIV_4,
+ GENERATE_PROBES_SUBDIV_8,
+ GENERATE_PROBES_SUBDIV_16,
+ GENERATE_PROBES_SUBDIV_32,
+
+ };
+
+ enum LightType {
+ LIGHT_TYPE_DIRECTIONAL,
+ LIGHT_TYPE_OMNI,
+ LIGHT_TYPE_SPOT
+ };
+
+ enum BakeError {
+ BAKE_ERROR_LIGHTMAP_TOO_SMALL,
+ BAKE_ERROR_LIGHTMAP_CANT_PRE_BAKE_MESHES,
+ BAKE_OK
+ };
+
+ enum BakeQuality {
+ BAKE_QUALITY_LOW,
+ BAKE_QUALITY_MEDIUM,
+ BAKE_QUALITY_HIGH,
+ BAKE_QUALITY_ULTRA,
+ };
+
+ typedef Lightmapper *(*CreateFunc)();
+
+ static CreateFunc create_custom;
+ static CreateFunc create_gpu;
+ static CreateFunc create_cpu;
+
+protected:
+public:
+ typedef bool (*BakeStepFunc)(float, const String &, void *, bool); //step index, step total, step description, userdata
+
+ struct MeshData {
+ //triangle data
+ Vector<Vector3> points;
+ Vector<Vector2> uv2;
+ Vector<Vector3> normal;
+ Ref<Image> albedo_on_uv2;
+ Ref<Image> emission_on_uv2;
+ Variant userdata;
+ };
+
+ virtual void add_mesh(const MeshData &p_mesh) = 0;
+ virtual void add_directional_light(bool p_static, const Vector3 &p_direction, const Color &p_color, float p_energy, float p_angular_distance) = 0;
+ virtual void add_omni_light(bool p_static, const Vector3 &p_position, const Color &p_color, float p_energy, float p_range, float p_attenuation, float p_size) = 0;
+ virtual void add_spot_light(bool p_static, const Vector3 &p_position, const Vector3 p_direction, const Color &p_color, float p_energy, float p_range, float p_attenuation, float p_spot_angle, float p_spot_attenuation, float p_size) = 0;
+ virtual void add_probe(const Vector3 &p_position) = 0;
+ virtual BakeError bake(BakeQuality p_quality, bool p_use_denoiser, int p_bounces, float p_bias, int p_max_texture_size, bool p_bake_sh, GenerateProbes p_generate_probes, const Ref<Image> &p_environment_panorama, const Basis &p_environment_transform, BakeStepFunc p_step_function = nullptr, void *p_step_userdata = nullptr) = 0;
+
+ virtual int get_bake_texture_count() const = 0;
+ virtual Ref<Image> get_bake_texture(int p_index) const = 0;
+ virtual int get_bake_mesh_count() const = 0;
+ virtual Variant get_bake_mesh_userdata(int p_index) const = 0;
+ virtual Rect2 get_bake_mesh_uv_scale(int p_index) const = 0;
+ virtual int get_bake_mesh_texture_slice(int p_index) const = 0;
+ virtual int get_bake_probe_count() const = 0;
+ virtual Vector3 get_bake_probe_point(int p_probe) const = 0;
+ virtual Vector<Color> get_bake_probe_sh(int p_probe) const = 0;
+
+ static Ref<Lightmapper> create();
+
+ Lightmapper();
+};
+
+#endif // LIGHTMAPPER_H
diff --git a/scene/3d/navigation_agent_3d.cpp b/scene/3d/navigation_agent_3d.cpp
index 0449ab15b7..020d598f00 100644
--- a/scene/3d/navigation_agent_3d.cpp
+++ b/scene/3d/navigation_agent_3d.cpp
@@ -141,16 +141,7 @@ void NavigationAgent3D::_notification(int p_what) {
}
}
-NavigationAgent3D::NavigationAgent3D() :
- agent_parent(nullptr),
- navigation(nullptr),
- agent(RID()),
- target_desired_distance(1.0),
- navigation_height_offset(0.0),
- path_max_distance(3.0),
- velocity_submitted(false),
- target_reached(false),
- navigation_finished(true) {
+NavigationAgent3D::NavigationAgent3D() {
agent = NavigationServer3D::get_singleton()->agent_create();
set_neighbor_dist(50.0);
set_max_neighbors(10);
@@ -306,9 +297,12 @@ String NavigationAgent3D::get_configuration_warning() const {
void NavigationAgent3D::update_navigation() {
- if (agent_parent == nullptr) return;
- if (navigation == nullptr) return;
- if (update_frame_id == Engine::get_singleton()->get_physics_frames()) return;
+ if (agent_parent == nullptr)
+ return;
+ if (navigation == nullptr)
+ return;
+ if (update_frame_id == Engine::get_singleton()->get_physics_frames())
+ return;
update_frame_id = Engine::get_singleton()->get_physics_frames();
diff --git a/scene/3d/navigation_agent_3d.h b/scene/3d/navigation_agent_3d.h
index 3558b4e51b..6dc375ef24 100644
--- a/scene/3d/navigation_agent_3d.h
+++ b/scene/3d/navigation_agent_3d.h
@@ -40,31 +40,31 @@ class Navigation3D;
class NavigationAgent3D : public Node {
GDCLASS(NavigationAgent3D, Node);
- Node3D *agent_parent;
- Navigation3D *navigation;
+ Node3D *agent_parent = nullptr;
+ Navigation3D *navigation = nullptr;
RID agent;
- real_t target_desired_distance;
+ real_t target_desired_distance = 1.0;
real_t radius;
- real_t navigation_height_offset;
+ real_t navigation_height_offset = 0.0;
bool ignore_y;
real_t neighbor_dist;
int max_neighbors;
real_t time_horizon;
real_t max_speed;
- real_t path_max_distance;
+ real_t path_max_distance = 3.0;
Vector3 target_location;
Vector<Vector3> navigation_path;
int nav_path_index;
- bool velocity_submitted;
+ bool velocity_submitted = false;
Vector3 prev_safe_velocity;
/// The submitted target velocity
Vector3 target_velocity;
- bool target_reached;
- bool navigation_finished;
+ bool target_reached = false;
+ bool navigation_finished = true;
// No initialized on purpose
uint32_t update_frame_id;
diff --git a/scene/3d/navigation_obstacle_3d.cpp b/scene/3d/navigation_obstacle_3d.cpp
index 2ee2008799..2f99a5f99e 100644
--- a/scene/3d/navigation_obstacle_3d.cpp
+++ b/scene/3d/navigation_obstacle_3d.cpp
@@ -86,9 +86,7 @@ void NavigationObstacle3D::_notification(int p_what) {
}
}
-NavigationObstacle3D::NavigationObstacle3D() :
- navigation(nullptr),
- agent(RID()) {
+NavigationObstacle3D::NavigationObstacle3D() {
agent = NavigationServer3D::get_singleton()->agent_create();
}
diff --git a/scene/3d/navigation_obstacle_3d.h b/scene/3d/navigation_obstacle_3d.h
index b58d7c4991..c7d2b556af 100644
--- a/scene/3d/navigation_obstacle_3d.h
+++ b/scene/3d/navigation_obstacle_3d.h
@@ -38,7 +38,7 @@ class Navigation3D;
class NavigationObstacle3D : public Node {
GDCLASS(NavigationObstacle3D, Node);
- Navigation3D *navigation;
+ Navigation3D *navigation = nullptr;
RID agent;
diff --git a/scene/3d/navigation_region_3d.cpp b/scene/3d/navigation_region_3d.cpp
index 043b816033..b15fa6166f 100644
--- a/scene/3d/navigation_region_3d.cpp
+++ b/scene/3d/navigation_region_3d.cpp
@@ -242,14 +242,8 @@ void NavigationRegion3D::_changed_callback(Object *p_changed, const char *p_prop
}
NavigationRegion3D::NavigationRegion3D() {
-
- enabled = true;
set_notify_transform(true);
region = NavigationServer3D::get_singleton()->region_create();
-
- navigation = nullptr;
- debug_view = nullptr;
- bake_thread = nullptr;
}
NavigationRegion3D::~NavigationRegion3D() {
diff --git a/scene/3d/navigation_region_3d.h b/scene/3d/navigation_region_3d.h
index ae071e6b7a..a7b5077f53 100644
--- a/scene/3d/navigation_region_3d.h
+++ b/scene/3d/navigation_region_3d.h
@@ -41,13 +41,13 @@ class NavigationRegion3D : public Node3D {
GDCLASS(NavigationRegion3D, Node3D);
- bool enabled;
+ bool enabled = true;
RID region;
Ref<NavigationMesh> navmesh;
- Navigation3D *navigation;
- Node *debug_view;
- Thread *bake_thread;
+ Navigation3D *navigation = nullptr;
+ Node *debug_view = nullptr;
+ Thread *bake_thread = nullptr;
protected:
void _notification(int p_what);
diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp
index 3991efc7c0..d672c6f6b5 100644
--- a/scene/3d/physics_body_3d.cpp
+++ b/scene/3d/physics_body_3d.cpp
@@ -1346,7 +1346,8 @@ Vector3 KinematicCollision3D::get_remainder() const {
return collision.remainder;
}
Object *KinematicCollision3D::get_local_shape() const {
- if (!owner) return nullptr;
+ if (!owner)
+ return nullptr;
uint32_t ownerid = owner->shape_find_owner(collision.local_shape);
return owner->shape_owner_get_owner(ownerid);
}
@@ -2578,24 +2579,7 @@ bool PhysicalBone3D::get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const {
}
PhysicalBone3D::PhysicalBone3D() :
- PhysicsBody3D(PhysicsServer3D::BODY_MODE_STATIC),
-#ifdef TOOLS_ENABLED
- gizmo_move_joint(false),
-#endif
- joint_data(nullptr),
- parent_skeleton(nullptr),
- simulate_physics(false),
- _internal_simulate_physics(false),
- bone_id(-1),
- bone_name(""),
- bounce(0),
- mass(1),
- friction(1),
- gravity_scale(1),
- linear_damp(-1),
- angular_damp(-1),
- can_sleep(true) {
-
+ PhysicsBody3D(PhysicsServer3D::BODY_MODE_STATIC) {
reset_physics_simulation_state();
}
diff --git a/scene/3d/physics_body_3d.h b/scene/3d/physics_body_3d.h
index 0e719f5108..205052f798 100644
--- a/scene/3d/physics_body_3d.h
+++ b/scene/3d/physics_body_3d.h
@@ -396,14 +396,11 @@ public:
virtual bool _get(const StringName &p_name, Variant &r_ret) const;
virtual void _get_property_list(List<PropertyInfo> *p_list) const;
- real_t bias;
- real_t damping;
- real_t impulse_clamp;
-
- PinJointData() :
- bias(0.3),
- damping(1.),
- impulse_clamp(0) {}
+ real_t bias = 0.3;
+ real_t damping = 1.;
+ real_t impulse_clamp = 0;
+
+ PinJointData() {}
};
struct ConeJointData : public JointData {
@@ -414,17 +411,13 @@ public:
virtual void _get_property_list(List<PropertyInfo> *p_list) const;
real_t swing_span;
- real_t twist_span;
- real_t bias;
- real_t softness;
- real_t relaxation;
+ real_t twist_span = Math_PI;
+ real_t bias = 0.3;
+ real_t softness = 0.8;
+ real_t relaxation = 1.;
ConeJointData() :
- swing_span(Math_PI * 0.25),
- twist_span(Math_PI),
- bias(0.3),
- softness(0.8),
- relaxation(1.) {}
+ swing_span(Math_PI * 0.25) {}
};
struct HingeJointData : public JointData {
@@ -434,20 +427,17 @@ public:
virtual bool _get(const StringName &p_name, Variant &r_ret) const;
virtual void _get_property_list(List<PropertyInfo> *p_list) const;
- bool angular_limit_enabled;
+ bool angular_limit_enabled = false;
real_t angular_limit_upper;
real_t angular_limit_lower;
- real_t angular_limit_bias;
- real_t angular_limit_softness;
- real_t angular_limit_relaxation;
+ real_t angular_limit_bias = 0.3;
+ real_t angular_limit_softness = 0.9;
+ real_t angular_limit_relaxation = 1.;
HingeJointData() :
- angular_limit_enabled(false),
+
angular_limit_upper(Math_PI * 0.5),
- angular_limit_lower(-Math_PI * 0.5),
- angular_limit_bias(0.3),
- angular_limit_softness(0.9),
- angular_limit_relaxation(1.) {}
+ angular_limit_lower(-Math_PI * 0.5) {}
};
struct SliderJointData : public JointData {
@@ -457,76 +447,45 @@ public:
virtual bool _get(const StringName &p_name, Variant &r_ret) const;
virtual void _get_property_list(List<PropertyInfo> *p_list) const;
- real_t linear_limit_upper;
- real_t linear_limit_lower;
- real_t linear_limit_softness;
- real_t linear_limit_restitution;
- real_t linear_limit_damping;
- real_t angular_limit_upper;
- real_t angular_limit_lower;
- real_t angular_limit_softness;
- real_t angular_limit_restitution;
- real_t angular_limit_damping;
-
- SliderJointData() :
- linear_limit_upper(1.),
- linear_limit_lower(-1.),
- linear_limit_softness(1.),
- linear_limit_restitution(0.7),
- linear_limit_damping(1.),
- angular_limit_upper(0),
- angular_limit_lower(0),
- angular_limit_softness(1.),
- angular_limit_restitution(0.7),
- angular_limit_damping(1.) {}
+ real_t linear_limit_upper = 1.;
+ real_t linear_limit_lower = -1.;
+ real_t linear_limit_softness = 1.;
+ real_t linear_limit_restitution = 0.7;
+ real_t linear_limit_damping = 1.;
+ real_t angular_limit_upper = 0;
+ real_t angular_limit_lower = 0;
+ real_t angular_limit_softness = 1.;
+ real_t angular_limit_restitution = 0.7;
+ real_t angular_limit_damping = 1.;
+
+ SliderJointData() {}
};
struct SixDOFJointData : public JointData {
struct SixDOFAxisData {
- bool linear_limit_enabled;
- real_t linear_limit_upper;
- real_t linear_limit_lower;
- real_t linear_limit_softness;
- real_t linear_restitution;
- real_t linear_damping;
- bool linear_spring_enabled;
- real_t linear_spring_stiffness;
- real_t linear_spring_damping;
- real_t linear_equilibrium_point;
- bool angular_limit_enabled;
- real_t angular_limit_upper;
- real_t angular_limit_lower;
- real_t angular_limit_softness;
- real_t angular_restitution;
- real_t angular_damping;
- real_t erp;
- bool angular_spring_enabled;
- real_t angular_spring_stiffness;
- real_t angular_spring_damping;
- real_t angular_equilibrium_point;
-
- SixDOFAxisData() :
- linear_limit_enabled(true),
- linear_limit_upper(0),
- linear_limit_lower(0),
- linear_limit_softness(0.7),
- linear_restitution(0.5),
- linear_damping(1.),
- linear_spring_enabled(false),
- linear_spring_stiffness(0),
- linear_spring_damping(0),
- linear_equilibrium_point(0),
- angular_limit_enabled(true),
- angular_limit_upper(0),
- angular_limit_lower(0),
- angular_limit_softness(0.5),
- angular_restitution(0),
- angular_damping(1.),
- erp(0.5),
- angular_spring_enabled(false),
- angular_spring_stiffness(0),
- angular_spring_damping(0.),
- angular_equilibrium_point(0) {}
+ bool linear_limit_enabled = true;
+ real_t linear_limit_upper = 0;
+ real_t linear_limit_lower = 0;
+ real_t linear_limit_softness = 0.7;
+ real_t linear_restitution = 0.5;
+ real_t linear_damping = 1.;
+ bool linear_spring_enabled = false;
+ real_t linear_spring_stiffness = 0;
+ real_t linear_spring_damping = 0;
+ real_t linear_equilibrium_point = 0;
+ bool angular_limit_enabled = true;
+ real_t angular_limit_upper = 0;
+ real_t angular_limit_lower = 0;
+ real_t angular_limit_softness = 0.5;
+ real_t angular_restitution = 0;
+ real_t angular_damping = 1.;
+ real_t erp = 0.5;
+ bool angular_spring_enabled = false;
+ real_t angular_spring_stiffness = 0;
+ real_t angular_spring_damping = 0.;
+ real_t angular_equilibrium_point = 0;
+
+ SixDOFAxisData() {}
};
virtual JointType get_joint_type() { return JOINT_TYPE_6DOF; }
@@ -543,28 +502,28 @@ public:
private:
#ifdef TOOLS_ENABLED
// if false gizmo move body
- bool gizmo_move_joint;
+ bool gizmo_move_joint = false;
#endif
- JointData *joint_data;
+ JointData *joint_data = nullptr;
Transform joint_offset;
RID joint;
- Skeleton3D *parent_skeleton;
+ Skeleton3D *parent_skeleton = nullptr;
Transform body_offset;
Transform body_offset_inverse;
- bool simulate_physics;
- bool _internal_simulate_physics;
- int bone_id;
+ bool simulate_physics = false;
+ bool _internal_simulate_physics = false;
+ int bone_id = -1;
String bone_name;
- real_t bounce;
- real_t mass;
- real_t friction;
- real_t gravity_scale;
- real_t linear_damp;
- real_t angular_damp;
- bool can_sleep;
+ real_t bounce = 0;
+ real_t mass = 1;
+ real_t friction = 1;
+ real_t gravity_scale = 1;
+ real_t linear_damp = -1;
+ real_t angular_damp = -1;
+ bool can_sleep = true;
protected:
bool _set(const StringName &p_name, const Variant &p_value);
diff --git a/scene/3d/physics_joint_3d.cpp b/scene/3d/physics_joint_3d.cpp
index 140d887d9a..b6953fafac 100644
--- a/scene/3d/physics_joint_3d.cpp
+++ b/scene/3d/physics_joint_3d.cpp
@@ -960,8 +960,7 @@ RID Generic6DOFJoint3D::_configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *b
return j;
}
-Generic6DOFJoint3D::Generic6DOFJoint3D() :
- precision(1) {
+Generic6DOFJoint3D::Generic6DOFJoint3D() {
set_param_x(PARAM_LINEAR_LOWER_LIMIT, 0);
set_param_x(PARAM_LINEAR_UPPER_LIMIT, 0);
diff --git a/scene/3d/physics_joint_3d.h b/scene/3d/physics_joint_3d.h
index ce0c7af5d1..38a3f314ba 100644
--- a/scene/3d/physics_joint_3d.h
+++ b/scene/3d/physics_joint_3d.h
@@ -305,7 +305,7 @@ protected:
float params_z[PARAM_MAX];
bool flags_z[FLAG_MAX];
- int precision;
+ int precision = 1;
virtual RID _configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b);
static void _bind_methods();
diff --git a/scene/3d/skeleton_ik_3d.cpp b/scene/3d/skeleton_ik_3d.cpp
index 10bdd71d73..5c0e48a5df 100644
--- a/scene/3d/skeleton_ik_3d.cpp
+++ b/scene/3d/skeleton_ik_3d.cpp
@@ -434,15 +434,7 @@ void SkeletonIK3D::_notification(int p_what) {
}
}
-SkeletonIK3D::SkeletonIK3D() :
- interpolation(1),
- override_tip_basis(true),
- use_magnet(false),
- min_distance(0.01),
- max_iterations(10),
- skeleton(nullptr),
- target_node_override(nullptr),
- task(nullptr) {
+SkeletonIK3D::SkeletonIK3D() {
}
SkeletonIK3D::~SkeletonIK3D() {
diff --git a/scene/3d/skeleton_ik_3d.h b/scene/3d/skeleton_ik_3d.h
index 5fbbe6e9e7..ad2623193b 100644
--- a/scene/3d/skeleton_ik_3d.h
+++ b/scene/3d/skeleton_ik_3d.h
@@ -50,36 +50,30 @@ class FabrikInverseKinematic {
struct ChainItem {
Vector<ChainItem> children;
- ChainItem *parent_item;
+ ChainItem *parent_item = nullptr;
// Bone info
- BoneId bone;
- PhysicalBone3D *pb;
+ BoneId bone = -1;
+ PhysicalBone3D *pb = nullptr;
- real_t length;
+ real_t length = 0;
/// Positions relative to root bone
Transform initial_transform;
Vector3 current_pos;
// Direction from this bone to child
Vector3 current_ori;
- ChainItem() :
- parent_item(nullptr),
- bone(-1),
- pb(nullptr),
- length(0) {}
+ ChainItem() {}
ChainItem *find_child(const BoneId p_bone_id);
ChainItem *add_child(const BoneId p_bone_id);
};
struct ChainTip {
- ChainItem *chain_item;
- const EndEffector *end_effector;
+ ChainItem *chain_item = nullptr;
+ const EndEffector *end_effector = nullptr;
- ChainTip() :
- chain_item(nullptr),
- end_effector(nullptr) {}
+ ChainTip() {}
ChainTip(ChainItem *p_chain_item, const EndEffector *p_end_effector) :
chain_item(p_chain_item),
@@ -100,25 +94,21 @@ class FabrikInverseKinematic {
public:
struct Task {
RID self;
- Skeleton3D *skeleton;
+ Skeleton3D *skeleton = nullptr;
Chain chain;
// Settings
- real_t min_distance;
- int max_iterations;
+ real_t min_distance = 0.01;
+ int max_iterations = 10;
// Bone data
- BoneId root_bone;
+ BoneId root_bone = -1;
Vector<EndEffector> end_effectors;
Transform goal_global_transform;
- Task() :
- skeleton(nullptr),
- min_distance(0.01),
- max_iterations(10),
- root_bone(-1) {}
+ Task() {}
};
private:
@@ -146,19 +136,19 @@ class SkeletonIK3D : public Node {
StringName root_bone;
StringName tip_bone;
- real_t interpolation;
+ real_t interpolation = 1;
Transform target;
NodePath target_node_path_override;
- bool override_tip_basis;
- bool use_magnet;
+ bool override_tip_basis = true;
+ bool use_magnet = false;
Vector3 magnet_position;
- real_t min_distance;
- int max_iterations;
+ real_t min_distance = 0.01;
+ int max_iterations = 10;
- Skeleton3D *skeleton;
- Node3D *target_node_override;
- FabrikInverseKinematic::Task *task;
+ Skeleton3D *skeleton = nullptr;
+ Node3D *target_node_override = nullptr;
+ FabrikInverseKinematic::Task *task = nullptr;
protected:
virtual void
diff --git a/scene/3d/soft_body_3d.cpp b/scene/3d/soft_body_3d.cpp
index 850ffab292..91b8b5c859 100644
--- a/scene/3d/soft_body_3d.cpp
+++ b/scene/3d/soft_body_3d.cpp
@@ -97,9 +97,7 @@ void SoftBodyRenderingServerHandler::set_aabb(const AABB &p_aabb) {
RS::get_singleton()->mesh_set_custom_aabb(mesh, p_aabb);
}
-SoftBody3D::PinnedPoint::PinnedPoint() :
- point_index(-1),
- spatial_attachment(nullptr) {
+SoftBody3D::PinnedPoint::PinnedPoint() {
}
SoftBody3D::PinnedPoint::PinnedPoint(const PinnedPoint &obj_tocopy) {
@@ -702,13 +700,7 @@ bool SoftBody3D::is_ray_pickable() const {
}
SoftBody3D::SoftBody3D() :
- physics_rid(PhysicsServer3D::get_singleton()->soft_body_create()),
- mesh_owner(false),
- collision_mask(1),
- collision_layer(1),
- simulation_started(false),
- pinned_points_cache_dirty(true),
- ray_pickable(true) {
+ physics_rid(PhysicsServer3D::get_singleton()->soft_body_create()) {
PhysicsServer3D::get_singleton()->body_attach_object_instance_id(physics_rid, get_instance_id());
}
diff --git a/scene/3d/soft_body_3d.h b/scene/3d/soft_body_3d.h
index 7dd5880985..485f7427f8 100644
--- a/scene/3d/soft_body_3d.h
+++ b/scene/3d/soft_body_3d.h
@@ -68,9 +68,9 @@ class SoftBody3D : public MeshInstance3D {
public:
struct PinnedPoint {
- int point_index;
+ int point_index = -1;
NodePath spatial_attachment_path;
- Node3D *spatial_attachment; // Cache
+ Node3D *spatial_attachment = nullptr; // Cache
Vector3 offset;
PinnedPoint();
@@ -83,19 +83,19 @@ private:
RID physics_rid;
- bool mesh_owner;
- uint32_t collision_mask;
- uint32_t collision_layer;
+ bool mesh_owner = false;
+ uint32_t collision_mask = 1;
+ uint32_t collision_layer = 1;
NodePath parent_collision_ignore;
Vector<PinnedPoint> pinned_points;
- bool simulation_started;
- bool pinned_points_cache_dirty;
+ bool simulation_started = false;
+ bool pinned_points_cache_dirty = true;
Ref<ArrayMesh> debug_mesh_cache;
class MeshInstance3D *debug_mesh;
bool capture_input_on_drag;
- bool ray_pickable;
+ bool ray_pickable = true;
void _update_pickable();
diff --git a/scene/3d/spring_arm_3d.cpp b/scene/3d/spring_arm_3d.cpp
index 1410b730fd..f61e6eb2a7 100644
--- a/scene/3d/spring_arm_3d.cpp
+++ b/scene/3d/spring_arm_3d.cpp
@@ -29,18 +29,12 @@
/*************************************************************************/
#include "spring_arm_3d.h"
+
#include "core/engine.h"
#include "scene/3d/collision_object_3d.h"
#include "scene/resources/sphere_shape_3d.h"
#include "servers/physics_server_3d.h"
-SpringArm3D::SpringArm3D() :
- spring_length(1),
- current_spring_length(0),
- keep_child_basis(false),
- mask(1),
- margin(0.01) {}
-
void SpringArm3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
diff --git a/scene/3d/spring_arm_3d.h b/scene/3d/spring_arm_3d.h
index cb8a00ecf9..7f6fe2f1a2 100644
--- a/scene/3d/spring_arm_3d.h
+++ b/scene/3d/spring_arm_3d.h
@@ -38,11 +38,11 @@ class SpringArm3D : public Node3D {
Ref<Shape3D> shape;
Set<RID> excluded_objects;
- float spring_length;
- float current_spring_length;
- bool keep_child_basis;
- uint32_t mask;
- float margin;
+ float spring_length = 1;
+ float current_spring_length = 0;
+ bool keep_child_basis = false;
+ uint32_t mask = 1;
+ float margin = 0.01;
protected:
void _notification(int p_what);
@@ -62,7 +62,7 @@ public:
void set_margin(float p_margin);
float get_margin();
- SpringArm3D();
+ SpringArm3D() {}
private:
void process_spring();
diff --git a/scene/3d/vehicle_body_3d.cpp b/scene/3d/vehicle_body_3d.cpp
index 5c2fa59a21..66fcf0e40b 100644
--- a/scene/3d/vehicle_body_3d.cpp
+++ b/scene/3d/vehicle_body_3d.cpp
@@ -44,7 +44,7 @@ public:
real_t getDiagonal() const { return m_Adiag; }
- btVehicleJacobianEntry(){};
+ btVehicleJacobianEntry() {}
//constraint between two different rigidbodies
btVehicleJacobianEntry(
const Basis &world2A,
diff --git a/scene/3d/visual_instance_3d.cpp b/scene/3d/visual_instance_3d.cpp
index ce8672c1dd..4724c88a30 100644
--- a/scene/3d/visual_instance_3d.cpp
+++ b/scene/3d/visual_instance_3d.cpp
@@ -239,7 +239,17 @@ bool GeometryInstance3D::_set(const StringName &p_name, const Variant &p_value)
set_shader_instance_uniform(*r, p_value);
return true;
}
+#ifndef DISABLE_DEPRECATED
+ if (p_name == SceneStringNames::get_singleton()->use_in_baked_light && bool(p_value)) {
+ set_gi_mode(GI_MODE_BAKED);
+ return true;
+ }
+ if (p_name == SceneStringNames::get_singleton()->use_dynamic_gi && bool(p_value)) {
+ set_gi_mode(GI_MODE_DYNAMIC);
+ return true;
+ }
+#endif
return false;
}
@@ -273,23 +283,6 @@ void GeometryInstance3D::_get_property_list(List<PropertyInfo> *p_list) const {
}
}
-void GeometryInstance3D::set_flag(Flags p_flag, bool p_value) {
-
- ERR_FAIL_INDEX(p_flag, FLAG_MAX);
- if (flags[p_flag] == p_value)
- return;
-
- flags[p_flag] = p_value;
- RS::get_singleton()->instance_geometry_set_flag(get_instance(), (RS::InstanceFlags)p_flag, p_value);
-}
-
-bool GeometryInstance3D::get_flag(Flags p_flag) const {
-
- ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
-
- return flags[p_flag];
-}
-
void GeometryInstance3D::set_cast_shadows_setting(ShadowCastingSetting p_shadow_casting_setting) {
shadow_casting_setting = p_shadow_casting_setting;
@@ -335,14 +328,45 @@ void GeometryInstance3D::set_custom_aabb(AABB aabb) {
RS::get_singleton()->instance_set_custom_aabb(get_instance(), aabb);
}
+void GeometryInstance3D::set_lightmap_scale(LightmapScale p_scale) {
+ ERR_FAIL_INDEX(p_scale, LIGHTMAP_SCALE_MAX);
+ lightmap_scale = p_scale;
+}
+
+GeometryInstance3D::LightmapScale GeometryInstance3D::get_lightmap_scale() const {
+ return lightmap_scale;
+}
+
+void GeometryInstance3D::set_gi_mode(GIMode p_mode) {
+
+ switch (p_mode) {
+ case GI_MODE_DISABLED: {
+ RS::get_singleton()->instance_geometry_set_flag(get_instance(), RS::INSTANCE_FLAG_USE_BAKED_LIGHT, false);
+ RS::get_singleton()->instance_geometry_set_flag(get_instance(), RS::INSTANCE_FLAG_USE_DYNAMIC_GI, false);
+ } break;
+ case GI_MODE_BAKED: {
+ RS::get_singleton()->instance_geometry_set_flag(get_instance(), RS::INSTANCE_FLAG_USE_BAKED_LIGHT, true);
+ RS::get_singleton()->instance_geometry_set_flag(get_instance(), RS::INSTANCE_FLAG_USE_DYNAMIC_GI, false);
+
+ } break;
+ case GI_MODE_DYNAMIC: {
+ RS::get_singleton()->instance_geometry_set_flag(get_instance(), RS::INSTANCE_FLAG_USE_BAKED_LIGHT, false);
+ RS::get_singleton()->instance_geometry_set_flag(get_instance(), RS::INSTANCE_FLAG_USE_DYNAMIC_GI, true);
+ } break;
+ }
+
+ gi_mode = p_mode;
+}
+
+GeometryInstance3D::GIMode GeometryInstance3D::get_gi_mode() const {
+ return gi_mode;
+}
+
void GeometryInstance3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_material_override", "material"), &GeometryInstance3D::set_material_override);
ClassDB::bind_method(D_METHOD("get_material_override"), &GeometryInstance3D::get_material_override);
- ClassDB::bind_method(D_METHOD("set_flag", "flag", "value"), &GeometryInstance3D::set_flag);
- ClassDB::bind_method(D_METHOD("get_flag", "flag"), &GeometryInstance3D::get_flag);
-
ClassDB::bind_method(D_METHOD("set_cast_shadows_setting", "shadow_casting_setting"), &GeometryInstance3D::set_cast_shadows_setting);
ClassDB::bind_method(D_METHOD("get_cast_shadows_setting"), &GeometryInstance3D::get_cast_shadows_setting);
@@ -364,6 +388,12 @@ void GeometryInstance3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_extra_cull_margin", "margin"), &GeometryInstance3D::set_extra_cull_margin);
ClassDB::bind_method(D_METHOD("get_extra_cull_margin"), &GeometryInstance3D::get_extra_cull_margin);
+ ClassDB::bind_method(D_METHOD("set_lightmap_scale", "scale"), &GeometryInstance3D::set_lightmap_scale);
+ ClassDB::bind_method(D_METHOD("get_lightmap_scale"), &GeometryInstance3D::get_lightmap_scale);
+
+ ClassDB::bind_method(D_METHOD("set_gi_mode", "mode"), &GeometryInstance3D::set_gi_mode);
+ ClassDB::bind_method(D_METHOD("get_gi_mode"), &GeometryInstance3D::get_gi_mode);
+
ClassDB::bind_method(D_METHOD("set_custom_aabb", "aabb"), &GeometryInstance3D::set_custom_aabb);
ClassDB::bind_method(D_METHOD("get_aabb"), &GeometryInstance3D::get_aabb);
@@ -372,8 +402,9 @@ void GeometryInstance3D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material_override", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,StandardMaterial3D", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DEFERRED_SET_RESOURCE), "set_material_override", "get_material_override");
ADD_PROPERTY(PropertyInfo(Variant::INT, "cast_shadow", PROPERTY_HINT_ENUM, "Off,On,Double-Sided,Shadows Only"), "set_cast_shadows_setting", "get_cast_shadows_setting");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "extra_cull_margin", PROPERTY_HINT_RANGE, "0,16384,0.01"), "set_extra_cull_margin", "get_extra_cull_margin");
- ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "use_in_baked_light"), "set_flag", "get_flag", FLAG_USE_BAKED_LIGHT);
- ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "use_dynamic_gi"), "set_flag", "get_flag", FLAG_USE_DYNAMIC_GI);
+ ADD_GROUP("Global Illumination", "gi_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "gi_mode", PROPERTY_HINT_ENUM, "Disabled,Baked,Dynamic"), "set_gi_mode", "get_gi_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "gi_lightmap_scale", PROPERTY_HINT_ENUM, "1x,2x,4x,8x"), "set_lightmap_scale", "get_lightmap_scale");
ADD_GROUP("LOD", "lod_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "lod_min_distance", PROPERTY_HINT_RANGE, "0,32768,0.01"), "set_lod_min_distance", "get_lod_min_distance");
@@ -388,10 +419,15 @@ void GeometryInstance3D::_bind_methods() {
BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_DOUBLE_SIDED);
BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_SHADOWS_ONLY);
- BIND_ENUM_CONSTANT(FLAG_USE_BAKED_LIGHT);
- BIND_ENUM_CONSTANT(FLAG_USE_DYNAMIC_GI);
- BIND_ENUM_CONSTANT(FLAG_DRAW_NEXT_FRAME_IF_VISIBLE);
- BIND_ENUM_CONSTANT(FLAG_MAX);
+ BIND_ENUM_CONSTANT(GI_MODE_DISABLED);
+ BIND_ENUM_CONSTANT(GI_MODE_BAKED);
+ BIND_ENUM_CONSTANT(GI_MODE_DYNAMIC);
+
+ BIND_ENUM_CONSTANT(LIGHTMAP_SCALE_1X);
+ BIND_ENUM_CONSTANT(LIGHTMAP_SCALE_2X);
+ BIND_ENUM_CONSTANT(LIGHTMAP_SCALE_4X);
+ BIND_ENUM_CONSTANT(LIGHTMAP_SCALE_8X);
+ BIND_ENUM_CONSTANT(LIGHTMAP_SCALE_MAX);
}
GeometryInstance3D::GeometryInstance3D() {
@@ -400,9 +436,8 @@ GeometryInstance3D::GeometryInstance3D() {
lod_min_hysteresis = 0;
lod_max_hysteresis = 0;
- for (int i = 0; i < FLAG_MAX; i++) {
- flags[i] = false;
- }
+ gi_mode = GI_MODE_DISABLED;
+ lightmap_scale = LIGHTMAP_SCALE_1X;
shadow_casting_setting = SHADOW_CASTING_SETTING_ON;
extra_cull_margin = 0;
diff --git a/scene/3d/visual_instance_3d.h b/scene/3d/visual_instance_3d.h
index cc5f92066f..a871c65b6a 100644
--- a/scene/3d/visual_instance_3d.h
+++ b/scene/3d/visual_instance_3d.h
@@ -85,13 +85,6 @@ class GeometryInstance3D : public VisualInstance3D {
GDCLASS(GeometryInstance3D, VisualInstance3D);
public:
- enum Flags {
- FLAG_USE_BAKED_LIGHT = RS::INSTANCE_FLAG_USE_BAKED_LIGHT,
- FLAG_USE_DYNAMIC_GI = RS::INSTANCE_FLAG_USE_DYNAMIC_GI,
- FLAG_DRAW_NEXT_FRAME_IF_VISIBLE = RS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE,
- FLAG_MAX = RS::INSTANCE_FLAG_MAX,
- };
-
enum ShadowCastingSetting {
SHADOW_CASTING_SETTING_OFF = RS::SHADOW_CASTING_SETTING_OFF,
SHADOW_CASTING_SETTING_ON = RS::SHADOW_CASTING_SETTING_ON,
@@ -99,8 +92,21 @@ public:
SHADOW_CASTING_SETTING_SHADOWS_ONLY = RS::SHADOW_CASTING_SETTING_SHADOWS_ONLY
};
+ enum GIMode {
+ GI_MODE_DISABLED,
+ GI_MODE_BAKED,
+ GI_MODE_DYNAMIC
+ };
+
+ enum LightmapScale {
+ LIGHTMAP_SCALE_1X,
+ LIGHTMAP_SCALE_2X,
+ LIGHTMAP_SCALE_4X,
+ LIGHTMAP_SCALE_8X,
+ LIGHTMAP_SCALE_MAX,
+ };
+
private:
- bool flags[FLAG_MAX];
ShadowCastingSetting shadow_casting_setting;
Ref<Material> material_override;
float lod_min_distance;
@@ -112,6 +118,8 @@ private:
mutable HashMap<StringName, StringName> instance_uniform_property_remap;
float extra_cull_margin;
+ LightmapScale lightmap_scale;
+ GIMode gi_mode;
const StringName *_instance_uniform_get_remap(const StringName p_name) const;
@@ -124,9 +132,6 @@ protected:
static void _bind_methods();
public:
- void set_flag(Flags p_flag, bool p_value);
- bool get_flag(Flags p_flag) const;
-
void set_cast_shadows_setting(ShadowCastingSetting p_shadow_casting_setting);
ShadowCastingSetting get_cast_shadows_setting() const;
@@ -148,6 +153,12 @@ public:
void set_extra_cull_margin(float p_margin);
float get_extra_cull_margin() const;
+ void set_gi_mode(GIMode p_mode);
+ GIMode get_gi_mode() const;
+
+ void set_lightmap_scale(LightmapScale p_scale);
+ LightmapScale get_lightmap_scale() const;
+
void set_shader_instance_uniform(const StringName &p_uniform, const Variant &p_value);
Variant get_shader_instance_uniform(const StringName &p_uniform) const;
@@ -156,7 +167,8 @@ public:
GeometryInstance3D();
};
-VARIANT_ENUM_CAST(GeometryInstance3D::Flags);
VARIANT_ENUM_CAST(GeometryInstance3D::ShadowCastingSetting);
+VARIANT_ENUM_CAST(GeometryInstance3D::LightmapScale);
+VARIANT_ENUM_CAST(GeometryInstance3D::GIMode);
#endif
diff --git a/scene/3d/voxelizer.cpp b/scene/3d/voxelizer.cpp
index f30c58be55..f9c3810843 100644
--- a/scene/3d/voxelizer.cpp
+++ b/scene/3d/voxelizer.cpp
@@ -29,192 +29,12 @@
/*************************************************************************/
#include "voxelizer.h"
+#include "core/math/geometry.h"
#include "core/os/os.h"
#include "core/os/threaded_array_processor.h"
#include <stdlib.h>
-#define FINDMINMAX(x0, x1, x2, min, max) \
- min = max = x0; \
- if (x1 < min) min = x1; \
- if (x1 > max) max = x1; \
- if (x2 < min) min = x2; \
- if (x2 > max) max = x2;
-
-static bool planeBoxOverlap(Vector3 normal, float d, Vector3 maxbox) {
- int q;
- Vector3 vmin, vmax;
- for (q = 0; q <= 2; q++) {
- if (normal[q] > 0.0f) {
- vmin[q] = -maxbox[q];
- vmax[q] = maxbox[q];
- } else {
- vmin[q] = maxbox[q];
- vmax[q] = -maxbox[q];
- }
- }
- if (normal.dot(vmin) + d > 0.0f) return false;
- if (normal.dot(vmax) + d >= 0.0f) return true;
-
- return false;
-}
-
-/*======================== X-tests ========================*/
-#define AXISTEST_X01(a, b, fa, fb) \
- p0 = a * v0.y - b * v0.z; \
- p2 = a * v2.y - b * v2.z; \
- if (p0 < p2) { \
- min = p0; \
- max = p2; \
- } else { \
- min = p2; \
- max = p0; \
- } \
- rad = fa * boxhalfsize.y + fb * boxhalfsize.z; \
- if (min > rad || max < -rad) return false;
-
-#define AXISTEST_X2(a, b, fa, fb) \
- p0 = a * v0.y - b * v0.z; \
- p1 = a * v1.y - b * v1.z; \
- if (p0 < p1) { \
- min = p0; \
- max = p1; \
- } else { \
- min = p1; \
- max = p0; \
- } \
- rad = fa * boxhalfsize.y + fb * boxhalfsize.z; \
- if (min > rad || max < -rad) return false;
-
-/*======================== Y-tests ========================*/
-#define AXISTEST_Y02(a, b, fa, fb) \
- p0 = -a * v0.x + b * v0.z; \
- p2 = -a * v2.x + b * v2.z; \
- if (p0 < p2) { \
- min = p0; \
- max = p2; \
- } else { \
- min = p2; \
- max = p0; \
- } \
- rad = fa * boxhalfsize.x + fb * boxhalfsize.z; \
- if (min > rad || max < -rad) return false;
-
-#define AXISTEST_Y1(a, b, fa, fb) \
- p0 = -a * v0.x + b * v0.z; \
- p1 = -a * v1.x + b * v1.z; \
- if (p0 < p1) { \
- min = p0; \
- max = p1; \
- } else { \
- min = p1; \
- max = p0; \
- } \
- rad = fa * boxhalfsize.x + fb * boxhalfsize.z; \
- if (min > rad || max < -rad) return false;
-
-/*======================== Z-tests ========================*/
-
-#define AXISTEST_Z12(a, b, fa, fb) \
- p1 = a * v1.x - b * v1.y; \
- p2 = a * v2.x - b * v2.y; \
- if (p2 < p1) { \
- min = p2; \
- max = p1; \
- } else { \
- min = p1; \
- max = p2; \
- } \
- rad = fa * boxhalfsize.x + fb * boxhalfsize.y; \
- if (min > rad || max < -rad) return false;
-
-#define AXISTEST_Z0(a, b, fa, fb) \
- p0 = a * v0.x - b * v0.y; \
- p1 = a * v1.x - b * v1.y; \
- if (p0 < p1) { \
- min = p0; \
- max = p1; \
- } else { \
- min = p1; \
- max = p0; \
- } \
- rad = fa * boxhalfsize.x + fb * boxhalfsize.y; \
- if (min > rad || max < -rad) return false;
-
-static bool fast_tri_box_overlap(const Vector3 &boxcenter, const Vector3 boxhalfsize, const Vector3 *triverts) {
-
- /* use separating axis theorem to test overlap between triangle and box */
- /* need to test for overlap in these directions: */
- /* 1) the {x,y,z}-directions (actually, since we use the AABB of the triangle */
- /* we do not even need to test these) */
- /* 2) normal of the triangle */
- /* 3) crossproduct(edge from tri, {x,y,z}-directin) */
- /* this gives 3x3=9 more tests */
- Vector3 v0, v1, v2;
- float min, max, d, p0, p1, p2, rad, fex, fey, fez;
- Vector3 normal, e0, e1, e2;
-
- /* This is the fastest branch on Sun */
- /* move everything so that the boxcenter is in (0,0,0) */
-
- v0 = triverts[0] - boxcenter;
- v1 = triverts[1] - boxcenter;
- v2 = triverts[2] - boxcenter;
-
- /* compute triangle edges */
- e0 = v1 - v0; /* tri edge 0 */
- e1 = v2 - v1; /* tri edge 1 */
- e2 = v0 - v2; /* tri edge 2 */
-
- /* Bullet 3: */
- /* test the 9 tests first (this was faster) */
- fex = Math::abs(e0.x);
- fey = Math::abs(e0.y);
- fez = Math::abs(e0.z);
- AXISTEST_X01(e0.z, e0.y, fez, fey);
- AXISTEST_Y02(e0.z, e0.x, fez, fex);
- AXISTEST_Z12(e0.y, e0.x, fey, fex);
-
- fex = Math::abs(e1.x);
- fey = Math::abs(e1.y);
- fez = Math::abs(e1.z);
- AXISTEST_X01(e1.z, e1.y, fez, fey);
- AXISTEST_Y02(e1.z, e1.x, fez, fex);
- AXISTEST_Z0(e1.y, e1.x, fey, fex);
-
- fex = Math::abs(e2.x);
- fey = Math::abs(e2.y);
- fez = Math::abs(e2.z);
- AXISTEST_X2(e2.z, e2.y, fez, fey);
- AXISTEST_Y1(e2.z, e2.x, fez, fex);
- AXISTEST_Z12(e2.y, e2.x, fey, fex);
-
- /* Bullet 1: */
- /* first test overlap in the {x,y,z}-directions */
- /* find min, max of the triangle each direction, and test for overlap in */
- /* that direction -- this is equivalent to testing a minimal AABB around */
- /* the triangle against the AABB */
-
- /* test in X-direction */
- FINDMINMAX(v0.x, v1.x, v2.x, min, max);
- if (min > boxhalfsize.x || max < -boxhalfsize.x) return false;
-
- /* test in Y-direction */
- FINDMINMAX(v0.y, v1.y, v2.y, min, max);
- if (min > boxhalfsize.y || max < -boxhalfsize.y) return false;
-
- /* test in Z-direction */
- FINDMINMAX(v0.z, v1.z, v2.z, min, max);
- if (min > boxhalfsize.z || max < -boxhalfsize.z) return false;
-
- /* Bullet 2: */
- /* test if the box intersects the plane of the triangle */
- /* compute plane equation of triangle: normal*x+d=0 */
- normal = e0.cross(e1);
- d = -normal.dot(v0); /* plane eq: normal.x+d=0 */
- return planeBoxOverlap(normal, d, boxhalfsize); /* if true, box and triangle overlaps */
-}
-
static _FORCE_INLINE_ void get_uv_and_normal(const Vector3 &p_pos, const Vector3 *p_vtx, const Vector2 *p_uv, const Vector3 *p_normal, Vector2 &r_uv, Vector3 &r_normal) {
if (p_pos.distance_squared_to(p_vtx[0]) < CMP_EPSILON2) {
@@ -309,7 +129,7 @@ void Voxelizer::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, co
Vector3 half = (to - from) * 0.5;
//is in this cell?
- if (!fast_tri_box_overlap(from + half, half, p_vtx)) {
+ if (!Geometry::triangle_box_overlap(from + half, half, p_vtx)) {
continue; //face does not span this cell
}
@@ -452,7 +272,7 @@ void Voxelizer::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, co
//test_aabb.grow_by(test_aabb.get_longest_axis_size()*0.05); //grow a bit to avoid numerical error in real-time
Vector3 qsize = test_aabb.size * 0.5; //quarter size, for fast aabb test
- if (!fast_tri_box_overlap(test_aabb.position + qsize, qsize, p_vtx)) {
+ if (!Geometry::triangle_box_overlap(test_aabb.position + qsize, qsize, p_vtx)) {
//if (!Face3(p_vtx[0],p_vtx[1],p_vtx[2]).intersects_aabb2(aabb)) {
//does not fit in child, go on
continue;
@@ -633,7 +453,7 @@ void Voxelizer::plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, const Vec
}
//test against original bounds
- if (!fast_tri_box_overlap(original_bounds.position + original_bounds.size * 0.5, original_bounds.size * 0.5, vtxs))
+ if (!Geometry::triangle_box_overlap(original_bounds.position + original_bounds.size * 0.5, original_bounds.size * 0.5, vtxs))
continue;
//plot
_plot_face(0, 0, 0, 0, 0, vtxs, normal, uvs, material, po2_bounds);
@@ -666,7 +486,7 @@ void Voxelizer::plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, const Vec
}
//test against original bounds
- if (!fast_tri_box_overlap(original_bounds.position + original_bounds.size * 0.5, original_bounds.size * 0.5, vtxs))
+ if (!Geometry::triangle_box_overlap(original_bounds.position + original_bounds.size * 0.5, original_bounds.size * 0.5, vtxs))
continue;
//plot face
_plot_face(0, 0, 0, 0, 0, vtxs, normal, uvs, material, po2_bounds);
diff --git a/scene/3d/xr_nodes.cpp b/scene/3d/xr_nodes.cpp
index 6f41629bac..1b13b64744 100644
--- a/scene/3d/xr_nodes.cpp
+++ b/scene/3d/xr_nodes.cpp
@@ -269,11 +269,11 @@ void XRController3D::set_controller_id(int p_controller_id) {
update_configuration_warning();
};
-int XRController3D::get_controller_id(void) const {
+int XRController3D::get_controller_id() const {
return controller_id;
};
-String XRController3D::get_controller_name(void) const {
+String XRController3D::get_controller_name() const {
// get our XRServer
XRServer *xr_server = XRServer::get_singleton();
ERR_FAIL_NULL_V(xr_server, String());
@@ -465,7 +465,7 @@ void XRAnchor3D::set_anchor_id(int p_anchor_id) {
update_configuration_warning();
};
-int XRAnchor3D::get_anchor_id(void) const {
+int XRAnchor3D::get_anchor_id() const {
return anchor_id;
};
@@ -473,7 +473,7 @@ Vector3 XRAnchor3D::get_size() const {
return size;
};
-String XRAnchor3D::get_anchor_name(void) const {
+String XRAnchor3D::get_anchor_name() const {
// get our XRServer
XRServer *xr_server = XRServer::get_singleton();
ERR_FAIL_NULL_V(xr_server, String());
diff --git a/scene/3d/xr_nodes.h b/scene/3d/xr_nodes.h
index a2f16545d1..55dcfe087e 100644
--- a/scene/3d/xr_nodes.h
+++ b/scene/3d/xr_nodes.h
@@ -84,8 +84,8 @@ protected:
public:
void set_controller_id(int p_controller_id);
- int get_controller_id(void) const;
- String get_controller_name(void) const;
+ int get_controller_id() const;
+ String get_controller_name() const;
int get_joystick_id() const;
bool is_button_pressed(int p_button) const;
@@ -97,7 +97,7 @@ public:
bool get_is_active() const;
XRPositionalTracker::TrackerHand get_hand() const;
- Ref<Mesh> get_mesh(void) const;
+ Ref<Mesh> get_mesh() const;
String get_configuration_warning() const;
@@ -125,15 +125,15 @@ protected:
public:
void set_anchor_id(int p_anchor_id);
- int get_anchor_id(void) const;
- String get_anchor_name(void) const;
+ int get_anchor_id() const;
+ String get_anchor_name() const;
bool get_is_active() const;
Vector3 get_size() const;
Plane get_plane() const;
- Ref<Mesh> get_mesh(void) const;
+ Ref<Mesh> get_mesh() const;
String get_configuration_warning() const;
diff --git a/scene/animation/animation_blend_space_2d.cpp b/scene/animation/animation_blend_space_2d.cpp
index 638531df41..ad60249f9a 100644
--- a/scene/animation/animation_blend_space_2d.cpp
+++ b/scene/animation/animation_blend_space_2d.cpp
@@ -29,7 +29,8 @@
/*************************************************************************/
#include "animation_blend_space_2d.h"
-#include "core/math/delaunay.h"
+
+#include "core/math/delaunay_2d.h"
void AnimationNodeBlendSpace2D::get_parameter_list(List<PropertyInfo> *r_list) const {
r_list->push_back(PropertyInfo(Variant::VECTOR2, blend_position));
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp
index 8228cf67bd..7bac09f839 100644
--- a/scene/animation/animation_player.cpp
+++ b/scene/animation/animation_player.cpp
@@ -1479,9 +1479,14 @@ void AnimationPlayer::_set_process(bool p_process, bool p_force) {
switch (animation_process_mode) {
- case ANIMATION_PROCESS_PHYSICS: set_physics_process_internal(p_process && active); break;
- case ANIMATION_PROCESS_IDLE: set_process_internal(p_process && active); break;
- case ANIMATION_PROCESS_MANUAL: break;
+ case ANIMATION_PROCESS_PHYSICS:
+ set_physics_process_internal(p_process && active);
+ break;
+ case ANIMATION_PROCESS_IDLE:
+ set_process_internal(p_process && active);
+ break;
+ case ANIMATION_PROCESS_MANUAL:
+ break;
}
processing = p_process;
diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h
index c134aff707..d709082f62 100644
--- a/scene/animation/animation_player.h
+++ b/scene/animation/animation_player.h
@@ -87,41 +87,37 @@ private:
struct TrackNodeCache {
NodePath path;
- uint32_t id;
+ uint32_t id = 0;
RES resource;
- Node *node;
- Node3D *spatial;
- Node2D *node_2d;
- Skeleton3D *skeleton;
- int bone_idx;
+ Node *node = nullptr;
+ Node3D *spatial = nullptr;
+ Node2D *node_2d = nullptr;
+ Skeleton3D *skeleton = nullptr;
+ int bone_idx = -1;
// accumulated transforms
Vector3 loc_accum;
Quat rot_accum;
Vector3 scale_accum;
- uint64_t accum_pass;
+ uint64_t accum_pass = 0;
- bool audio_playing;
- float audio_start;
- float audio_len;
+ bool audio_playing = false;
+ float audio_start = 0.0;
+ float audio_len = 0.0;
- bool animation_playing;
+ bool animation_playing = false;
struct PropertyAnim {
- TrackNodeCache *owner;
- SpecialProperty special; //small optimization
+ TrackNodeCache *owner = nullptr;
+ SpecialProperty special = SP_NONE; //small optimization
Vector<StringName> subpath;
- Object *object;
+ Object *object = nullptr;
Variant value_accum;
- uint64_t accum_pass;
+ uint64_t accum_pass = 0;
Variant capture;
- PropertyAnim() :
- owner(nullptr),
- special(SP_NONE),
- object(nullptr),
- accum_pass(0) {}
+ PropertyAnim() {}
};
Map<StringName, PropertyAnim> property_anim;
@@ -129,32 +125,17 @@ private:
struct BezierAnim {
Vector<StringName> bezier_property;
- TrackNodeCache *owner;
- float bezier_accum;
- Object *object;
- uint64_t accum_pass;
-
- BezierAnim() :
- owner(nullptr),
- bezier_accum(0.0),
- object(nullptr),
- accum_pass(0) {}
+ TrackNodeCache *owner = nullptr;
+ float bezier_accum = 0.0;
+ Object *object = nullptr;
+ uint64_t accum_pass = 0;
+
+ BezierAnim() {}
};
Map<StringName, BezierAnim> bezier_anim;
- TrackNodeCache() :
- id(0),
- node(nullptr),
- spatial(nullptr),
- node_2d(nullptr),
- skeleton(nullptr),
- bone_idx(-1),
- accum_pass(0),
- audio_playing(false),
- audio_start(0.0),
- audio_len(0.0),
- animation_playing(false) {}
+ TrackNodeCache() {}
};
struct TrackNodeCacheKey {
diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp
index d0c6cac8cf..b826907a3a 100644
--- a/scene/animation/tween.cpp
+++ b/scene/animation/tween.cpp
@@ -353,7 +353,8 @@ Variant Tween::_get_final_val(const InterpolateData &p_data) const {
// If we're looking at an INT value, instead convert it to a FLOAT
// This is better for interpolation
- if (final_val.get_type() == Variant::INT) final_val = final_val.operator real_t();
+ if (final_val.get_type() == Variant::INT)
+ final_val = final_val.operator real_t();
return final_val;
}
@@ -395,7 +396,8 @@ Variant &Tween::_get_delta_val(InterpolateData &p_data) {
// If we're looking at an INT value, instead convert it to a FLOAT
// This is better for interpolation
- if (final_val.get_type() == Variant::INT) final_val = final_val.operator real_t();
+ if (final_val.get_type() == Variant::INT)
+ final_val = final_val.operator real_t();
// Calculate the delta based on the initial value and the final value
_calc_delta_val(p_data.initial_val, final_val, p_data.delta_val);
@@ -409,7 +411,8 @@ Variant &Tween::_get_delta_val(InterpolateData &p_data) {
// If we're looking at an INT value, instead convert it to a FLOAT
// This is better for interpolation
- if (initial_val.get_type() == Variant::INT) initial_val = initial_val.operator real_t();
+ if (initial_val.get_type() == Variant::INT)
+ initial_val = initial_val.operator real_t();
// Calculate the delta based on the initial value and the final value
_calc_delta_val(initial_val, p_data.final_val, p_data.delta_val);
@@ -823,8 +826,12 @@ void Tween::set_active(bool p_active) {
// Depending on physics or idle, set processing
switch (tween_process_mode) {
- case TWEEN_PROCESS_IDLE: set_process_internal(p_active); break;
- case TWEEN_PROCESS_PHYSICS: set_physics_process_internal(p_active); break;
+ case TWEEN_PROCESS_IDLE:
+ set_process_internal(p_active);
+ break;
+ case TWEEN_PROCESS_PHYSICS:
+ set_physics_process_internal(p_active);
+ break;
}
}
@@ -1334,11 +1341,14 @@ void Tween::interpolate_property(Object *p_object, NodePath p_property, Variant
// If no initial value given, grab the initial value from the object
// TODO: Is this documented? This is very useful and removes a lot of clutter from tweens!
- if (p_initial_val.get_type() == Variant::NIL) p_initial_val = p_object->get_indexed(p_property.get_subnames());
+ if (p_initial_val.get_type() == Variant::NIL)
+ p_initial_val = p_object->get_indexed(p_property.get_subnames());
// Convert any integers into REALs as they are better for interpolation
- if (p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t();
- if (p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t();
+ if (p_initial_val.get_type() == Variant::INT)
+ p_initial_val = p_initial_val.operator real_t();
+ if (p_final_val.get_type() == Variant::INT)
+ p_final_val = p_final_val.operator real_t();
// Build the interpolation data
_build_interpolation(INTER_PROPERTY, p_object, &p_property, nullptr, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay);
@@ -1352,8 +1362,10 @@ void Tween::interpolate_method(Object *p_object, StringName p_method, Variant p_
}
// Convert any integers into REALs as they are better for interpolation
- if (p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t();
- if (p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t();
+ if (p_initial_val.get_type() == Variant::INT)
+ p_initial_val = p_initial_val.operator real_t();
+ if (p_final_val.get_type() == Variant::INT)
+ p_final_val = p_final_val.operator real_t();
// Build the interpolation data
_build_interpolation(INTER_METHOD, p_object, nullptr, &p_method, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay);
@@ -1486,10 +1498,12 @@ void Tween::follow_property(Object *p_object, NodePath p_property, Variant p_ini
// If no initial value is given, grab it from the source object
// TODO: Is this documented? It's really helpful for decluttering tweens
- if (p_initial_val.get_type() == Variant::NIL) p_initial_val = p_object->get_indexed(p_property.get_subnames());
+ if (p_initial_val.get_type() == Variant::NIL)
+ p_initial_val = p_object->get_indexed(p_property.get_subnames());
// Convert initial INT values to FLOAT as they are better for interpolation
- if (p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t();
+ if (p_initial_val.get_type() == Variant::INT)
+ p_initial_val = p_initial_val.operator real_t();
// Confirm the source and target objects are valid
ERR_FAIL_COND(p_object == nullptr);
@@ -1515,7 +1529,8 @@ void Tween::follow_property(Object *p_object, NodePath p_property, Variant p_ini
ERR_FAIL_COND(!target_prop_valid);
// Convert target INT to FLOAT since it is better for interpolation
- if (target_val.get_type() == Variant::INT) target_val = target_val.operator real_t();
+ if (target_val.get_type() == Variant::INT)
+ target_val = target_val.operator real_t();
// Verify that the target value and initial value are the same type
ERR_FAIL_COND(target_val.get_type() != p_initial_val.get_type());
@@ -1550,7 +1565,8 @@ void Tween::follow_method(Object *p_object, StringName p_method, Variant p_initi
return;
}
// Convert initial INT values to FLOAT as they are better for interpolation
- if (p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t();
+ if (p_initial_val.get_type() == Variant::INT)
+ p_initial_val = p_initial_val.operator real_t();
// Verify the source and target objects are valid
ERR_FAIL_COND(p_object == nullptr);
@@ -1576,7 +1592,8 @@ void Tween::follow_method(Object *p_object, StringName p_method, Variant p_initi
ERR_FAIL_COND(error.error != Callable::CallError::CALL_OK);
// Convert target INT values to FLOAT as they are better for interpolation
- if (target_val.get_type() == Variant::INT) target_val = target_val.operator real_t();
+ if (target_val.get_type() == Variant::INT)
+ target_val = target_val.operator real_t();
ERR_FAIL_COND(target_val.get_type() != p_initial_val.get_type());
// Make the new InterpolateData for the method follow
@@ -1613,7 +1630,8 @@ void Tween::targeting_property(Object *p_object, NodePath p_property, Object *p_
p_initial_property = p_initial_property.get_as_property_path();
// Convert the initial INT values to FLOAT as they are better for Interpolation
- if (p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t();
+ if (p_final_val.get_type() == Variant::INT)
+ p_final_val = p_final_val.operator real_t();
// Verify both objects are valid
ERR_FAIL_COND(p_object == nullptr);
@@ -1639,7 +1657,8 @@ void Tween::targeting_property(Object *p_object, NodePath p_property, Object *p_
ERR_FAIL_COND(!initial_prop_valid);
// Convert the initial INT value to FLOAT as it is better for interpolation
- if (initial_val.get_type() == Variant::INT) initial_val = initial_val.operator real_t();
+ if (initial_val.get_type() == Variant::INT)
+ initial_val = initial_val.operator real_t();
ERR_FAIL_COND(initial_val.get_type() != p_final_val.get_type());
// Build the InterpolateData object
@@ -1679,7 +1698,8 @@ void Tween::targeting_method(Object *p_object, StringName p_method, Object *p_in
}
// Convert final INT values to FLOAT as they are better for interpolation
- if (p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t();
+ if (p_final_val.get_type() == Variant::INT)
+ p_final_val = p_final_val.operator real_t();
// Make sure the given objects are valid
ERR_FAIL_COND(p_object == nullptr);
@@ -1705,7 +1725,8 @@ void Tween::targeting_method(Object *p_object, StringName p_method, Object *p_in
ERR_FAIL_COND(error.error != Callable::CallError::CALL_OK);
// Convert initial INT values to FLOAT as they aer better for interpolation
- if (initial_val.get_type() == Variant::INT) initial_val = initial_val.operator real_t();
+ if (initial_val.get_type() == Variant::INT)
+ initial_val = initial_val.operator real_t();
ERR_FAIL_COND(initial_val.get_type() != p_final_val.get_type());
// Build the new InterpolateData object
diff --git a/scene/debugger/scene_debugger.h b/scene/debugger/scene_debugger.h
index e295510960..e8521d6a20 100644
--- a/scene/debugger/scene_debugger.h
+++ b/scene/debugger/scene_debugger.h
@@ -100,7 +100,7 @@ public:
void serialize(Array &r_arr);
void deserialize(const Array &p_arr);
SceneDebuggerTree(Node *p_root);
- SceneDebuggerTree(){};
+ SceneDebuggerTree() {}
};
class LiveEditor {
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index 89d13ecd7f..a449d680a8 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -410,7 +410,8 @@ void FileDialog::_tree_item_activated() {
void FileDialog::update_file_name() {
int idx = filter->get_selected() - 1;
if ((idx == -1 && filter->get_item_count() == 2) || (filter->get_item_count() > 2 && idx >= 0 && idx < filter->get_item_count() - 2)) {
- if (idx == -1) idx += 1;
+ if (idx == -1)
+ idx += 1;
String filter_str = filters[idx];
String file_str = file->get_text();
String base_name = file_str.get_basename();
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index bedcef2df2..7490101ee3 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "label.h"
+
#include "core/print_string.h"
#include "core/project_settings.h"
#include "core/translation.h"
@@ -693,24 +694,8 @@ void Label::_bind_methods() {
}
Label::Label(const String &p_text) {
-
- align = ALIGN_LEFT;
- valign = VALIGN_TOP;
- xl_text = "";
- word_cache = nullptr;
- word_cache_dirty = true;
- autowrap = false;
- line_count = 0;
- set_v_size_flags(0);
- clip = false;
set_mouse_filter(MOUSE_FILTER_IGNORE);
- total_char_cache = 0;
- visible_chars = -1;
- percent_visible = 1;
- lines_skipped = 0;
- max_lines_visible = -1;
set_text(p_text);
- uppercase = false;
set_v_size_flags(SIZE_SHRINK_CENTER);
}
diff --git a/scene/gui/label.h b/scene/gui/label.h
index ba6e627c58..0f84b01604 100644
--- a/scene/gui/label.h
+++ b/scene/gui/label.h
@@ -55,15 +55,15 @@ public:
};
private:
- Align align;
- VAlign valign;
+ Align align = ALIGN_LEFT;
+ VAlign valign = VALIGN_TOP;
String text;
String xl_text;
- bool autowrap;
- bool clip;
+ bool autowrap = false;
+ bool clip = false;
Size2 minsize;
- int line_count;
- bool uppercase;
+ int line_count = 0;
+ bool uppercase = false;
int get_longest_line_width() const;
@@ -73,30 +73,23 @@ private:
CHAR_NEWLINE = -1,
CHAR_WRAPLINE = -2
};
- int char_pos; // if -1, then newline
- int word_len;
- int pixel_width;
- int space_count;
- WordCache *next;
- WordCache() {
- char_pos = 0;
- word_len = 0;
- pixel_width = 0;
- next = 0;
- space_count = 0;
- }
+ int char_pos = 0; // if -1, then newline
+ int word_len = 0;
+ int pixel_width = 0;
+ int space_count = 0;
+ WordCache *next = nullptr;
};
- bool word_cache_dirty;
+ bool word_cache_dirty = true;
void regenerate_word_cache();
- float percent_visible;
+ float percent_visible = 1;
- WordCache *word_cache;
- int total_char_cache;
- int visible_chars;
- int lines_skipped;
- int max_lines_visible;
+ WordCache *word_cache = nullptr;
+ int total_char_cache = 0;
+ int visible_chars = -1;
+ int lines_skipped = 0;
+ int max_lines_visible = -1;
protected:
void _notification(int p_what);
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index b9b7560f2e..bb177ae0e7 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -277,10 +277,14 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
} break;
#ifdef APPLE_STYLE_KEYS
case (KEY_LEFT): { // Go to start of text - like HOME key.
+ shift_selection_check_pre(k->get_shift());
set_cursor_position(0);
+ shift_selection_check_post(k->get_shift());
} break;
case (KEY_RIGHT): { // Go to end of text - like END key.
+ shift_selection_check_pre(k->get_shift());
set_cursor_position(text.length());
+ shift_selection_check_post(k->get_shift());
} break;
#endif
default: {
@@ -463,14 +467,16 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
case KEY_UP: {
shift_selection_check_pre(k->get_shift());
- if (get_cursor_position() == 0) handled = false;
+ if (get_cursor_position() == 0)
+ handled = false;
set_cursor_position(0);
shift_selection_check_post(k->get_shift());
} break;
case KEY_DOWN: {
shift_selection_check_pre(k->get_shift());
- if (get_cursor_position() == text.length()) handled = false;
+ if (get_cursor_position() == text.length())
+ handled = false;
set_cursor_position(text.length());
shift_selection_check_post(k->get_shift());
} break;
@@ -988,7 +994,8 @@ void LineEdit::paste_text() {
if (paste_buffer != "") {
int prev_len = text.length();
- if (selection.enabled) selection_delete();
+ if (selection.enabled)
+ selection_delete();
append_at_cursor(paste_buffer);
if (!text_changed_dirty) {
@@ -1204,7 +1211,8 @@ void LineEdit::_toggle_draw_caret() {
void LineEdit::delete_char() {
- if ((text.length() <= 0) || (cursor_pos == 0)) return;
+ if ((text.length() <= 0) || (cursor_pos == 0))
+ return;
Ref<Font> font = get_theme_font("font");
if (font != nullptr) {
@@ -1379,7 +1387,8 @@ int LineEdit::get_cursor_position() const {
void LineEdit::set_window_pos(int p_pos) {
window_pos = p_pos;
- if (window_pos < 0) window_pos = 0;
+ if (window_pos < 0)
+ window_pos = 0;
}
void LineEdit::append_at_cursor(String p_text) {
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index 84097eb6a1..a6c0c99bdb 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -230,10 +230,18 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
} else { \
int used = wofs - margin; \
switch (align) { \
- case ALIGN_LEFT: l.offset_caches.push_back(0); break; \
- case ALIGN_CENTER: l.offset_caches.push_back(((p_width - margin) - used) / 2); break; \
- case ALIGN_RIGHT: l.offset_caches.push_back(((p_width - margin) - used)); break; \
- case ALIGN_FILL: l.offset_caches.push_back(line_wrapped ? ((p_width - margin) - used) : 0); break; \
+ case ALIGN_LEFT: \
+ l.offset_caches.push_back(0); \
+ break; \
+ case ALIGN_CENTER: \
+ l.offset_caches.push_back(((p_width - margin) - used) / 2); \
+ break; \
+ case ALIGN_RIGHT: \
+ l.offset_caches.push_back(((p_width - margin) - used)); \
+ break; \
+ case ALIGN_FILL: \
+ l.offset_caches.push_back(line_wrapped ? ((p_width - margin) - used) : 0); \
+ break; \
} \
l.height_caches.push_back(line_height); \
l.ascent_caches.push_back(line_ascent); \
@@ -255,7 +263,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
line_descent = line < l.descent_caches.size() ? l.descent_caches[line] : 1; \
} \
if (p_mode == PROCESS_POINTER && r_click_item && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh && p_click_pos.x < p_ofs.x + wofs) { \
- if (r_outside) *r_outside = true; \
+ if (r_outside) \
+ *r_outside = true; \
*r_click_item = it; \
*r_click_char = rchar; \
RETURN; \
@@ -275,7 +284,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
} \
const bool x_in_range = (p_click_pos.x > p_ofs.x + wofs) && (!p_frame->cell || p_click_pos.x < p_ofs.x + p_width); \
if (p_mode == PROCESS_POINTER && r_click_item && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh && x_in_range) { \
- if (r_outside) *r_outside = true; \
+ if (r_outside) \
+ *r_outside = true; \
*r_click_item = it; \
*r_click_char = rchar; \
RETURN; \
@@ -286,7 +296,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
#define ADVANCE(m_width) \
{ \
if (p_mode == PROCESS_POINTER && r_click_item && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh && p_click_pos.x >= p_ofs.x + wofs && p_click_pos.x < p_ofs.x + wofs + m_width) { \
- if (r_outside) *r_outside = false; \
+ if (r_outside) \
+ *r_outside = false; \
*r_click_item = it; \
*r_click_char = rchar; \
RETURN; \
@@ -855,7 +866,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
if (p_mode == PROCESS_POINTER && r_click_item && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh) {
//went to next line, but pointer was on the previous one
- if (r_outside) *r_outside = true;
+ if (r_outside)
+ *r_outside = true;
*r_click_item = itp;
*r_click_char = rchar;
RETURN;
diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp
index 1f135163d4..910d5f8230 100644
--- a/scene/gui/slider.cpp
+++ b/scene/gui/slider.cpp
@@ -182,7 +182,8 @@ void Slider::_notification(int p_what) {
if (ticks > 1) {
int grabber_offset = (grabber->get_size().height / 2 - tick->get_height() / 2);
for (int i = 0; i < ticks; i++) {
- if (!ticks_on_borders && (i == 0 || i + 1 == ticks)) continue;
+ if (!ticks_on_borders && (i == 0 || i + 1 == ticks))
+ continue;
int ofs = (i * areasize / (ticks - 1)) + grabber_offset;
tick->draw(ci, Point2i((size.width - widget_width) / 2, ofs));
}
@@ -199,7 +200,8 @@ void Slider::_notification(int p_what) {
if (ticks > 1) {
int grabber_offset = (grabber->get_size().width / 2 - tick->get_width() / 2);
for (int i = 0; i < ticks; i++) {
- if ((!ticks_on_borders) && ((i == 0) || ((i + 1) == ticks))) continue;
+ if ((!ticks_on_borders) && ((i == 0) || ((i + 1) == ticks)))
+ continue;
int ofs = (i * areasize / (ticks - 1)) + grabber_offset;
tick->draw(ci, Point2i(ofs, (size.height - widget_height) / 2));
}
diff --git a/scene/gui/subviewport_container.cpp b/scene/gui/subviewport_container.cpp
index 50f468741d..7252a43651 100644
--- a/scene/gui/subviewport_container.cpp
+++ b/scene/gui/subviewport_container.cpp
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* subviewport_container.cpp */
+/* subviewport_container.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
diff --git a/scene/gui/subviewport_container.h b/scene/gui/subviewport_container.h
index 6ff3d188e2..13b711f838 100644
--- a/scene/gui/subviewport_container.h
+++ b/scene/gui/subviewport_container.h
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* subviewport_container.h */
+/* subviewport_container.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp
index 1a3b53f489..b856d3ab3a 100644
--- a/scene/gui/tabs.cpp
+++ b/scene/gui/tabs.cpp
@@ -399,7 +399,8 @@ int Tabs::get_tab_count() const {
void Tabs::set_current_tab(int p_current) {
- if (current == p_current) return;
+ if (current == p_current)
+ return;
ERR_FAIL_INDEX(p_current, get_tab_count());
current = p_current;
@@ -856,7 +857,8 @@ void Tabs::ensure_tab_visible(int p_idx) {
if (!is_inside_tree())
return;
- if (tabs.size() == 0) return;
+ if (tabs.size() == 0)
+ return;
ERR_FAIL_INDEX(p_idx, tabs.size());
if (p_idx == offset) {
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index aa518fbb7d..e986e350f3 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -941,7 +941,7 @@ void TextEdit::_notification(int p_what) {
// calculate viewport size and y offset
int viewport_height = (draw_amount - 1) * minimap_line_height;
int control_height = _get_control_height() - viewport_height;
- int viewport_offset_y = round(get_scroll_pos_for_line(first_visible_line) * control_height) / ((v_scroll->get_max() <= minimap_visible_lines) ? (minimap_visible_lines - draw_amount) : (v_scroll->get_max() - draw_amount));
+ int viewport_offset_y = round(get_scroll_pos_for_line(first_visible_line + 1) * control_height) / ((v_scroll->get_max() <= minimap_visible_lines) ? (minimap_visible_lines - draw_amount) : (v_scroll->get_max() - draw_amount));
// calculate the first line.
int num_lines_before = round((viewport_offset_y) / minimap_line_height);
@@ -2991,7 +2991,8 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
} break;
case KEY_TAB: {
- if (k->get_command()) break; // Avoid tab when command.
+ if (k->get_command())
+ break; // Avoid tab when command.
if (readonly)
break;
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 329c1085df..4a550727fc 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -2277,7 +2277,8 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
bool is_command = k.is_valid() && k->get_command();
if (p_event->is_action("ui_right") && p_event->is_pressed()) {
- if (!cursor_can_exit_tree) accept_event();
+ if (!cursor_can_exit_tree)
+ accept_event();
if (!selected_item || select_mode == SELECT_ROW || selected_col > (columns.size() - 1)) {
return;
@@ -2294,7 +2295,8 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
}
} else if (p_event->is_action("ui_left") && p_event->is_pressed()) {
- if (!cursor_can_exit_tree) accept_event();
+ if (!cursor_can_exit_tree)
+ accept_event();
if (!selected_item || select_mode == SELECT_ROW || selected_col < 0) {
return;
@@ -2313,19 +2315,22 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
} else if (p_event->is_action("ui_up") && p_event->is_pressed() && !is_command) {
- if (!cursor_can_exit_tree) accept_event();
+ if (!cursor_can_exit_tree)
+ accept_event();
_go_up();
} else if (p_event->is_action("ui_down") && p_event->is_pressed() && !is_command) {
- if (!cursor_can_exit_tree) accept_event();
+ if (!cursor_can_exit_tree)
+ accept_event();
_go_down();
} else if (p_event->is_action("ui_page_down") && p_event->is_pressed()) {
- if (!cursor_can_exit_tree) accept_event();
+ if (!cursor_can_exit_tree)
+ accept_event();
TreeItem *next = nullptr;
if (!selected_item)
@@ -2363,7 +2368,8 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
ensure_cursor_is_visible();
} else if (p_event->is_action("ui_page_up") && p_event->is_pressed()) {
- if (!cursor_can_exit_tree) accept_event();
+ if (!cursor_can_exit_tree)
+ accept_event();
TreeItem *prev = nullptr;
if (!selected_item)
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 87c2588a12..3c67a79558 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -544,7 +544,7 @@ public:
void clear();
- TreeItem *create_item(TreeItem *p_parent = 0, int p_idx = -1);
+ TreeItem *create_item(TreeItem *p_parent = nullptr, int p_idx = -1);
TreeItem *get_root();
TreeItem *get_last_item();
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp
index b5d54b2199..e91826d44b 100644
--- a/scene/main/canvas_item.cpp
+++ b/scene/main/canvas_item.cpp
@@ -95,18 +95,35 @@ void CanvasItemMaterial::_update_shader() {
String code = "shader_type canvas_item;\nrender_mode ";
switch (blend_mode) {
- case BLEND_MODE_MIX: code += "blend_mix"; break;
- case BLEND_MODE_ADD: code += "blend_add"; break;
- case BLEND_MODE_SUB: code += "blend_sub"; break;
- case BLEND_MODE_MUL: code += "blend_mul"; break;
- case BLEND_MODE_PREMULT_ALPHA: code += "blend_premul_alpha"; break;
- case BLEND_MODE_DISABLED: code += "blend_disabled"; break;
+ case BLEND_MODE_MIX:
+ code += "blend_mix";
+ break;
+ case BLEND_MODE_ADD:
+ code += "blend_add";
+ break;
+ case BLEND_MODE_SUB:
+ code += "blend_sub";
+ break;
+ case BLEND_MODE_MUL:
+ code += "blend_mul";
+ break;
+ case BLEND_MODE_PREMULT_ALPHA:
+ code += "blend_premul_alpha";
+ break;
+ case BLEND_MODE_DISABLED:
+ code += "blend_disabled";
+ break;
}
switch (light_mode) {
- case LIGHT_MODE_NORMAL: break;
- case LIGHT_MODE_UNSHADED: code += ",unshaded"; break;
- case LIGHT_MODE_LIGHT_ONLY: code += ",light_only"; break;
+ case LIGHT_MODE_NORMAL:
+ break;
+ case LIGHT_MODE_UNSHADED:
+ code += ",unshaded";
+ break;
+ case LIGHT_MODE_LIGHT_ONLY:
+ code += ",light_only";
+ break;
}
code += ";\n";
@@ -1372,10 +1389,18 @@ void CanvasItem::_update_texture_filter_changed(bool p_propagate) {
} else {
//from viewport
switch (get_viewport()->get_default_canvas_item_texture_filter()) {
- case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_NEAREST: texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST; break;
- case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR: texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR; break;
- case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS: texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS; break;
- case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS: texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS; break;
+ case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_NEAREST:
+ texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST;
+ break;
+ case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR:
+ texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR;
+ break;
+ case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS:
+ texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS;
+ break;
+ case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS:
+ texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS;
+ break;
default: {
}
}
@@ -1421,9 +1446,15 @@ void CanvasItem::_update_texture_repeat_changed(bool p_propagate) {
} else {
//from viewport
switch (get_viewport()->get_default_canvas_item_texture_repeat()) {
- case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_DISABLED: texture_repeat_cache = RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED; break;
- case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_ENABLED: texture_repeat_cache = RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED; break;
- case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_MIRROR: texture_repeat_cache = RS::CANVAS_ITEM_TEXTURE_REPEAT_MIRROR; break;
+ case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_DISABLED:
+ texture_repeat_cache = RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED;
+ break;
+ case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_ENABLED:
+ texture_repeat_cache = RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED;
+ break;
+ case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_MIRROR:
+ texture_repeat_cache = RS::CANVAS_ITEM_TEXTURE_REPEAT_MIRROR;
+ break;
default: {
}
}
diff --git a/scene/main/canvas_item.h b/scene/main/canvas_item.h
index dc17c5283b..805659376a 100644
--- a/scene/main/canvas_item.h
+++ b/scene/main/canvas_item.h
@@ -247,9 +247,11 @@ private:
protected:
_FORCE_INLINE_ void _notify_transform() {
- if (!is_inside_tree()) return;
+ if (!is_inside_tree())
+ return;
_notify_transform(this);
- if (!block_transform_notify && notify_local_transform) notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
+ if (!block_transform_notify && notify_local_transform)
+ notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
}
void item_rect_changed(bool p_size_changed = true);
@@ -275,7 +277,7 @@ public:
virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const;
// Save and restore a CanvasItem state
- virtual void _edit_set_state(const Dictionary &p_state){};
+ virtual void _edit_set_state(const Dictionary &p_state) {}
virtual Dictionary _edit_get_state() const { return Dictionary(); };
// Used to move the node
@@ -288,18 +290,18 @@ public:
// Used to rotate the node
virtual bool _edit_use_rotation() const { return false; };
- virtual void _edit_set_rotation(float p_rotation){};
+ virtual void _edit_set_rotation(float p_rotation) {}
virtual float _edit_get_rotation() const { return 0.0; };
// Used to resize/move the node
virtual bool _edit_use_rect() const { return false; }; // MAYBE REPLACE BY A _edit_get_editmode()
- virtual void _edit_set_rect(const Rect2 &p_rect){};
+ virtual void _edit_set_rect(const Rect2 &p_rect) {}
virtual Rect2 _edit_get_rect() const { return Rect2(0, 0, 0, 0); };
virtual Size2 _edit_get_minimum_size() const { return Size2(-1, -1); }; // LOOKS WEIRD
// Used to set a pivot
virtual bool _edit_use_pivot() const { return false; };
- virtual void _edit_set_pivot(const Point2 &p_pivot){};
+ virtual void _edit_set_pivot(const Point2 &p_pivot) {}
virtual Point2 _edit_get_pivot() const { return Point2(); };
virtual Transform2D _edit_get_transform() const;
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 4c02a15531..3d56b51e26 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -819,10 +819,14 @@ String Node::get_rpc_md5() const {
bool Node::can_process_notification(int p_what) const {
switch (p_what) {
- case NOTIFICATION_PHYSICS_PROCESS: return data.physics_process;
- case NOTIFICATION_PROCESS: return data.idle_process;
- case NOTIFICATION_INTERNAL_PROCESS: return data.idle_process_internal;
- case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: return data.physics_process_internal;
+ case NOTIFICATION_PHYSICS_PROCESS:
+ return data.physics_process;
+ case NOTIFICATION_PROCESS:
+ return data.idle_process;
+ case NOTIFICATION_INTERNAL_PROCESS:
+ return data.idle_process_internal;
+ case NOTIFICATION_INTERNAL_PHYSICS_PROCESS:
+ return data.physics_process_internal;
}
return true;
@@ -2994,10 +2998,14 @@ void Node::_bind_methods() {
String Node::_get_name_num_separator() {
switch (ProjectSettings::get_singleton()->get("node/name_num_separator").operator int()) {
- case 0: return "";
- case 1: return " ";
- case 2: return "_";
- case 3: return "-";
+ case 0:
+ return "";
+ case 1:
+ return " ";
+ case 2:
+ return "_";
+ case 3:
+ return "-";
}
return " ";
}
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index 7afc1b2edd..94be22ccd2 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -1372,7 +1372,8 @@ void SceneTree::get_argument_options(const StringName &p_function, int p_idx, Li
SceneTree::SceneTree() {
- if (singleton == nullptr) singleton = this;
+ if (singleton == nullptr)
+ singleton = this;
_quit = false;
accept_quit = true;
quit_on_go_back = true;
@@ -1478,5 +1479,6 @@ SceneTree::~SceneTree() {
memdelete(root);
}
- if (singleton == this) singleton = nullptr;
+ if (singleton == this)
+ singleton = nullptr;
}
diff --git a/scene/main/shader_globals_override.cpp b/scene/main/shader_globals_override.cpp
index 13582cf655..272cea8f2b 100644
--- a/scene/main/shader_globals_override.cpp
+++ b/scene/main/shader_globals_override.cpp
@@ -1,3 +1,33 @@
+/*************************************************************************/
+/* shader_globals_override.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
#include "shader_globals_override.h"
#include "core/core_string_names.h"
@@ -176,7 +206,7 @@ void ShaderGlobalsOverride::_get_property_list(List<PropertyInfo> *p_list) const
Override o;
o.in_use = false;
Callable::CallError ce;
- o.override = Variant::construct(pinfo.type, NULL, 0, ce);
+ o.override = Variant::construct(pinfo.type, nullptr, 0, ce);
overrides[variables[i]] = o;
}
diff --git a/scene/main/shader_globals_override.h b/scene/main/shader_globals_override.h
index 33d0dc948f..d470e6a7dc 100644
--- a/scene/main/shader_globals_override.h
+++ b/scene/main/shader_globals_override.h
@@ -1,3 +1,33 @@
+/*************************************************************************/
+/* shader_globals_override.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
#ifndef SHADER_GLOBALS_OVERRIDE_H
#define SHADER_GLOBALS_OVERRIDE_H
diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp
index 7c847095e1..7cab4028b8 100644
--- a/scene/main/timer.cpp
+++ b/scene/main/timer.cpp
@@ -173,8 +173,12 @@ Timer::TimerProcessMode Timer::get_timer_process_mode() const {
void Timer::_set_process(bool p_process, bool p_force) {
switch (timer_process_mode) {
- case TIMER_PROCESS_PHYSICS: set_physics_process_internal(p_process && !paused); break;
- case TIMER_PROCESS_IDLE: set_process_internal(p_process && !paused); break;
+ case TIMER_PROCESS_PHYSICS:
+ set_physics_process_internal(p_process && !paused);
+ break;
+ case TIMER_PROCESS_IDLE:
+ set_process_internal(p_process && !paused);
+ break;
}
processing = p_process;
}
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index e9827d521b..58024dab38 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -173,7 +173,7 @@ class TooltipPanel : public PopupPanel {
GDCLASS(TooltipPanel, PopupPanel);
public:
- TooltipPanel(){};
+ TooltipPanel() {}
};
class TooltipLabel : public Label {
@@ -181,7 +181,7 @@ class TooltipLabel : public Label {
GDCLASS(TooltipLabel, Label);
public:
- TooltipLabel(){};
+ TooltipLabel() {}
};
Viewport::GUI::GUI() {
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index dc3ef5b508..24f92bdc20 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -193,6 +193,7 @@
#include "scene/3d/gpu_particles_3d.h"
#include "scene/3d/immediate_geometry_3d.h"
#include "scene/3d/light_3d.h"
+#include "scene/3d/lightmap_probe.h"
#include "scene/3d/listener_3d.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/multimesh_instance_3d.h"
@@ -225,8 +226,8 @@ static Ref<ResourceFormatLoaderText> resource_loader_text;
static Ref<ResourceFormatLoaderDynamicFont> resource_loader_dynamic_font;
-static Ref<ResourceFormatLoaderStreamTexture> resource_loader_stream_texture;
-static Ref<ResourceFormatLoaderTextureLayered> resource_loader_texture_layered;
+static Ref<ResourceFormatLoaderStreamTexture2D> resource_loader_stream_texture;
+static Ref<ResourceFormatLoaderStreamTextureLayered> resource_loader_texture_layered;
static Ref<ResourceFormatLoaderBMFont> resource_loader_bmfont;
@@ -432,8 +433,10 @@ void register_scene_types() {
ClassDB::register_class<Decal>();
ClassDB::register_class<GIProbe>();
ClassDB::register_class<GIProbeData>();
- //ClassDB::register_class<BakedLightmap>();
- //ClassDB::register_class<BakedLightmapData>();
+ ClassDB::register_class<BakedLightmap>();
+ ClassDB::register_class<BakedLightmapData>();
+ ClassDB::register_class<LightmapProbe>();
+ ClassDB::register_virtual_class<Lightmapper>();
ClassDB::register_class<GPUParticles3D>();
ClassDB::register_class<CPUParticles3D>();
ClassDB::register_class<Position3D>();
@@ -675,7 +678,7 @@ void register_scene_types() {
ClassDB::register_virtual_class<Texture>();
ClassDB::register_virtual_class<Texture2D>();
ClassDB::register_class<Sky>();
- ClassDB::register_class<StreamTexture>();
+ ClassDB::register_class<StreamTexture2D>();
ClassDB::register_class<ImageTexture>();
ClassDB::register_class<AtlasTexture>();
ClassDB::register_class<MeshTexture>();
@@ -686,9 +689,15 @@ void register_scene_types() {
ClassDB::register_class<AnimatedTexture>();
ClassDB::register_class<CameraTexture>();
ClassDB::register_virtual_class<TextureLayered>();
+ ClassDB::register_virtual_class<ImageTextureLayered>();
ClassDB::register_class<Cubemap>();
ClassDB::register_class<CubemapArray>();
ClassDB::register_class<Texture2DArray>();
+ ClassDB::register_virtual_class<StreamTextureLayered>();
+ ClassDB::register_class<StreamCubemap>();
+ ClassDB::register_class<StreamCubemapArray>();
+ ClassDB::register_class<StreamTexture2DArray>();
+
ClassDB::register_class<Animation>();
ClassDB::register_virtual_class<Font>();
ClassDB::register_class<BitmapFont>();
@@ -867,6 +876,7 @@ void register_scene_types() {
ClassDB::add_compatibility_class("VisualShaderNodeScalarOp", "VisualShaderNodeFloatOp");
ClassDB::add_compatibility_class("VisualShaderNodeScalarUniform", "VisualShaderNodeFloatUniform");
ClassDB::add_compatibility_class("World", "World3D");
+ ClassDB::add_compatibility_class("StreamTexture", "StreamTexture2D");
#endif
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp
index ea4338519e..c5806ee7b3 100644
--- a/scene/resources/animation.cpp
+++ b/scene/resources/animation.cpp
@@ -349,12 +349,24 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const {
switch (track_get_type(track)) {
- case TYPE_TRANSFORM: r_ret = "transform"; break;
- case TYPE_VALUE: r_ret = "value"; break;
- case TYPE_METHOD: r_ret = "method"; break;
- case TYPE_BEZIER: r_ret = "bezier"; break;
- case TYPE_AUDIO: r_ret = "audio"; break;
- case TYPE_ANIMATION: r_ret = "animation"; break;
+ case TYPE_TRANSFORM:
+ r_ret = "transform";
+ break;
+ case TYPE_VALUE:
+ r_ret = "value";
+ break;
+ case TYPE_METHOD:
+ r_ret = "method";
+ break;
+ case TYPE_BEZIER:
+ r_ret = "bezier";
+ break;
+ case TYPE_AUDIO:
+ r_ret = "audio";
+ break;
+ case TYPE_ANIMATION:
+ r_ret = "animation";
+ break;
}
return true;
@@ -1842,7 +1854,8 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, float p_time, Interpola
return _cubic_interpolate(p_keys[pre].value, p_keys[idx].value, p_keys[next].value, p_keys[post].value, c);
} break;
- default: return p_keys[idx].value;
+ default:
+ return p_keys[idx].value;
}
// do a barrel roll
diff --git a/scene/resources/audio_stream_sample.cpp b/scene/resources/audio_stream_sample.cpp
index d630a1f3ee..fdf5e2c2d0 100644
--- a/scene/resources/audio_stream_sample.cpp
+++ b/scene/resources/audio_stream_sample.cpp
@@ -230,9 +230,15 @@ void AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, in
int len = base->data_bytes;
switch (base->format) {
- case AudioStreamSample::FORMAT_8_BITS: len /= 1; break;
- case AudioStreamSample::FORMAT_16_BITS: len /= 2; break;
- case AudioStreamSample::FORMAT_IMA_ADPCM: len *= 2; break;
+ case AudioStreamSample::FORMAT_8_BITS:
+ len /= 1;
+ break;
+ case AudioStreamSample::FORMAT_16_BITS:
+ len /= 2;
+ break;
+ case AudioStreamSample::FORMAT_IMA_ADPCM:
+ len *= 2;
+ break;
}
if (base->stereo) {
@@ -465,9 +471,15 @@ float AudioStreamSample::get_length() const {
int len = data_bytes;
switch (format) {
- case AudioStreamSample::FORMAT_8_BITS: len /= 1; break;
- case AudioStreamSample::FORMAT_16_BITS: len /= 2; break;
- case AudioStreamSample::FORMAT_IMA_ADPCM: len *= 2; break;
+ case AudioStreamSample::FORMAT_8_BITS:
+ len /= 1;
+ break;
+ case AudioStreamSample::FORMAT_16_BITS:
+ len /= 2;
+ break;
+ case AudioStreamSample::FORMAT_IMA_ADPCM:
+ len *= 2;
+ break;
}
if (stereo) {
@@ -536,9 +548,15 @@ Error AudioStreamSample::save_to_wav(const String &p_path) {
int byte_pr_sample = 0;
switch (format) {
- case AudioStreamSample::FORMAT_8_BITS: byte_pr_sample = 1; break;
- case AudioStreamSample::FORMAT_16_BITS: byte_pr_sample = 2; break;
- case AudioStreamSample::FORMAT_IMA_ADPCM: byte_pr_sample = 4; break;
+ case AudioStreamSample::FORMAT_8_BITS:
+ byte_pr_sample = 1;
+ break;
+ case AudioStreamSample::FORMAT_16_BITS:
+ byte_pr_sample = 2;
+ break;
+ case AudioStreamSample::FORMAT_IMA_ADPCM:
+ byte_pr_sample = 4;
+ break;
}
String file_path = p_path;
diff --git a/scene/resources/capsule_shape_2d.cpp b/scene/resources/capsule_shape_2d.cpp
index ab2657c892..5a3282478c 100644
--- a/scene/resources/capsule_shape_2d.cpp
+++ b/scene/resources/capsule_shape_2d.cpp
@@ -72,6 +72,9 @@ real_t CapsuleShape2D::get_radius() const {
void CapsuleShape2D::set_height(real_t p_height) {
height = p_height;
+ if (height < 0)
+ height = 0;
+
_update_shape();
}
diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp
index 02ea5b24b8..abbe579307 100644
--- a/scene/resources/environment.cpp
+++ b/scene/resources/environment.cpp
@@ -164,7 +164,7 @@ float Environment::get_ambient_light_sky_contribution() const {
return ambient_sky_contribution;
}
-int Environment::get_camera_feed_id(void) const {
+int Environment::get_camera_feed_id() const {
return camera_feed_id;
}
@@ -1117,11 +1117,7 @@ void Environment::_bind_methods() {
BIND_ENUM_CONSTANT(SSAO_BLUR_3x3);
}
-Environment::Environment() :
- bg_mode(BG_CLEAR_COLOR),
- tone_mapper(TONE_MAPPER_LINEAR),
- ssao_blur(SSAO_BLUR_3x3),
- glow_blend_mode(GLOW_BLEND_MODE_ADDITIVE) {
+Environment::Environment() {
environment = RS::get_singleton()->environment_create();
diff --git a/scene/resources/environment.h b/scene/resources/environment.h
index 02434bc592..f0ea8489ff 100644
--- a/scene/resources/environment.h
+++ b/scene/resources/environment.h
@@ -90,7 +90,7 @@ public:
private:
RID environment;
- BGMode bg_mode;
+ BGMode bg_mode = BG_CLEAR_COLOR;
Ref<Sky> bg_sky;
float bg_sky_custom_fov;
Vector3 sky_rotation;
@@ -105,7 +105,7 @@ private:
AmbientSource ambient_source;
ReflectionSource reflection_source;
- ToneMapper tone_mapper;
+ ToneMapper tone_mapper = TONE_MAPPER_LINEAR;
float tonemap_exposure;
float tonemap_white;
bool tonemap_auto_exposure;
@@ -132,7 +132,7 @@ private:
float ssao_bias;
float ssao_direct_light_affect;
float ssao_ao_channel_affect;
- SSAOBlur ssao_blur;
+ SSAOBlur ssao_blur = SSAO_BLUR_3x3;
float ssao_edge_sharpness;
bool glow_enabled;
@@ -141,7 +141,7 @@ private:
float glow_strength;
float glow_mix;
float glow_bloom;
- GlowBlendMode glow_blend_mode;
+ GlowBlendMode glow_blend_mode = GLOW_BLEND_MODE_ADDITIVE;
float glow_hdr_bleed_threshold;
float glow_hdr_bleed_scale;
float glow_hdr_luminance_cap;
@@ -200,7 +200,7 @@ public:
Color get_ambient_light_color() const;
float get_ambient_light_energy() const;
float get_ambient_light_sky_contribution() const;
- int get_camera_feed_id(void) const;
+ int get_camera_feed_id() const;
void set_tonemapper(ToneMapper p_tone_mapper);
ToneMapper get_tonemapper() const;
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index fd8cff7cd0..137657d239 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -414,13 +414,26 @@ void BaseMaterial3D::_update_shader() {
String texfilter_str;
switch (texture_filter) {
- case TEXTURE_FILTER_NEAREST: texfilter_str = "filter_nearest"; break;
- case TEXTURE_FILTER_LINEAR: texfilter_str = "filter_linear"; break;
- case TEXTURE_FILTER_NEAREST_WITH_MIPMAPS: texfilter_str = "filter_nearest_mipmap"; break;
- case TEXTURE_FILTER_LINEAR_WITH_MIPMAPS: texfilter_str = "filter_linear_mipmap"; break;
- case TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC: texfilter_str = "filter_nearest_mipmap_aniso"; break;
- case TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC: texfilter_str = "filter_linear_mipmap_aniso"; break;
- case TEXTURE_FILTER_MAX: break; // Internal value, skip.
+ case TEXTURE_FILTER_NEAREST:
+ texfilter_str = "filter_nearest";
+ break;
+ case TEXTURE_FILTER_LINEAR:
+ texfilter_str = "filter_linear";
+ break;
+ case TEXTURE_FILTER_NEAREST_WITH_MIPMAPS:
+ texfilter_str = "filter_nearest_mipmap";
+ break;
+ case TEXTURE_FILTER_LINEAR_WITH_MIPMAPS:
+ texfilter_str = "filter_linear_mipmap";
+ break;
+ case TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC:
+ texfilter_str = "filter_nearest_mipmap_aniso";
+ break;
+ case TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC:
+ texfilter_str = "filter_linear_mipmap_aniso";
+ break;
+ case TEXTURE_FILTER_MAX:
+ break; // Internal value, skip.
}
if (flags[FLAG_USE_TEXTURE_REPEAT]) {
@@ -433,10 +446,18 @@ void BaseMaterial3D::_update_shader() {
String code = "shader_type spatial;\nrender_mode ";
switch (blend_mode) {
- case BLEND_MODE_MIX: code += "blend_mix"; break;
- case BLEND_MODE_ADD: code += "blend_add"; break;
- case BLEND_MODE_SUB: code += "blend_sub"; break;
- case BLEND_MODE_MUL: code += "blend_mul"; break;
+ case BLEND_MODE_MIX:
+ code += "blend_mix";
+ break;
+ case BLEND_MODE_ADD:
+ code += "blend_add";
+ break;
+ case BLEND_MODE_SUB:
+ code += "blend_sub";
+ break;
+ case BLEND_MODE_MUL:
+ code += "blend_mul";
+ break;
}
DepthDrawMode ddm = depth_draw_mode;
@@ -445,9 +466,15 @@ void BaseMaterial3D::_update_shader() {
}
switch (ddm) {
- case DEPTH_DRAW_OPAQUE_ONLY: code += ",depth_draw_opaque"; break;
- case DEPTH_DRAW_ALWAYS: code += ",depth_draw_always"; break;
- case DEPTH_DRAW_DISABLED: code += ",depth_draw_never"; break;
+ case DEPTH_DRAW_OPAQUE_ONLY:
+ code += ",depth_draw_opaque";
+ break;
+ case DEPTH_DRAW_ALWAYS:
+ code += ",depth_draw_always";
+ break;
+ case DEPTH_DRAW_DISABLED:
+ code += ",depth_draw_never";
+ break;
}
if (transparency == TRANSPARENCY_ALPHA_DEPTH_PRE_PASS) {
@@ -455,23 +482,49 @@ void BaseMaterial3D::_update_shader() {
}
switch (cull_mode) {
- case CULL_BACK: code += ",cull_back"; break;
- case CULL_FRONT: code += ",cull_front"; break;
- case CULL_DISABLED: code += ",cull_disabled"; break;
+ case CULL_BACK:
+ code += ",cull_back";
+ break;
+ case CULL_FRONT:
+ code += ",cull_front";
+ break;
+ case CULL_DISABLED:
+ code += ",cull_disabled";
+ break;
}
switch (diffuse_mode) {
- case DIFFUSE_BURLEY: code += ",diffuse_burley"; break;
- case DIFFUSE_LAMBERT: code += ",diffuse_lambert"; break;
- case DIFFUSE_LAMBERT_WRAP: code += ",diffuse_lambert_wrap"; break;
- case DIFFUSE_OREN_NAYAR: code += ",diffuse_oren_nayar"; break;
- case DIFFUSE_TOON: code += ",diffuse_toon"; break;
+ case DIFFUSE_BURLEY:
+ code += ",diffuse_burley";
+ break;
+ case DIFFUSE_LAMBERT:
+ code += ",diffuse_lambert";
+ break;
+ case DIFFUSE_LAMBERT_WRAP:
+ code += ",diffuse_lambert_wrap";
+ break;
+ case DIFFUSE_OREN_NAYAR:
+ code += ",diffuse_oren_nayar";
+ break;
+ case DIFFUSE_TOON:
+ code += ",diffuse_toon";
+ break;
}
switch (specular_mode) {
- case SPECULAR_SCHLICK_GGX: code += ",specular_schlick_ggx"; break;
- case SPECULAR_BLINN: code += ",specular_blinn"; break;
- case SPECULAR_PHONG: code += ",specular_phong"; break;
- case SPECULAR_TOON: code += ",specular_toon"; break;
- case SPECULAR_DISABLED: code += ",specular_disabled"; break;
+ case SPECULAR_SCHLICK_GGX:
+ code += ",specular_schlick_ggx";
+ break;
+ case SPECULAR_BLINN:
+ code += ",specular_blinn";
+ break;
+ case SPECULAR_PHONG:
+ code += ",specular_phong";
+ break;
+ case SPECULAR_TOON:
+ code += ",specular_toon";
+ break;
+ case SPECULAR_DISABLED:
+ code += ",specular_disabled";
+ break;
}
if (features[FEATURE_SUBSURFACE_SCATTERING] && flags[FLAG_SUBSURFACE_MODE_SKIN]) {
code += ",sss_mode_skin";
@@ -2637,7 +2690,7 @@ BaseMaterial3D::BaseMaterial3D(bool p_orm) :
depth_draw_mode = DEPTH_DRAW_OPAQUE_ONLY;
cull_mode = CULL_BACK;
for (int i = 0; i < FLAG_MAX; i++) {
- flags[i] = 0;
+ flags[i] = false;
}
flags[FLAG_USE_TEXTURE_REPEAT] = true;
diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp
index 401b689145..6548c65cd7 100644
--- a/scene/resources/mesh.cpp
+++ b/scene/resources/mesh.cpp
@@ -472,11 +472,11 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const {
return newmesh;
}
-void Mesh::set_lightmap_size_hint(const Vector2 &p_size) {
+void Mesh::set_lightmap_size_hint(const Size2i &p_size) {
lightmap_size_hint = p_size;
}
-Size2 Mesh::get_lightmap_size_hint() const {
+Size2i Mesh::get_lightmap_size_hint() const {
return lightmap_size_hint;
}
@@ -486,7 +486,7 @@ void Mesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_lightmap_size_hint"), &Mesh::get_lightmap_size_hint);
ClassDB::bind_method(D_METHOD("get_aabb"), &Mesh::get_aabb);
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "lightmap_size_hint"), "set_lightmap_size_hint", "get_lightmap_size_hint");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "lightmap_size_hint"), "set_lightmap_size_hint", "get_lightmap_size_hint");
ClassDB::bind_method(D_METHOD("get_surface_count"), &Mesh::get_surface_count);
ClassDB::bind_method(D_METHOD("surface_get_arrays", "surf_idx"), &Mesh::surface_get_arrays);
diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h
index a65cf0a928..80cd57846b 100644
--- a/scene/resources/mesh.h
+++ b/scene/resources/mesh.h
@@ -43,7 +43,7 @@ class Mesh : public Resource {
mutable Ref<TriangleMesh> triangle_mesh; //cached
mutable Vector<Vector3> debug_lines;
- Size2 lightmap_size_hint;
+ Size2i lightmap_size_hint;
protected:
static void _bind_methods();
@@ -138,8 +138,8 @@ public:
virtual AABB get_aabb() const = 0;
- void set_lightmap_size_hint(const Vector2 &p_size);
- Size2 get_lightmap_size_hint() const;
+ void set_lightmap_size_hint(const Size2i &p_size);
+ Size2i get_lightmap_size_hint() const;
void clear_cache() const;
typedef Vector<Vector<Face3>> (*ConvexDecompositionFunc)(const Vector<Face3> &);
diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp
index 83430aef9e..1a28e2586d 100644
--- a/scene/resources/particles_material.cpp
+++ b/scene/resources/particles_material.cpp
@@ -703,7 +703,8 @@ void ParticlesMaterial::set_param(Parameter p_param, float p_value) {
case PARAM_ANIM_OFFSET: {
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_offset, p_value);
} break;
- case PARAM_MAX: break; // Can't happen, but silences warning
+ case PARAM_MAX:
+ break; // Can't happen, but silences warning
}
}
float ParticlesMaterial::get_param(Parameter p_param) const {
@@ -756,7 +757,8 @@ void ParticlesMaterial::set_param_randomness(Parameter p_param, float p_value) {
case PARAM_ANIM_OFFSET: {
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_offset_random, p_value);
} break;
- case PARAM_MAX: break; // Can't happen, but silences warning
+ case PARAM_MAX:
+ break; // Can't happen, but silences warning
}
}
float ParticlesMaterial::get_param_randomness(Parameter p_param) const {
@@ -828,7 +830,8 @@ void ParticlesMaterial::set_param_texture(Parameter p_param, const Ref<Texture2D
case PARAM_ANIM_OFFSET: {
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_offset_texture, p_texture);
} break;
- case PARAM_MAX: break; // Can't happen, but silences warning
+ case PARAM_MAX:
+ break; // Can't happen, but silences warning
}
_queue_shader_change();
diff --git a/scene/resources/physics_material.cpp b/scene/resources/physics_material.cpp
index 8ac0191452..89fbf7a248 100644
--- a/scene/resources/physics_material.cpp
+++ b/scene/resources/physics_material.cpp
@@ -69,9 +69,3 @@ void PhysicsMaterial::set_absorbent(bool p_val) {
absorbent = p_val;
emit_changed();
}
-
-PhysicsMaterial::PhysicsMaterial() :
- friction(1),
- rough(false),
- bounce(0),
- absorbent(false) {}
diff --git a/scene/resources/physics_material.h b/scene/resources/physics_material.h
index f4a77d9854..1fac3fa6ef 100644
--- a/scene/resources/physics_material.h
+++ b/scene/resources/physics_material.h
@@ -28,8 +28,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef physics_material_override_H
-#define physics_material_override_H
+#ifndef PHYSICS_MATERIAL_H
+#define PHYSICS_MATERIAL_H
#include "core/resource.h"
#include "servers/physics_server_3d.h"
@@ -40,10 +40,10 @@ class PhysicsMaterial : public Resource {
OBJ_SAVE_TYPE(PhysicsMaterial);
RES_BASE_EXTENSION("phymat");
- real_t friction;
- bool rough;
- real_t bounce;
- bool absorbent;
+ real_t friction = 1;
+ bool rough = false;
+ real_t bounce = 0;
+ bool absorbent = false;
protected:
static void _bind_methods();
@@ -69,7 +69,7 @@ public:
return absorbent ? -bounce : bounce;
}
- PhysicsMaterial();
+ PhysicsMaterial() {}
};
-#endif // physics_material_override_H
+#endif // PHYSICS_MATERIAL_H
diff --git a/scene/resources/shape_3d.cpp b/scene/resources/shape_3d.cpp
index f4a5d91e52..97d03b3cfc 100644
--- a/scene/resources/shape_3d.cpp
+++ b/scene/resources/shape_3d.cpp
@@ -109,19 +109,13 @@ void Shape3D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "margin", PROPERTY_HINT_RANGE, "0.001,10,0.001"), "set_margin", "get_margin");
}
-Shape3D::Shape3D() :
- margin(0.04) {
-
- ERR_PRINT("Constructor must not be called!");
+Shape3D::Shape3D() {
+ ERR_PRINT("Default constructor must not be called!");
}
Shape3D::Shape3D(RID p_shape) :
- margin(0.04) {
-
- shape = p_shape;
-}
+ shape(p_shape) {}
Shape3D::~Shape3D() {
-
PhysicsServer3D::get_singleton()->free(shape);
}
diff --git a/scene/resources/shape_3d.h b/scene/resources/shape_3d.h
index e7a516412d..6516868fd5 100644
--- a/scene/resources/shape_3d.h
+++ b/scene/resources/shape_3d.h
@@ -41,7 +41,7 @@ class Shape3D : public Resource {
OBJ_SAVE_TYPE(Shape3D);
RES_BASE_EXTENSION("shape");
RID shape;
- real_t margin;
+ real_t margin = 0.04;
Ref<ArrayMesh> debug_mesh_cache;
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index d57af29599..b212bba826 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -355,7 +355,7 @@ ImageTexture::~ImageTexture() {
//////////////////////////////////////////
-Ref<Image> StreamTexture::load_image_from_file(FileAccess *f, int p_size_limit) {
+Ref<Image> StreamTexture2D::load_image_from_file(FileAccess *f, int p_size_limit) {
uint32_t data_format = f->get_32();
uint32_t w = f->get_16();
@@ -492,7 +492,7 @@ Ref<Image> StreamTexture::load_image_from_file(FileAccess *f, int p_size_limit)
return Ref<Image>();
}
-void StreamTexture::set_path(const String &p_path, bool p_take_over) {
+void StreamTexture2D::set_path(const String &p_path, bool p_take_over) {
if (texture.is_valid()) {
RenderingServer::get_singleton()->texture_set_path(texture, p_path);
@@ -501,40 +501,40 @@ void StreamTexture::set_path(const String &p_path, bool p_take_over) {
Resource::set_path(p_path, p_take_over);
}
-void StreamTexture::_requested_3d(void *p_ud) {
+void StreamTexture2D::_requested_3d(void *p_ud) {
- StreamTexture *st = (StreamTexture *)p_ud;
- Ref<StreamTexture> stex(st);
+ StreamTexture2D *st = (StreamTexture2D *)p_ud;
+ Ref<StreamTexture2D> stex(st);
ERR_FAIL_COND(!request_3d_callback);
request_3d_callback(stex);
}
-void StreamTexture::_requested_roughness(void *p_ud, const String &p_normal_path, RS::TextureDetectRoughnessChannel p_roughness_channel) {
+void StreamTexture2D::_requested_roughness(void *p_ud, const String &p_normal_path, RS::TextureDetectRoughnessChannel p_roughness_channel) {
- StreamTexture *st = (StreamTexture *)p_ud;
- Ref<StreamTexture> stex(st);
+ StreamTexture2D *st = (StreamTexture2D *)p_ud;
+ Ref<StreamTexture2D> stex(st);
ERR_FAIL_COND(!request_roughness_callback);
request_roughness_callback(stex, p_normal_path, p_roughness_channel);
}
-void StreamTexture::_requested_normal(void *p_ud) {
+void StreamTexture2D::_requested_normal(void *p_ud) {
- StreamTexture *st = (StreamTexture *)p_ud;
- Ref<StreamTexture> stex(st);
+ StreamTexture2D *st = (StreamTexture2D *)p_ud;
+ Ref<StreamTexture2D> stex(st);
ERR_FAIL_COND(!request_normal_callback);
request_normal_callback(stex);
}
-StreamTexture::TextureFormatRequestCallback StreamTexture::request_3d_callback = nullptr;
-StreamTexture::TextureFormatRoughnessRequestCallback StreamTexture::request_roughness_callback = nullptr;
-StreamTexture::TextureFormatRequestCallback StreamTexture::request_normal_callback = nullptr;
+StreamTexture2D::TextureFormatRequestCallback StreamTexture2D::request_3d_callback = nullptr;
+StreamTexture2D::TextureFormatRoughnessRequestCallback StreamTexture2D::request_roughness_callback = nullptr;
+StreamTexture2D::TextureFormatRequestCallback StreamTexture2D::request_normal_callback = nullptr;
-Image::Format StreamTexture::get_format() const {
+Image::Format StreamTexture2D::get_format() const {
return format;
}
-Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &tw_custom, int &th_custom, Ref<Image> &image, bool &r_request_3d, bool &r_request_normal, bool &r_request_roughness, int &mipmap_limit, int p_size_limit) {
+Error StreamTexture2D::_load_data(const String &p_path, int &tw, int &th, int &tw_custom, int &th_custom, Ref<Image> &image, bool &r_request_3d, bool &r_request_normal, bool &r_request_roughness, int &mipmap_limit, int p_size_limit) {
alpha_cache.unref();
@@ -595,7 +595,7 @@ Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &tw_
return OK;
}
-Error StreamTexture::load(const String &p_path) {
+Error StreamTexture2D::load(const String &p_path) {
int lw, lh, lwc, lhc;
Ref<Image> image;
@@ -661,20 +661,20 @@ Error StreamTexture::load(const String &p_path) {
emit_changed();
return OK;
}
-String StreamTexture::get_load_path() const {
+String StreamTexture2D::get_load_path() const {
return path_to_file;
}
-int StreamTexture::get_width() const {
+int StreamTexture2D::get_width() const {
return w;
}
-int StreamTexture::get_height() const {
+int StreamTexture2D::get_height() const {
return h;
}
-RID StreamTexture::get_rid() const {
+RID StreamTexture2D::get_rid() const {
if (!texture.is_valid()) {
texture = RS::get_singleton()->texture_2d_placeholder_create();
@@ -682,7 +682,7 @@ RID StreamTexture::get_rid() const {
return texture;
}
-void StreamTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
+void StreamTexture2D::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
if ((w | h) == 0)
return;
@@ -690,7 +690,7 @@ void StreamTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_
RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID();
RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, Size2(w, h)), texture, false, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat);
}
-void StreamTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
+void StreamTexture2D::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
if ((w | h) == 0)
return;
@@ -698,7 +698,7 @@ void StreamTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_til
RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID();
RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, texture, p_tile, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat);
}
-void StreamTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const {
+void StreamTexture2D::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const {
if ((w | h) == 0)
return;
@@ -707,12 +707,12 @@ void StreamTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, con
RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, p_rect, texture, p_src_rect, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_clip_uv, p_texture_filter, p_texture_repeat);
}
-bool StreamTexture::has_alpha() const {
+bool StreamTexture2D::has_alpha() const {
return false;
}
-Ref<Image> StreamTexture::get_data() const {
+Ref<Image> StreamTexture2D::get_data() const {
if (texture.is_valid()) {
return RS::get_singleton()->texture_2d_get(texture);
@@ -721,7 +721,7 @@ Ref<Image> StreamTexture::get_data() const {
}
}
-bool StreamTexture::is_pixel_opaque(int p_x, int p_y) const {
+bool StreamTexture2D::is_pixel_opaque(int p_x, int p_y) const {
if (!alpha_cache.is_valid()) {
Ref<Image> img = get_data();
@@ -757,7 +757,7 @@ bool StreamTexture::is_pixel_opaque(int p_x, int p_y) const {
return true;
}
-void StreamTexture::reload_from_file() {
+void StreamTexture2D::reload_from_file() {
String path = get_path();
if (!path.is_resource_file())
@@ -771,34 +771,34 @@ void StreamTexture::reload_from_file() {
load(path);
}
-void StreamTexture::_validate_property(PropertyInfo &property) const {
+void StreamTexture2D::_validate_property(PropertyInfo &property) const {
}
-void StreamTexture::_bind_methods() {
+void StreamTexture2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("load", "path"), &StreamTexture::load);
- ClassDB::bind_method(D_METHOD("get_load_path"), &StreamTexture::get_load_path);
+ ClassDB::bind_method(D_METHOD("load", "path"), &StreamTexture2D::load);
+ ClassDB::bind_method(D_METHOD("get_load_path"), &StreamTexture2D::get_load_path);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "load_path", PROPERTY_HINT_FILE, "*.stex"), "load", "get_load_path");
}
-StreamTexture::StreamTexture() {
+StreamTexture2D::StreamTexture2D() {
format = Image::FORMAT_MAX;
w = 0;
h = 0;
}
-StreamTexture::~StreamTexture() {
+StreamTexture2D::~StreamTexture2D() {
if (texture.is_valid()) {
RS::get_singleton()->free(texture);
}
}
-RES ResourceFormatLoaderStreamTexture::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
+RES ResourceFormatLoaderStreamTexture2D::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
- Ref<StreamTexture> st;
+ Ref<StreamTexture2D> st;
st.instance();
Error err = st->load(p_path);
if (r_error)
@@ -809,17 +809,17 @@ RES ResourceFormatLoaderStreamTexture::load(const String &p_path, const String &
return st;
}
-void ResourceFormatLoaderStreamTexture::get_recognized_extensions(List<String> *p_extensions) const {
+void ResourceFormatLoaderStreamTexture2D::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("stex");
}
-bool ResourceFormatLoaderStreamTexture::handles_type(const String &p_type) const {
- return p_type == "StreamTexture";
+bool ResourceFormatLoaderStreamTexture2D::handles_type(const String &p_type) const {
+ return p_type == "StreamTexture2D";
}
-String ResourceFormatLoaderStreamTexture::get_resource_type(const String &p_path) const {
+String ResourceFormatLoaderStreamTexture2D::get_resource_type(const String &p_path) const {
if (p_path.get_extension().to_lower() == "stex")
- return "StreamTexture";
+ return "StreamTexture2D";
return "";
}
@@ -1037,8 +1037,10 @@ bool AtlasTexture::is_pixel_opaque(int p_x, int p_y) const {
int y = p_y + region.position.y - margin.position.y;
// margin edge may outside of atlas
- if (x < 0 || x >= atlas->get_width()) return false;
- if (y < 0 || y >= atlas->get_height()) return false;
+ if (x < 0 || x >= atlas->get_width())
+ return false;
+ if (y < 0 || y >= atlas->get_height())
+ return false;
return atlas->is_pixel_opaque(x, y);
}
@@ -1928,23 +1930,47 @@ AnimatedTexture::~AnimatedTexture() {
}
///////////////////////////////
-Image::Format TextureLayered::get_format() const {
+void TextureLayered::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("get_format"), &TextureLayered::get_format);
+ ClassDB::bind_method(D_METHOD("get_layered_type"), &TextureLayered::get_layered_type);
+ ClassDB::bind_method(D_METHOD("get_width"), &TextureLayered::get_width);
+ ClassDB::bind_method(D_METHOD("get_height"), &TextureLayered::get_height);
+ ClassDB::bind_method(D_METHOD("get_layers"), &TextureLayered::get_layers);
+ ClassDB::bind_method(D_METHOD("has_mipmaps"), &TextureLayered::has_mipmaps);
+ ClassDB::bind_method(D_METHOD("get_layer_data", "layer"), &TextureLayered::get_layer_data);
+
+ BIND_ENUM_CONSTANT(LAYERED_TYPE_2D_ARRAY);
+ BIND_ENUM_CONSTANT(LAYERED_TYPE_CUBEMAP);
+ BIND_ENUM_CONSTANT(LAYERED_TYPE_CUBEMAP_ARRAY);
+}
+
+///////////////////////////////
+Image::Format ImageTextureLayered::get_format() const {
return format;
}
-uint32_t TextureLayered::get_width() const {
+int ImageTextureLayered::get_width() const {
return width;
}
-uint32_t TextureLayered::get_height() const {
+int ImageTextureLayered::get_height() const {
return height;
}
-uint32_t TextureLayered::get_layers() const {
+int ImageTextureLayered::get_layers() const {
return layers;
}
-Error TextureLayered::_create_from_images(const Array &p_images) {
+bool ImageTextureLayered::has_mipmaps() const {
+ return mipmaps;
+}
+
+ImageTextureLayered::LayeredType ImageTextureLayered::get_layered_type() const {
+ return layered_type;
+}
+
+Error ImageTextureLayered::_create_from_images(const Array &p_images) {
Vector<Ref<Image>> images;
for (int i = 0; i < p_images.size(); i++) {
Ref<Image> img = p_images[i];
@@ -1955,7 +1981,7 @@ Error TextureLayered::_create_from_images(const Array &p_images) {
return create_from_images(images);
}
-Array TextureLayered::_get_images() const {
+Array ImageTextureLayered::_get_images() const {
Array images;
for (int i = 0; i < layers; i++) {
images.push_back(get_layer_data(i));
@@ -1963,14 +1989,14 @@ Array TextureLayered::_get_images() const {
return images;
}
-Error TextureLayered::create_from_images(Vector<Ref<Image>> p_images) {
+Error ImageTextureLayered::create_from_images(Vector<Ref<Image>> p_images) {
int new_layers = p_images.size();
ERR_FAIL_COND_V(new_layers == 0, ERR_INVALID_PARAMETER);
- if (layered_type == RS::TEXTURE_LAYERED_CUBEMAP) {
+ if (layered_type == LAYERED_TYPE_CUBEMAP) {
ERR_FAIL_COND_V_MSG(new_layers != 6, ERR_INVALID_PARAMETER,
"Cubemaps require exactly 6 layers");
- } else if (layered_type == RS::TEXTURE_LAYERED_CUBEMAP_ARRAY) {
+ } else if (layered_type == LAYERED_TYPE_CUBEMAP_ARRAY) {
ERR_FAIL_COND_V_MSG((new_layers % 6) != 0, ERR_INVALID_PARAMETER,
"Cubemap array layers must be a multiple of 6");
}
@@ -1992,11 +2018,11 @@ Error TextureLayered::create_from_images(Vector<Ref<Image>> p_images) {
}
if (texture.is_valid()) {
- RID new_texture = RS::get_singleton()->texture_2d_layered_create(p_images, layered_type);
+ RID new_texture = RS::get_singleton()->texture_2d_layered_create(p_images, RS::TextureLayeredType(layered_type));
ERR_FAIL_COND_V(!new_texture.is_valid(), ERR_CANT_CREATE);
RS::get_singleton()->texture_replace(texture, new_texture);
} else {
- texture = RS::get_singleton()->texture_2d_layered_create(p_images, layered_type);
+ texture = RS::get_singleton()->texture_2d_layered_create(p_images, RS::TextureLayeredType(layered_type));
ERR_FAIL_COND_V(!texture.is_valid(), ERR_CANT_CREATE);
}
@@ -2008,7 +2034,7 @@ Error TextureLayered::create_from_images(Vector<Ref<Image>> p_images) {
return OK;
}
-void TextureLayered::update_layer(const Ref<Image> &p_image, int p_layer) {
+void ImageTextureLayered::update_layer(const Ref<Image> &p_image, int p_layer) {
ERR_FAIL_COND(texture.is_valid());
ERR_FAIL_COND(p_image.is_null());
ERR_FAIL_COND(p_image->get_format() != format);
@@ -2018,19 +2044,19 @@ void TextureLayered::update_layer(const Ref<Image> &p_image, int p_layer) {
RS::get_singleton()->texture_2d_update(texture, p_image, p_layer);
}
-Ref<Image> TextureLayered::get_layer_data(int p_layer) const {
+Ref<Image> ImageTextureLayered::get_layer_data(int p_layer) const {
ERR_FAIL_INDEX_V(p_layer, layers, Ref<Image>());
return RS::get_singleton()->texture_2d_layer_get(texture, p_layer);
}
-RID TextureLayered::get_rid() const {
+RID ImageTextureLayered::get_rid() const {
if (texture.is_null()) {
- texture = RS::get_singleton()->texture_2d_layered_placeholder_create();
+ texture = RS::get_singleton()->texture_2d_layered_placeholder_create(RS::TextureLayeredType(layered_type));
}
return texture;
}
-void TextureLayered::set_path(const String &p_path, bool p_take_over) {
+void ImageTextureLayered::set_path(const String &p_path, bool p_take_over) {
if (texture.is_valid()) {
RS::get_singleton()->texture_set_path(texture, p_path);
}
@@ -2038,24 +2064,17 @@ void TextureLayered::set_path(const String &p_path, bool p_take_over) {
Resource::set_path(p_path, p_take_over);
}
-void TextureLayered::_bind_methods() {
+void ImageTextureLayered::_bind_methods() {
- ClassDB::bind_method(D_METHOD("get_format"), &TextureLayered::get_format);
+ ClassDB::bind_method(D_METHOD("create_from_images", "images"), &ImageTextureLayered::_create_from_images);
+ ClassDB::bind_method(D_METHOD("update_layer", "image", "layer"), &ImageTextureLayered::update_layer);
- ClassDB::bind_method(D_METHOD("get_width"), &TextureLayered::get_width);
- ClassDB::bind_method(D_METHOD("get_height"), &TextureLayered::get_height);
- ClassDB::bind_method(D_METHOD("get_layers"), &TextureLayered::get_layers);
-
- ClassDB::bind_method(D_METHOD("create_from_images", "images"), &TextureLayered::_create_from_images);
- ClassDB::bind_method(D_METHOD("update_layer", "image", "layer"), &TextureLayered::update_layer);
- ClassDB::bind_method(D_METHOD("get_layer_data", "layer"), &TextureLayered::get_layer_data);
-
- ClassDB::bind_method(D_METHOD("_get_images"), &TextureLayered::_get_images);
+ ClassDB::bind_method(D_METHOD("_get_images"), &ImageTextureLayered::_get_images);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_images", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_INTERNAL), "create_from_images", "_get_images");
}
-TextureLayered::TextureLayered(RenderingServer::TextureLayeredType p_layered_type) {
+ImageTextureLayered::ImageTextureLayered(LayeredType p_layered_type) {
layered_type = p_layered_type;
format = Image::FORMAT_MAX;
@@ -2064,193 +2083,241 @@ TextureLayered::TextureLayered(RenderingServer::TextureLayeredType p_layered_typ
layers = 0;
}
-TextureLayered::~TextureLayered() {
+ImageTextureLayered::~ImageTextureLayered() {
if (texture.is_valid()) {
RS::get_singleton()->free(texture);
}
}
-RES ResourceFormatLoaderTextureLayered::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
+///////////////////////////////////////////
+
+void StreamTextureLayered::set_path(const String &p_path, bool p_take_over) {
- if (r_error) {
- *r_error = ERR_CANT_OPEN;
+ if (texture.is_valid()) {
+ RenderingServer::get_singleton()->texture_set_path(texture, p_path);
}
- Ref<TextureLayered> lt;
+ Resource::set_path(p_path, p_take_over);
+}
- if (p_path.ends_with("cube")) {
- Ref<Cubemap> cube;
- cube.instance();
- lt = cube;
- } else if (p_path.ends_with("cubearr")) {
- Ref<CubemapArray> cubearr;
- cubearr.instance();
- lt = cubearr;
- } else if (p_path.ends_with("tex2darr")) {
- Ref<Texture2DArray> t2darr;
- t2darr.instance();
- lt = t2darr;
- } else {
- ERR_FAIL_V_MSG(RES(), "Unrecognized layered texture extension.");
+Image::Format StreamTextureLayered::get_format() const {
+
+ return format;
+}
+
+Error StreamTextureLayered::_load_data(const String &p_path, Vector<Ref<Image>> &images, int &mipmap_limit, int p_size_limit) {
+
+ ERR_FAIL_COND_V(images.size() != 0, ERR_INVALID_PARAMETER);
+
+ FileAccessRef f = FileAccess::open(p_path, FileAccess::READ);
+ ERR_FAIL_COND_V(!f, ERR_CANT_OPEN);
+
+ uint8_t header[4];
+ f->get_buffer(header, 4);
+ if (header[0] != 'G' || header[1] != 'S' || header[2] != 'T' || header[3] != 'L') {
+ ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Stream texture layered file is corrupt (Bad header).");
}
- FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
- ERR_FAIL_COND_V_MSG(!f, RES(), "Cannot open file '" + p_path + "'.");
+ uint32_t version = f->get_32();
- char header[5] = { 0, 0, 0, 0, 0 };
- f->get_buffer((uint8_t *)header, 4);
+ if (version > FORMAT_VERSION) {
+ ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Stream texture file is too new.");
+ }
- if (String(header) != "GDLT") {
- f->close();
- memdelete(f);
- if (r_error) {
- *r_error = ERR_FILE_CORRUPT;
- }
- // FIXME: It's bogus that we fail in both branches. Seen while rebasing
- // vulkan branch on master branch.
- ERR_FAIL_V_MSG(RES(), "Unrecognized layered texture.");
- } else {
+ uint32_t layer_count = f->get_32(); //layer count
+ uint32_t type = f->get_32(); //layer count
+ ERR_FAIL_COND_V(type != layered_type, ERR_INVALID_DATA);
- f->close();
- memdelete(f);
- ERR_FAIL_V_MSG(RES(), "Unrecognized layered texture file format '" + String((const char *)header) + "'.");
+ uint32_t df = f->get_32(); //data format
+ mipmap_limit = int(f->get_32());
+ //reserverd
+ f->get_32();
+ f->get_32();
+ f->get_32();
+
+ if (!(df & FORMAT_BIT_STREAM)) {
+ p_size_limit = 0;
}
- int tw = f->get_32();
- int th = f->get_32();
- int td = f->get_32();
- bool use_mipmaps = f->get_32() != 0; //texture flags (deprecated)
- Image::Format format = Image::Format(f->get_32());
- uint32_t compression = f->get_32(); // 0 - lossless (PNG), 1 - vram, 2 - uncompressed
+ images.resize(layer_count);
- Vector<Ref<Image>> images;
- for (int layer = 0; layer < td; layer++) {
+ for (uint32_t i = 0; i < layer_count; i++) {
+ Ref<Image> image = StreamTexture2D::load_image_from_file(f, p_size_limit);
+ ERR_FAIL_COND_V(image.is_null() || image->empty(), ERR_CANT_OPEN);
+ images.write[i] = image;
+ }
- Ref<Image> image;
- image.instance();
+ return OK;
+}
- if (compression == COMPRESSION_LOSSLESS) {
- //look for a PNG file inside
+Error StreamTextureLayered::load(const String &p_path) {
- int mipmaps = f->get_32();
- Vector<Ref<Image>> mipmap_images;
+ Vector<Ref<Image>> images;
- for (int i = 0; i < mipmaps; i++) {
- uint32_t size = f->get_32();
+ int mipmap_limit;
- Vector<uint8_t> pv;
- pv.resize(size);
- {
- uint8_t *w = pv.ptrw();
- f->get_buffer(w, size);
- }
+ Error err = _load_data(p_path, images, mipmap_limit);
+ if (err)
+ return err;
- Ref<Image> img = Image::lossless_unpacker(pv);
+ if (texture.is_valid()) {
+ RID new_texture = RS::get_singleton()->texture_2d_layered_create(images, RS::TextureLayeredType(layered_type));
+ RS::get_singleton()->texture_replace(texture, new_texture);
+ } else {
+ texture = RS::get_singleton()->texture_2d_layered_create(images, RS::TextureLayeredType(layered_type));
+ }
- if (img.is_null() || img->empty() || format != img->get_format()) {
- if (r_error) {
- *r_error = ERR_FILE_CORRUPT;
- }
- f->close();
- memdelete(f);
- ERR_FAIL_V(RES());
- }
+ w = images[0]->get_width();
+ h = images[0]->get_height();
+ mipmaps = images[0]->has_mipmaps();
+ format = images[0]->get_format();
+ layers = images.size();
- mipmap_images.push_back(img);
- }
+ path_to_file = p_path;
- if (mipmap_images.size() == 1) {
+ if (get_path() == String()) {
+ //temporarily set path if no path set for resource, helps find errors
+ RenderingServer::get_singleton()->texture_set_path(texture, p_path);
+ }
- image = mipmap_images[0];
+ _change_notify();
+ emit_changed();
+ return OK;
+}
+String StreamTextureLayered::get_load_path() const {
- } else {
- int total_size = Image::get_image_data_size(tw, th, format, true);
- Vector<uint8_t> img_data;
- img_data.resize(total_size);
-
- {
- uint8_t *w = img_data.ptrw();
-
- int ofs = 0;
- for (int i = 0; i < mipmap_images.size(); i++) {
-
- Vector<uint8_t> id = mipmap_images[i]->get_data();
- int len = id.size();
- const uint8_t *r = id.ptr();
- copymem(&w[ofs], r, len);
- ofs += len;
- }
- }
+ return path_to_file;
+}
- image->create(tw, th, true, format, img_data);
- if (image->empty()) {
- if (r_error) {
- *r_error = ERR_FILE_CORRUPT;
- }
- f->close();
- memdelete(f);
- ERR_FAIL_V(RES());
- }
- }
+int StreamTextureLayered::get_width() const {
- } else {
+ return w;
+}
+int StreamTextureLayered::get_height() const {
- //look for regular format
+ return h;
+}
+int StreamTextureLayered::get_layers() const {
- int total_size = Image::get_image_data_size(tw, th, format, use_mipmaps);
+ return layers;
+}
+bool StreamTextureLayered::has_mipmaps() const {
+ return mipmaps;
+}
- Vector<uint8_t> img_data;
- img_data.resize(total_size);
+TextureLayered::LayeredType StreamTextureLayered::get_layered_type() const {
- {
- uint8_t *w = img_data.ptrw();
- int bytes = f->get_buffer(w, total_size);
- if (bytes != total_size) {
- if (r_error) {
- *r_error = ERR_FILE_CORRUPT;
- }
- f->close();
- memdelete(f);
- ERR_FAIL_V(RES());
- }
- }
+ return layered_type;
+}
- image->create(tw, th, use_mipmaps, format, img_data);
- }
+RID StreamTextureLayered::get_rid() const {
- images.push_back(image);
+ if (!texture.is_valid()) {
+ texture = RS::get_singleton()->texture_2d_layered_placeholder_create(RS::TextureLayeredType(layered_type));
}
+ return texture;
+}
- Error err = lt->create_from_images(images);
- if (err != OK) {
- *r_error = err;
- return RES();
+Ref<Image> StreamTextureLayered::get_layer_data(int p_layer) const {
+
+ if (texture.is_valid()) {
+ return RS::get_singleton()->texture_2d_layer_get(texture, p_layer);
} else {
+ return Ref<Image>();
+ }
+}
+
+void StreamTextureLayered::reload_from_file() {
- if (r_error)
- *r_error = OK;
+ String path = get_path();
+ if (!path.is_resource_file())
+ return;
+
+ path = ResourceLoader::path_remap(path); //remap for translation
+ path = ResourceLoader::import_remap(path); //remap for import
+ if (!path.is_resource_file())
+ return;
+
+ load(path);
+}
+
+void StreamTextureLayered::_validate_property(PropertyInfo &property) const {
+}
+
+void StreamTextureLayered::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("load", "path"), &StreamTextureLayered::load);
+ ClassDB::bind_method(D_METHOD("get_load_path"), &StreamTextureLayered::get_load_path);
+
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "load_path", PROPERTY_HINT_FILE, "*.stex"), "load", "get_load_path");
+}
+
+StreamTextureLayered::StreamTextureLayered(LayeredType p_type) {
+
+ layered_type = p_type;
+ format = Image::FORMAT_MAX;
+ w = 0;
+ h = 0;
+ layers = 0;
+ mipmaps = false;
+}
+
+StreamTextureLayered::~StreamTextureLayered() {
+
+ if (texture.is_valid()) {
+ RS::get_singleton()->free(texture);
+ }
+}
+
+/////////////////////////////////////////////////
+
+RES ResourceFormatLoaderStreamTextureLayered::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
+
+ Ref<StreamTextureLayered> st;
+ if (p_path.get_extension().to_lower() == "stexarray") {
+ Ref<StreamTexture2DArray> s;
+ s.instance();
+ st = s;
+ } else if (p_path.get_extension().to_lower() == "scube") {
+ Ref<StreamCubemap> s;
+ s.instance();
+ st = s;
+ } else if (p_path.get_extension().to_lower() == "scubearray") {
+ Ref<StreamCubemapArray> s;
+ s.instance();
+ st = s;
+ } else {
+ if (r_error) {
+ *r_error = ERR_FILE_UNRECOGNIZED;
+ }
+ return RES();
}
+ Error err = st->load(p_path);
+ if (r_error)
+ *r_error = err;
+ if (err != OK)
+ return RES();
- return lt;
+ return st;
}
-void ResourceFormatLoaderTextureLayered::get_recognized_extensions(List<String> *p_extensions) const {
+void ResourceFormatLoaderStreamTextureLayered::get_recognized_extensions(List<String> *p_extensions) const {
- p_extensions->push_back("cube");
- p_extensions->push_back("cubearr");
- p_extensions->push_back("tex2darr");
+ p_extensions->push_back("stexarray");
+ p_extensions->push_back("scube");
+ p_extensions->push_back("scubearray");
}
-bool ResourceFormatLoaderTextureLayered::handles_type(const String &p_type) const {
- return p_type == "Texture2DArray" || p_type == "Cubemap" || p_type == "CubemapArray";
+bool ResourceFormatLoaderStreamTextureLayered::handles_type(const String &p_type) const {
+ return p_type == "StreamTexture2DArray" || p_type == "StreamCubemap" || p_type == "StreamCubemapArray";
}
-String ResourceFormatLoaderTextureLayered::get_resource_type(const String &p_path) const {
+String ResourceFormatLoaderStreamTextureLayered::get_resource_type(const String &p_path) const {
- if (p_path.get_extension().to_lower() == "cube")
- return "Cubemap";
- if (p_path.get_extension().to_lower() == "cubearr")
- return "CubemapArray";
- if (p_path.get_extension().to_lower() == "tex2darr")
- return "Texture2DArray";
+ if (p_path.get_extension().to_lower() == "stexarray")
+ return "StreamTexture2DArray";
+ if (p_path.get_extension().to_lower() == "scube")
+ return "StreamCubemap";
+ if (p_path.get_extension().to_lower() == "scubearray")
+ return "StreamCubemapArray";
return "";
}
diff --git a/scene/resources/texture.h b/scene/resources/texture.h
index 5d5f438eba..5d4131ec4c 100644
--- a/scene/resources/texture.h
+++ b/scene/resources/texture.h
@@ -132,9 +132,9 @@ public:
~ImageTexture();
};
-class StreamTexture : public Texture2D {
+class StreamTexture2D : public Texture2D {
- GDCLASS(StreamTexture, Texture2D);
+ GDCLASS(StreamTexture2D, Texture2D);
public:
enum DataFormat {
@@ -181,8 +181,8 @@ protected:
public:
static Ref<Image> load_image_from_file(FileAccess *p_file, int p_size_limit);
- typedef void (*TextureFormatRequestCallback)(const Ref<StreamTexture> &);
- typedef void (*TextureFormatRoughnessRequestCallback)(const Ref<StreamTexture> &, const String &p_normal_path, RS::TextureDetectRoughnessChannel p_roughness_channel);
+ typedef void (*TextureFormatRequestCallback)(const Ref<StreamTexture2D> &);
+ typedef void (*TextureFormatRoughnessRequestCallback)(const Ref<StreamTexture2D> &, const String &p_normal_path, RS::TextureDetectRoughnessChannel p_roughness_channel);
static TextureFormatRequestCallback request_3d_callback;
static TextureFormatRoughnessRequestCallback request_roughness_callback;
@@ -207,11 +207,11 @@ public:
virtual Ref<Image> get_data() const;
- StreamTexture();
- ~StreamTexture();
+ StreamTexture2D();
+ ~StreamTexture2D();
};
-class ResourceFormatLoaderStreamTexture : public ResourceFormatLoader {
+class ResourceFormatLoaderStreamTexture2D : public ResourceFormatLoader {
public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
@@ -349,10 +349,34 @@ public:
};
class TextureLayered : public Texture {
-
GDCLASS(TextureLayered, Texture);
- RS::TextureLayeredType layered_type;
+protected:
+ static void _bind_methods();
+
+public:
+ enum LayeredType {
+ LAYERED_TYPE_2D_ARRAY,
+ LAYERED_TYPE_CUBEMAP,
+ LAYERED_TYPE_CUBEMAP_ARRAY
+ };
+
+ virtual Image::Format get_format() const = 0;
+ virtual LayeredType get_layered_type() const = 0;
+ virtual int get_width() const = 0;
+ virtual int get_height() const = 0;
+ virtual int get_layers() const = 0;
+ virtual bool has_mipmaps() const = 0;
+ virtual Ref<Image> get_layer_data(int p_layer) const = 0;
+};
+
+VARIANT_ENUM_CAST(TextureLayered::LayeredType)
+
+class ImageTextureLayered : public TextureLayered {
+
+ GDCLASS(ImageTextureLayered, TextureLayered);
+
+ LayeredType layered_type;
mutable RID texture;
Image::Format format;
@@ -370,57 +394,137 @@ protected:
static void _bind_methods();
public:
- Image::Format get_format() const;
- uint32_t get_width() const;
- uint32_t get_height() const;
- uint32_t get_layers() const;
- bool has_mipmaps() const;
+ virtual Image::Format get_format() const;
+ virtual int get_width() const;
+ virtual int get_height() const;
+ virtual int get_layers() const;
+ virtual bool has_mipmaps() const;
+ virtual LayeredType get_layered_type() const;
Error create_from_images(Vector<Ref<Image>> p_images);
void update_layer(const Ref<Image> &p_image, int p_layer);
- Ref<Image> get_layer_data(int p_layer) const;
+ virtual Ref<Image> get_layer_data(int p_layer) const;
virtual RID get_rid() const;
virtual void set_path(const String &p_path, bool p_take_over = false);
- TextureLayered(RS::TextureLayeredType p_layered_type);
- ~TextureLayered();
+ ImageTextureLayered(LayeredType p_layered_type);
+ ~ImageTextureLayered();
};
-class Texture2DArray : public TextureLayered {
+class Texture2DArray : public ImageTextureLayered {
- GDCLASS(Texture2DArray, TextureLayered)
+ GDCLASS(Texture2DArray, ImageTextureLayered)
public:
Texture2DArray() :
- TextureLayered(RS::TEXTURE_LAYERED_2D_ARRAY) {}
+ ImageTextureLayered(LAYERED_TYPE_2D_ARRAY) {}
};
-class Cubemap : public TextureLayered {
+class Cubemap : public ImageTextureLayered {
- GDCLASS(Cubemap, TextureLayered);
+ GDCLASS(Cubemap, ImageTextureLayered);
public:
Cubemap() :
- TextureLayered(RS::TEXTURE_LAYERED_CUBEMAP) {}
+ ImageTextureLayered(LAYERED_TYPE_CUBEMAP) {}
};
-class CubemapArray : public TextureLayered {
+class CubemapArray : public ImageTextureLayered {
- GDCLASS(CubemapArray, TextureLayered);
+ GDCLASS(CubemapArray, ImageTextureLayered);
public:
CubemapArray() :
- TextureLayered(RS::TEXTURE_LAYERED_CUBEMAP_ARRAY) {}
+ ImageTextureLayered(LAYERED_TYPE_CUBEMAP_ARRAY) {}
};
-class ResourceFormatLoaderTextureLayered : public ResourceFormatLoader {
+class StreamTextureLayered : public TextureLayered {
+
+ GDCLASS(StreamTextureLayered, TextureLayered);
+
public:
- enum Compression {
- COMPRESSION_LOSSLESS,
- COMPRESSION_VRAM,
- COMPRESSION_UNCOMPRESSED
+ enum DataFormat {
+ DATA_FORMAT_IMAGE,
+ DATA_FORMAT_LOSSLESS,
+ DATA_FORMAT_LOSSY,
+ DATA_FORMAT_BASIS_UNIVERSAL,
+ };
+
+ enum {
+ FORMAT_VERSION = 1
};
+ enum FormatBits {
+ FORMAT_MASK_IMAGE_FORMAT = (1 << 20) - 1,
+ FORMAT_BIT_LOSSLESS = 1 << 20,
+ FORMAT_BIT_LOSSY = 1 << 21,
+ FORMAT_BIT_STREAM = 1 << 22,
+ FORMAT_BIT_HAS_MIPMAPS = 1 << 23,
+ };
+
+private:
+ Error _load_data(const String &p_path, Vector<Ref<Image>> &images, int &mipmap_limit, int p_size_limit = 0);
+ String path_to_file;
+ mutable RID texture;
+ Image::Format format;
+ int w, h, layers;
+ bool mipmaps;
+ LayeredType layered_type;
+
+ virtual void reload_from_file();
+
+protected:
+ static void _bind_methods();
+ void _validate_property(PropertyInfo &property) const;
+
+public:
+ Image::Format get_format() const;
+ Error load(const String &p_path);
+ String get_load_path() const;
+ virtual LayeredType get_layered_type() const;
+
+ int get_width() const;
+ int get_height() const;
+ int get_layers() const;
+ virtual bool has_mipmaps() const;
+ virtual RID get_rid() const;
+
+ virtual void set_path(const String &p_path, bool p_take_over);
+
+ virtual Ref<Image> get_layer_data(int p_layer) const;
+
+ StreamTextureLayered(LayeredType p_layered_type);
+ ~StreamTextureLayered();
+};
+
+class StreamTexture2DArray : public StreamTextureLayered {
+
+ GDCLASS(StreamTexture2DArray, StreamTextureLayered)
+public:
+ StreamTexture2DArray() :
+ StreamTextureLayered(LAYERED_TYPE_2D_ARRAY) {}
+};
+
+class StreamCubemap : public StreamTextureLayered {
+
+ GDCLASS(StreamCubemap, StreamTextureLayered);
+
+public:
+ StreamCubemap() :
+ StreamTextureLayered(LAYERED_TYPE_CUBEMAP) {}
+};
+
+class StreamCubemapArray : public StreamTextureLayered {
+
+ GDCLASS(StreamCubemapArray, StreamTextureLayered);
+
+public:
+ StreamCubemapArray() :
+ StreamTextureLayered(LAYERED_TYPE_CUBEMAP_ARRAY) {}
+};
+
+class ResourceFormatLoaderStreamTextureLayered : public ResourceFormatLoader {
+public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp
index 98ebf048dc..325ada69ea 100644
--- a/scene/resources/theme.cpp
+++ b/scene/resources/theme.cpp
@@ -69,7 +69,7 @@ Vector<String> Theme::_get_stylebox_list(const String &p_type) const {
return ilret;
}
-Vector<String> Theme::_get_stylebox_types(void) const {
+Vector<String> Theme::_get_stylebox_types() const {
Vector<String> ilret;
List<StringName> il;
diff --git a/scene/resources/theme.h b/scene/resources/theme.h
index d6d724e3f7..b5043c35e8 100644
--- a/scene/resources/theme.h
+++ b/scene/resources/theme.h
@@ -54,7 +54,7 @@ class Theme : public Resource {
Vector<String> _get_icon_list(const String &p_type) const;
Vector<String> _get_stylebox_list(const String &p_type) const;
- Vector<String> _get_stylebox_types(void) const;
+ Vector<String> _get_stylebox_types() const;
Vector<String> _get_font_list(const String &p_type) const;
Vector<String> _get_color_list(const String &p_type) const;
Vector<String> _get_constant_list(const String &p_type) const;
diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp
index 6f8a53be1a..1b68b7486b 100644
--- a/scene/resources/tile_set.cpp
+++ b/scene/resources/tile_set.cpp
@@ -993,7 +993,8 @@ void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) {
if (p_shapes[i].get_type() == Variant::OBJECT) {
Ref<Shape2D> shape = p_shapes[i];
- if (shape.is_null()) continue;
+ if (shape.is_null())
+ continue;
s.shape = shape;
s.shape_transform = default_transform;
diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h
index 05b43dfb89..5f01959253 100644
--- a/scene/resources/tile_set.h
+++ b/scene/resources/tile_set.h
@@ -48,13 +48,10 @@ public:
Ref<Shape2D> shape;
Transform2D shape_transform;
Vector2 autotile_coord;
- bool one_way_collision;
- float one_way_collision_margin;
+ bool one_way_collision = false;
+ float one_way_collision_margin = 1.0;
- ShapeData() {
- one_way_collision = false;
- one_way_collision_margin = 1.0;
- }
+ ShapeData() {}
};
enum BitmaskMode {
@@ -92,22 +89,18 @@ public:
};
struct AutotileData {
- BitmaskMode bitmask_mode;
- Size2 size;
- int spacing;
- Vector2 icon_coord;
+ BitmaskMode bitmask_mode = BITMASK_2X2;
+ // Default size to prevent invalid value
+ Size2 size = Size2(64, 64);
+ Vector2 icon_coord = Vector2(0, 0);
+ int spacing = 0;
Map<Vector2, uint32_t> flags;
Map<Vector2, Ref<OccluderPolygon2D>> occluder_map;
Map<Vector2, Ref<NavigationPolygon>> navpoly_map;
Map<Vector2, int> priority_map;
Map<Vector2, int> z_index_map;
- // Default size to prevent invalid value
- explicit AutotileData() :
- bitmask_mode(BITMASK_2X2),
- size(64, 64),
- spacing(0),
- icon_coord(0, 0) {}
+ explicit AutotileData() {}
};
private:
@@ -124,16 +117,13 @@ private:
Vector2 navigation_polygon_offset;
Ref<NavigationPolygon> navigation_polygon;
Ref<ShaderMaterial> material;
- TileMode tile_mode;
- Color modulate;
+ TileMode tile_mode = SINGLE_TILE;
+ // Default modulate for back-compat
+ Color modulate = Color(1, 1, 1);
AutotileData autotile_data;
- int z_index;
+ int z_index = 0;
- // Default modulate for back-compat
- explicit TileData() :
- tile_mode(SINGLE_TILE),
- modulate(1, 1, 1),
- z_index(0) {}
+ explicit TileData() {}
};
Map<int, TileData> tile_map;
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp
index 3b245f908a..5637aaec9a 100644
--- a/scene/resources/visual_shader.cpp
+++ b/scene/resources/visual_shader.cpp
@@ -1229,11 +1229,21 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
for (int i = 0; i < output_count; i++) {
String var_name = "n_out" + itos(node) + "p" + itos(i);
switch (vsnode->get_output_port_type(i)) {
- case VisualShaderNode::PORT_TYPE_SCALAR: outputs[i] = "float " + var_name; break;
- case VisualShaderNode::PORT_TYPE_SCALAR_INT: outputs[i] = "int " + var_name; break;
- case VisualShaderNode::PORT_TYPE_VECTOR: outputs[i] = "vec3 " + var_name; break;
- case VisualShaderNode::PORT_TYPE_BOOLEAN: outputs[i] = "bool " + var_name; break;
- case VisualShaderNode::PORT_TYPE_TRANSFORM: outputs[i] = "mat4 " + var_name; break;
+ case VisualShaderNode::PORT_TYPE_SCALAR:
+ outputs[i] = "float " + var_name;
+ break;
+ case VisualShaderNode::PORT_TYPE_SCALAR_INT:
+ outputs[i] = "int " + var_name;
+ break;
+ case VisualShaderNode::PORT_TYPE_VECTOR:
+ outputs[i] = "vec3 " + var_name;
+ break;
+ case VisualShaderNode::PORT_TYPE_BOOLEAN:
+ outputs[i] = "bool " + var_name;
+ break;
+ case VisualShaderNode::PORT_TYPE_TRANSFORM:
+ outputs[i] = "mat4 " + var_name;
+ break;
default: {
}
}
@@ -1243,11 +1253,21 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
for (int i = 0; i < output_count; i++) {
outputs[i] = "n_out" + itos(node) + "p" + itos(i);
switch (vsnode->get_output_port_type(i)) {
- case VisualShaderNode::PORT_TYPE_SCALAR: code += String() + "\tfloat " + outputs[i] + ";\n"; break;
- case VisualShaderNode::PORT_TYPE_SCALAR_INT: code += String() + "\tint " + outputs[i] + ";\n"; break;
- case VisualShaderNode::PORT_TYPE_VECTOR: code += String() + "\tvec3 " + outputs[i] + ";\n"; break;
- case VisualShaderNode::PORT_TYPE_BOOLEAN: code += String() + "\tbool " + outputs[i] + ";\n"; break;
- case VisualShaderNode::PORT_TYPE_TRANSFORM: code += String() + "\tmat4 " + outputs[i] + ";\n"; break;
+ case VisualShaderNode::PORT_TYPE_SCALAR:
+ code += String() + "\tfloat " + outputs[i] + ";\n";
+ break;
+ case VisualShaderNode::PORT_TYPE_SCALAR_INT:
+ code += String() + "\tint " + outputs[i] + ";\n";
+ break;
+ case VisualShaderNode::PORT_TYPE_VECTOR:
+ code += String() + "\tvec3 " + outputs[i] + ";\n";
+ break;
+ case VisualShaderNode::PORT_TYPE_BOOLEAN:
+ code += String() + "\tbool " + outputs[i] + ";\n";
+ break;
+ case VisualShaderNode::PORT_TYPE_TRANSFORM:
+ code += String() + "\tmat4 " + outputs[i] + ";\n";
+ break;
default: {
}
}
diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp
index 7b9953a90f..03db8c3ac5 100644
--- a/scene/resources/visual_shader_nodes.cpp
+++ b/scene/resources/visual_shader_nodes.cpp
@@ -497,9 +497,14 @@ String VisualShaderNodeTexture::generate_global(Shader::Mode p_mode, VisualShade
String u = "uniform sampler2D " + make_unique_id(p_type, p_id, "tex");
switch (texture_type) {
- case TYPE_DATA: break;
- case TYPE_COLOR: u += " : hint_albedo"; break;
- case TYPE_NORMALMAP: u += " : hint_normal"; break;
+ case TYPE_DATA:
+ break;
+ case TYPE_COLOR:
+ u += " : hint_albedo";
+ break;
+ case TYPE_NORMALMAP:
+ u += " : hint_normal";
+ break;
}
return u + ";\n";
}
@@ -869,9 +874,14 @@ String VisualShaderNodeCubemap::generate_global(Shader::Mode p_mode, VisualShade
if (source == SOURCE_TEXTURE) {
String u = "uniform samplerCube " + make_unique_id(p_type, p_id, "cube");
switch (texture_type) {
- case TYPE_DATA: break;
- case TYPE_COLOR: u += " : hint_albedo"; break;
- case TYPE_NORMALMAP: u += " : hint_normal"; break;
+ case TYPE_DATA:
+ break;
+ case TYPE_COLOR:
+ u += " : hint_albedo";
+ break;
+ case TYPE_NORMALMAP:
+ u += " : hint_normal";
+ break;
}
return u + ";\n";
}
@@ -1032,16 +1042,36 @@ String VisualShaderNodeFloatOp::generate_code(Shader::Mode p_mode, VisualShader:
String code = "\t" + p_output_vars[0] + " = ";
switch (op) {
- case OP_ADD: code += p_input_vars[0] + " + " + p_input_vars[1] + ";\n"; break;
- case OP_SUB: code += p_input_vars[0] + " - " + p_input_vars[1] + ";\n"; break;
- case OP_MUL: code += p_input_vars[0] + " * " + p_input_vars[1] + ";\n"; break;
- case OP_DIV: code += p_input_vars[0] + " / " + p_input_vars[1] + ";\n"; break;
- case OP_MOD: code += "mod(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; break;
- case OP_POW: code += "pow(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; break;
- case OP_MAX: code += "max(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; break;
- case OP_MIN: code += "min(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; break;
- case OP_ATAN2: code += "atan(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; break;
- case OP_STEP: code += "step(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; break;
+ case OP_ADD:
+ code += p_input_vars[0] + " + " + p_input_vars[1] + ";\n";
+ break;
+ case OP_SUB:
+ code += p_input_vars[0] + " - " + p_input_vars[1] + ";\n";
+ break;
+ case OP_MUL:
+ code += p_input_vars[0] + " * " + p_input_vars[1] + ";\n";
+ break;
+ case OP_DIV:
+ code += p_input_vars[0] + " / " + p_input_vars[1] + ";\n";
+ break;
+ case OP_MOD:
+ code += "mod(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ break;
+ case OP_POW:
+ code += "pow(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ break;
+ case OP_MAX:
+ code += "max(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ break;
+ case OP_MIN:
+ code += "min(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ break;
+ case OP_ATAN2:
+ code += "atan(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ break;
+ case OP_STEP:
+ code += "step(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ break;
}
return code;
@@ -1124,13 +1154,27 @@ String VisualShaderNodeIntOp::generate_code(Shader::Mode p_mode, VisualShader::T
String code = "\t" + p_output_vars[0] + " = ";
switch (op) {
- case OP_ADD: code += p_input_vars[0] + " + " + p_input_vars[1] + ";\n"; break;
- case OP_SUB: code += p_input_vars[0] + " - " + p_input_vars[1] + ";\n"; break;
- case OP_MUL: code += p_input_vars[0] + " * " + p_input_vars[1] + ";\n"; break;
- case OP_DIV: code += p_input_vars[0] + " / " + p_input_vars[1] + ";\n"; break;
- case OP_MOD: code += p_input_vars[0] + " % " + p_input_vars[1] + ";\n"; break;
- case OP_MAX: code += "max(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; break;
- case OP_MIN: code += "min(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; break;
+ case OP_ADD:
+ code += p_input_vars[0] + " + " + p_input_vars[1] + ";\n";
+ break;
+ case OP_SUB:
+ code += p_input_vars[0] + " - " + p_input_vars[1] + ";\n";
+ break;
+ case OP_MUL:
+ code += p_input_vars[0] + " * " + p_input_vars[1] + ";\n";
+ break;
+ case OP_DIV:
+ code += p_input_vars[0] + " / " + p_input_vars[1] + ";\n";
+ break;
+ case OP_MOD:
+ code += p_input_vars[0] + " % " + p_input_vars[1] + ";\n";
+ break;
+ case OP_MAX:
+ code += "max(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ break;
+ case OP_MIN:
+ code += "min(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ break;
}
return code;
@@ -1209,18 +1253,42 @@ String VisualShaderNodeVectorOp::generate_code(Shader::Mode p_mode, VisualShader
String code = "\t" + p_output_vars[0] + " = ";
switch (op) {
- case OP_ADD: code += p_input_vars[0] + " + " + p_input_vars[1] + ";\n"; break;
- case OP_SUB: code += p_input_vars[0] + " - " + p_input_vars[1] + ";\n"; break;
- case OP_MUL: code += p_input_vars[0] + " * " + p_input_vars[1] + ";\n"; break;
- case OP_DIV: code += p_input_vars[0] + " / " + p_input_vars[1] + ";\n"; break;
- case OP_MOD: code += "mod(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; break;
- case OP_POW: code += "pow(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; break;
- case OP_MAX: code += "max(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; break;
- case OP_MIN: code += "min(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; break;
- case OP_CROSS: code += "cross(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; break;
- case OP_ATAN2: code += "atan(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; break;
- case OP_REFLECT: code += "reflect(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; break;
- case OP_STEP: code += "step(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; break;
+ case OP_ADD:
+ code += p_input_vars[0] + " + " + p_input_vars[1] + ";\n";
+ break;
+ case OP_SUB:
+ code += p_input_vars[0] + " - " + p_input_vars[1] + ";\n";
+ break;
+ case OP_MUL:
+ code += p_input_vars[0] + " * " + p_input_vars[1] + ";\n";
+ break;
+ case OP_DIV:
+ code += p_input_vars[0] + " / " + p_input_vars[1] + ";\n";
+ break;
+ case OP_MOD:
+ code += "mod(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ break;
+ case OP_POW:
+ code += "pow(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ break;
+ case OP_MAX:
+ code += "max(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ break;
+ case OP_MIN:
+ code += "min(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ break;
+ case OP_CROSS:
+ code += "cross(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ break;
+ case OP_ATAN2:
+ code += "atan(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ break;
+ case OP_REFLECT:
+ code += "reflect(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ break;
+ case OP_STEP:
+ code += "step(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ break;
}
return code;
@@ -3752,8 +3820,12 @@ String VisualShaderNodeTextureUniform::generate_global(Shader::Mode p_mode, Visu
else
code += " : hint_albedo;\n";
break;
- case TYPE_NORMALMAP: code += " : hint_normal;\n"; break;
- case TYPE_ANISO: code += " : hint_aniso;\n"; break;
+ case TYPE_NORMALMAP:
+ code += " : hint_normal;\n";
+ break;
+ case TYPE_ANISO:
+ code += " : hint_aniso;\n";
+ break;
}
return code;
@@ -4003,8 +4075,12 @@ String VisualShaderNodeCubemapUniform::generate_global(Shader::Mode p_mode, Visu
else
code += " : hint_albedo;\n";
break;
- case TYPE_NORMALMAP: code += " : hint_normal;\n"; break;
- case TYPE_ANISO: code += " : hint_aniso;\n"; break;
+ case TYPE_NORMALMAP:
+ code += " : hint_normal;\n";
+ break;
+ case TYPE_ANISO:
+ code += " : hint_aniso;\n";
+ break;
}
return code;
diff --git a/scene/scene_string_names.cpp b/scene/scene_string_names.cpp
index 5e3f8b803b..e761354cc9 100644
--- a/scene/scene_string_names.cpp
+++ b/scene/scene_string_names.cpp
@@ -205,4 +205,9 @@ SceneStringNames::SceneStringNames() {
shader_overrides_group = StaticCString::create("_shader_overrides_group_");
shader_overrides_group_active = StaticCString::create("_shader_overrides_group_active_");
+
+#ifndef DISABLE_DEPRECATED
+ use_in_baked_light = StaticCString::create("use_in_baked_light");
+ use_dynamic_gi = StaticCString::create("use_dynamic_gi");
+#endif
}
diff --git a/scene/scene_string_names.h b/scene/scene_string_names.h
index c5de10a6f6..c5c98ba9e5 100644
--- a/scene/scene_string_names.h
+++ b/scene/scene_string_names.h
@@ -210,6 +210,10 @@ public:
StringName shader_overrides_group;
StringName shader_overrides_group_active;
+#ifndef DISABLE_DEPRECATED
+ StringName use_in_baked_light;
+ StringName use_dynamic_gi;
+#endif
enum {
MAX_MATERIALS = 32
};