From af243a11111ff0bb4eabeb7d08b0a616b8b301c1 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 26 Mar 2024 14:10:14 +0100 Subject: [PATCH] Fix issues with vertex lights. --- .../vertex_lights_2d/vertex_light_data.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/modules/vertex_lights_2d/vertex_light_data.cpp b/modules/vertex_lights_2d/vertex_light_data.cpp index ac33ed1a1..3c1b01ca7 100644 --- a/modules/vertex_lights_2d/vertex_light_data.cpp +++ b/modules/vertex_lights_2d/vertex_light_data.cpp @@ -57,12 +57,14 @@ Color VertexLights2DServer::VertexLightQuadrant2D::sample_light(const Color &p_c continue; } - if (p_layer < l->z_range.x || p_layer > l->z_range.y) { + if (p_layer < l->layer_range.x || p_layer > l->layer_range.y) { continue; } - + + //TODO z_range + Vector2 light_to_pos = p_position - l->position; - + Vector2 light_to_pos_normal_space = light_to_pos; light_to_pos_normal_space.x /= static_cast(l->range.x); light_to_pos_normal_space.y /= static_cast(l->range.y); @@ -73,7 +75,7 @@ Color VertexLights2DServer::VertexLightQuadrant2D::sample_light(const Color &p_c if (ltpnsl >= 1) { continue; } - + real_t attenuation = pow(1.0 - ltpnsl, l->attenuation); Color ac = l->color * attenuation; @@ -89,8 +91,10 @@ Color VertexLights2DServer::VertexLightQuadrant2D::sample_light(const Color &p_c c = c.blend(ac); } break; } + + c = c.clamp(); } - + return c; } @@ -159,6 +163,7 @@ VertexLights2DServer::VertexLightQuadrant2D *VertexLights2DServer::VertexLightMa void VertexLights2DServer::VertexLightMap2D::set_light_position(VertexLightData2D *p_light, const Vector2 &p_position) { remove_light(p_light); + p_light->position = p_position; add_light(p_light); } @@ -184,14 +189,14 @@ Color VertexLights2DServer::VertexLightMap2D::sample_light(const Vector2 &p_posi Color c = Color(); Vector2i quadrant_position = to_quadrant_position(p_position); - + for (int x = quadrant_position.x - 1; x <= quadrant_position.x + 1; ++x) { for (int y = quadrant_position.y - 1; y <= quadrant_position.y + 1; ++y) { Vector2i qp = Vector2i(x, y); if (quadrants.has(qp)) { VertexLightQuadrant2D *q = quadrants[qp]; - + c = q->sample_light(c, p_position, p_item_cull_mask, p_layer); } }