summaryrefslogtreecommitdiffstats
path: root/scene/3d
diff options
context:
space:
mode:
authorGeorge L. Albany <Megacake1234@gmail.com>2024-11-15 20:50:25 +0000
committerGitHub <noreply@github.com>2024-11-15 20:50:25 +0000
commit9767837a7ec40697788765e581131cb2cf172567 (patch)
treed58eaa8daad3e30c8b84a50e70a21f93b05525c5 /scene/3d
parentac1a49725fc038ae11ef9060fecb2b0f9c6333b2 (diff)
parent4a5836e5462554a738b502aa8bbde5e4a051eb56 (diff)
downloadredot-engine-9767837a7ec40697788765e581131cb2cf172567.tar.gz
Merge pull request #864 from Spartan322/merge/6c05ec3
Merge commit godotengine/godot@6c05ec3
Diffstat (limited to 'scene/3d')
-rw-r--r--scene/3d/lightmap_gi.cpp6
-rw-r--r--scene/3d/lightmap_gi.h2
-rw-r--r--scene/3d/visual_instance_3d.cpp48
-rw-r--r--scene/3d/visual_instance_3d.h11
4 files changed, 56 insertions, 11 deletions
diff --git a/scene/3d/lightmap_gi.cpp b/scene/3d/lightmap_gi.cpp
index 8456da3280..8cd6f0f547 100644
--- a/scene/3d/lightmap_gi.cpp
+++ b/scene/3d/lightmap_gi.cpp
@@ -335,9 +335,7 @@ void LightmapGI::_find_meshes_and_lights(Node *p_at_node, Vector<MeshesFound> &m
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()];
+ mf.lightmap_scale = mi->get_lightmap_texel_scale();
Ref<Material> all_override = mi->get_material_override();
for (int i = 0; i < mesh->get_surface_count(); i++) {
@@ -371,7 +369,7 @@ void LightmapGI::_find_meshes_and_lights(Node *p_at_node, Vector<MeshesFound> &m
mf.xform = xf * mesh_xf;
mf.node_path = get_path_to(s);
mf.subindex = i / 2;
- mf.lightmap_scale = 1;
+ mf.lightmap_scale = 1.0;
mf.mesh = mesh;
meshes.push_back(mf);
diff --git a/scene/3d/lightmap_gi.h b/scene/3d/lightmap_gi.h
index 39fca0e415..6efdcf497f 100644
--- a/scene/3d/lightmap_gi.h
+++ b/scene/3d/lightmap_gi.h
@@ -196,7 +196,7 @@ private:
NodePath node_path;
int32_t subindex = 0;
Ref<Mesh> mesh;
- int32_t lightmap_scale = 0;
+ float lightmap_scale = 0.0;
Vector<Ref<Material>> overrides;
};
diff --git a/scene/3d/visual_instance_3d.cpp b/scene/3d/visual_instance_3d.cpp
index 0959c61f3a..68d412dbe2 100644
--- a/scene/3d/visual_instance_3d.cpp
+++ b/scene/3d/visual_instance_3d.cpp
@@ -456,14 +456,48 @@ AABB GeometryInstance3D::get_custom_aabb() const {
return custom_aabb;
}
+void GeometryInstance3D::set_lightmap_texel_scale(float p_scale) {
+ lightmap_texel_scale = p_scale;
+}
+
+float GeometryInstance3D::get_lightmap_texel_scale() const {
+ return lightmap_texel_scale;
+}
+
+#ifndef DISABLE_DEPRECATED
void GeometryInstance3D::set_lightmap_scale(LightmapScale p_scale) {
ERR_FAIL_INDEX(p_scale, LIGHTMAP_SCALE_MAX);
- lightmap_scale = p_scale;
+ switch (p_scale) {
+ case GeometryInstance3D::LIGHTMAP_SCALE_1X:
+ lightmap_texel_scale = 1.0f;
+ break;
+ case GeometryInstance3D::LIGHTMAP_SCALE_2X:
+ lightmap_texel_scale = 2.0f;
+ break;
+ case GeometryInstance3D::LIGHTMAP_SCALE_4X:
+ lightmap_texel_scale = 4.0f;
+ break;
+ case GeometryInstance3D::LIGHTMAP_SCALE_8X:
+ lightmap_texel_scale = 8.0f;
+ break;
+ case GeometryInstance3D::LIGHTMAP_SCALE_MAX:
+ break; // Can't happen, but silences warning.
+ }
}
GeometryInstance3D::LightmapScale GeometryInstance3D::get_lightmap_scale() const {
- return lightmap_scale;
+ // Return closest approximation.
+ if (lightmap_texel_scale < 1.5f) {
+ return GeometryInstance3D::LIGHTMAP_SCALE_1X;
+ } else if (lightmap_texel_scale < 3.0f) {
+ return GeometryInstance3D::LIGHTMAP_SCALE_2X;
+ } else if (lightmap_texel_scale < 6.0f) {
+ return GeometryInstance3D::LIGHTMAP_SCALE_4X;
+ }
+
+ return GeometryInstance3D::LIGHTMAP_SCALE_8X;
}
+#endif // DISABLE_DEPRECATED
void GeometryInstance3D::set_gi_mode(GIMode p_mode) {
switch (p_mode) {
@@ -567,8 +601,13 @@ 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_texel_scale", "scale"), &GeometryInstance3D::set_lightmap_texel_scale);
+ ClassDB::bind_method(D_METHOD("get_lightmap_texel_scale"), &GeometryInstance3D::get_lightmap_texel_scale);
+
+#ifndef DISABLE_DEPRECATED
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);
+#endif // DISABLE_DEPRECATED
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);
@@ -593,7 +632,10 @@ void GeometryInstance3D::_bind_methods() {
ADD_GROUP("Global Illumination", "gi_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "gi_mode", PROPERTY_HINT_ENUM, "Disabled,Static,Dynamic"), "set_gi_mode", "get_gi_mode");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "gi_lightmap_scale", PROPERTY_HINT_ENUM, String::utf8("1×,2×,4×,8×")), "set_lightmap_scale", "get_lightmap_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gi_lightmap_texel_scale", PROPERTY_HINT_RANGE, "0.01,10,0.0001,or_greater"), "set_lightmap_texel_scale", "get_lightmap_texel_scale");
+#ifndef DISABLE_DEPRECATED
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "gi_lightmap_scale", PROPERTY_HINT_ENUM, String::utf8("1×,2×,4×,8×"), PROPERTY_USAGE_NONE), "set_lightmap_scale", "get_lightmap_scale");
+#endif // DISABLE_DEPRECATED
ADD_GROUP("Visibility Range", "visibility_range_");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "visibility_range_begin", PROPERTY_HINT_RANGE, "0.0,4096.0,0.01,or_greater,suffix:m"), "set_visibility_range_begin", "get_visibility_range_begin");
diff --git a/scene/3d/visual_instance_3d.h b/scene/3d/visual_instance_3d.h
index 4c4e5de2e8..48237823a4 100644
--- a/scene/3d/visual_instance_3d.h
+++ b/scene/3d/visual_instance_3d.h
@@ -136,7 +136,7 @@ private:
float extra_cull_margin = 0.0;
AABB custom_aabb;
- LightmapScale lightmap_scale = LIGHTMAP_SCALE_1X;
+ float lightmap_texel_scale = 1.0f;
GIMode gi_mode = GI_MODE_STATIC;
bool ignore_occlusion_culling = false;
@@ -187,8 +187,13 @@ public:
void set_gi_mode(GIMode p_mode);
GIMode get_gi_mode() const;
- void set_lightmap_scale(LightmapScale p_scale);
+ void set_lightmap_texel_scale(float p_scale);
+ float get_lightmap_texel_scale() const;
+
+#ifndef DISABLE_DEPRECATED
+ void set_lightmap_scale(GeometryInstance3D::LightmapScale p_scale);
LightmapScale get_lightmap_scale() const;
+#endif // DISABLE_DEPRECATED
void set_instance_shader_parameter(const StringName &p_name, const Variant &p_value);
Variant get_instance_shader_parameter(const StringName &p_name) const;
@@ -205,8 +210,8 @@ public:
};
VARIANT_ENUM_CAST(GeometryInstance3D::ShadowCastingSetting);
-VARIANT_ENUM_CAST(GeometryInstance3D::LightmapScale);
VARIANT_ENUM_CAST(GeometryInstance3D::GIMode);
+VARIANT_ENUM_CAST(GeometryInstance3D::LightmapScale);
VARIANT_ENUM_CAST(GeometryInstance3D::VisibilityRangeFadeMode);
#endif // VISUAL_INSTANCE_3D_H