summaryrefslogtreecommitdiffstats
path: root/servers
diff options
context:
space:
mode:
Diffstat (limited to 'servers')
-rw-r--r--servers/rendering/rendering_light_culler.cpp18
-rw-r--r--servers/rendering/rendering_light_culler.h33
-rw-r--r--servers/text/text_server_extension.cpp9
-rw-r--r--servers/text/text_server_extension.h2
-rw-r--r--servers/text_server.cpp1
-rw-r--r--servers/text_server.h1
6 files changed, 58 insertions, 6 deletions
diff --git a/servers/rendering/rendering_light_culler.cpp b/servers/rendering/rendering_light_culler.cpp
index fdf0d73654..0889898f0b 100644
--- a/servers/rendering/rendering_light_culler.cpp
+++ b/servers/rendering/rendering_light_culler.cpp
@@ -427,15 +427,19 @@ bool RenderingLightCuller::_add_light_camera_planes(LightCullPlanes &r_cull_plan
uint8_t *entry = &data.LUT_entries[lookup][0];
int n_edges = data.LUT_entry_sizes[lookup] - 1;
+ const Vector3 &pt2 = p_light_source.pos;
+
for (int e = 0; e < n_edges; e++) {
int i0 = entry[e];
int i1 = entry[e + 1];
const Vector3 &pt0 = data.frustum_points[i0];
const Vector3 &pt1 = data.frustum_points[i1];
- // Create plane from 3 points.
- Plane p(pt0, pt1, p_light_source.pos);
- r_cull_planes.add_cull_plane(p);
+ if (!_is_colinear_tri(pt0, pt1, pt2)) {
+ // Create plane from 3 points.
+ Plane p(pt0, pt1, pt2);
+ r_cull_planes.add_cull_plane(p);
+ }
}
// Last to 0 edge.
@@ -446,9 +450,11 @@ bool RenderingLightCuller::_add_light_camera_planes(LightCullPlanes &r_cull_plan
const Vector3 &pt0 = data.frustum_points[i0];
const Vector3 &pt1 = data.frustum_points[i1];
- // Create plane from 3 points.
- Plane p(pt0, pt1, p_light_source.pos);
- r_cull_planes.add_cull_plane(p);
+ if (!_is_colinear_tri(pt0, pt1, pt2)) {
+ // Create plane from 3 points.
+ Plane p(pt0, pt1, pt2);
+ r_cull_planes.add_cull_plane(p);
+ }
}
#ifdef LIGHT_CULLER_DEBUG_LOGGING
diff --git a/servers/rendering/rendering_light_culler.h b/servers/rendering/rendering_light_culler.h
index 602543850a..0bf975430b 100644
--- a/servers/rendering/rendering_light_culler.h
+++ b/servers/rendering/rendering_light_culler.h
@@ -163,6 +163,39 @@ private:
bool _prepare_light(const RendererSceneCull::Instance &p_instance, int32_t p_directional_light_id = -1);
+ // Avoid adding extra culling planes derived from near colinear triangles.
+ // The normals derived from these will be inaccurate, and can lead to false
+ // culling of objects that should be within the light volume.
+ bool _is_colinear_tri(const Vector3 &p_a, const Vector3 &p_b, const Vector3 &p_c) const {
+ // Lengths of sides a, b and c.
+ float la = (p_b - p_a).length();
+ float lb = (p_c - p_b).length();
+ float lc = (p_c - p_a).length();
+
+ // Get longest side into lc.
+ if (lb < la) {
+ SWAP(la, lb);
+ }
+ if (lc < lb) {
+ SWAP(lb, lc);
+ }
+
+ // Prevent divide by zero.
+ if (lc > 0.00001f) {
+ // If the summed length of the smaller two
+ // sides is close to the length of the longest side,
+ // the points are colinear, and the triangle is near degenerate.
+ float ld = ((la + lb) - lc) / lc;
+
+ // ld will be close to zero for colinear tris.
+ return ld < 0.00001f;
+ }
+
+ // Don't create planes from tiny triangles,
+ // they won't be accurate.
+ return true;
+ }
+
// Internal version uses LightSource.
bool _add_light_camera_planes(LightCullPlanes &r_cull_planes, const LightSource &p_light_source);
diff --git a/servers/text/text_server_extension.cpp b/servers/text/text_server_extension.cpp
index eb9f1c1484..53e1d119fd 100644
--- a/servers/text/text_server_extension.cpp
+++ b/servers/text/text_server_extension.cpp
@@ -341,6 +341,7 @@ void TextServerExtension::_bind_methods() {
GDVIRTUAL_BIND(_string_to_upper, "string", "language");
GDVIRTUAL_BIND(_string_to_lower, "string", "language");
+ GDVIRTUAL_BIND(_string_to_title, "string", "language");
GDVIRTUAL_BIND(_parse_structured_text, "parser_type", "args", "text");
@@ -1507,6 +1508,14 @@ String TextServerExtension::string_to_upper(const String &p_string, const String
return p_string;
}
+String TextServerExtension::string_to_title(const String &p_string, const String &p_language) const {
+ String ret;
+ if (GDVIRTUAL_CALL(_string_to_title, p_string, p_language, ret)) {
+ return ret;
+ }
+ return p_string;
+}
+
String TextServerExtension::string_to_lower(const String &p_string, const String &p_language) const {
String ret;
if (GDVIRTUAL_CALL(_string_to_lower, p_string, p_language, ret)) {
diff --git a/servers/text/text_server_extension.h b/servers/text/text_server_extension.h
index 84d68de4fa..53d30abee4 100644
--- a/servers/text/text_server_extension.h
+++ b/servers/text/text_server_extension.h
@@ -566,8 +566,10 @@ public:
virtual String string_to_upper(const String &p_string, const String &p_language = "") const override;
virtual String string_to_lower(const String &p_string, const String &p_language = "") const override;
+ virtual String string_to_title(const String &p_string, const String &p_language = "") const override;
GDVIRTUAL2RC(String, _string_to_upper, const String &, const String &);
GDVIRTUAL2RC(String, _string_to_lower, const String &, const String &);
+ GDVIRTUAL2RC(String, _string_to_title, const String &, const String &);
TypedArray<Vector3i> parse_structured_text(StructuredTextParser p_parser_type, const Array &p_args, const String &p_text) const;
GDVIRTUAL3RC(TypedArray<Vector3i>, _parse_structured_text, StructuredTextParser, const Array &, const String &);
diff --git a/servers/text_server.cpp b/servers/text_server.cpp
index 078ee27753..fac9e32d01 100644
--- a/servers/text_server.cpp
+++ b/servers/text_server.cpp
@@ -491,6 +491,7 @@ void TextServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("string_to_upper", "string", "language"), &TextServer::string_to_upper, DEFVAL(""));
ClassDB::bind_method(D_METHOD("string_to_lower", "string", "language"), &TextServer::string_to_lower, DEFVAL(""));
+ ClassDB::bind_method(D_METHOD("string_to_title", "string", "language"), &TextServer::string_to_title, DEFVAL(""));
ClassDB::bind_method(D_METHOD("parse_structured_text", "parser_type", "args", "text"), &TextServer::parse_structured_text);
diff --git a/servers/text_server.h b/servers/text_server.h
index 4a16ae64e8..396d7ca8e5 100644
--- a/servers/text_server.h
+++ b/servers/text_server.h
@@ -546,6 +546,7 @@ public:
// Other string operations.
virtual String string_to_upper(const String &p_string, const String &p_language = "") const = 0;
virtual String string_to_lower(const String &p_string, const String &p_language = "") const = 0;
+ virtual String string_to_title(const String &p_string, const String &p_language = "") const = 0;
TypedArray<Vector3i> parse_structured_text(StructuredTextParser p_parser_type, const Array &p_args, const String &p_text) const;