Fix issues with vertex lights.

This commit is contained in:
Relintai 2024-03-26 14:10:14 +01:00
parent 6e8073bbb6
commit af243a1111

View File

@ -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<real_t>(l->range.x);
light_to_pos_normal_space.y /= static_cast<real_t>(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);
}
}