Added missing z_index parameter to VertexLights2DServer::sample_light().

This commit is contained in:
Relintai 2024-03-27 09:04:59 +01:00
parent 7f5b9650d9
commit 2007ef0f90
4 changed files with 14 additions and 11 deletions

View File

@ -245,6 +245,7 @@
<argument index="1" name="position" type="Vector2" /> <argument index="1" name="position" type="Vector2" />
<argument index="2" name="item_cull_mask" type="int" default="1" /> <argument index="2" name="item_cull_mask" type="int" default="1" />
<argument index="3" name="layer" type="int" default="0" /> <argument index="3" name="layer" type="int" default="0" />
<argument index="4" name="z_index" type="int" default="0" />
<description> <description>
Sample the lighing information at a specific position. Sample the lighing information at a specific position.
</description> </description>

View File

@ -39,7 +39,7 @@ void VertexLights2DServer::VertexLightQuadrant2D::get_lights(List<VertexLightDat
} }
} }
Color VertexLights2DServer::VertexLightQuadrant2D::sample_light(const Color &p_current_color, const Vector2 &p_position, const int p_item_cull_mask, const int p_layer) { Color VertexLights2DServer::VertexLightQuadrant2D::sample_light(const Color &p_current_color, const Vector2 &p_position, const int p_item_cull_mask, const int p_layer, const int p_z_index) {
Color c = p_current_color; Color c = p_current_color;
for (uint32_t i = 0; i < lights.size(); ++i) { for (uint32_t i = 0; i < lights.size(); ++i) {
@ -61,7 +61,9 @@ Color VertexLights2DServer::VertexLightQuadrant2D::sample_light(const Color &p_c
continue; continue;
} }
//TODO z_range if (p_z_index < l->z_range.x || p_z_index > l->z_range.y) {
continue;
}
Vector2 light_to_pos = p_position - l->position; Vector2 light_to_pos = p_position - l->position;
@ -185,7 +187,7 @@ void VertexLights2DServer::VertexLightMap2D::clear() {
} }
} }
Color VertexLights2DServer::VertexLightMap2D::sample_light(const Vector2 &p_position, const int p_item_cull_mask, const int p_layer) { Color VertexLights2DServer::VertexLightMap2D::sample_light(const Vector2 &p_position, const int p_item_cull_mask, const int p_layer, const int p_z_index) {
Color c = base_color; Color c = base_color;
Vector2i quadrant_position = to_quadrant_position(p_position); Vector2i quadrant_position = to_quadrant_position(p_position);
@ -197,7 +199,7 @@ Color VertexLights2DServer::VertexLightMap2D::sample_light(const Vector2 &p_posi
if (quadrants.has(qp)) { if (quadrants.has(qp)) {
VertexLightQuadrant2D *q = quadrants[qp]; VertexLightQuadrant2D *q = quadrants[qp];
c = q->sample_light(c, p_position, p_item_cull_mask, p_layer); c = q->sample_light(c, p_position, p_item_cull_mask, p_layer, p_z_index);
} }
} }
} }

View File

@ -294,11 +294,11 @@ void VertexLights2DServer::light_set_item_cull_mask(RID p_light, const int p_ite
// Sampling // Sampling
Color VertexLights2DServer::sample_light(RID p_map, const Vector2 &p_position, const int p_item_cull_mask, const int p_layer) { Color VertexLights2DServer::sample_light(RID p_map, const Vector2 &p_position, const int p_item_cull_mask, const int p_layer, const int p_z_index) {
VertexLightMap2D *map = map_owner.getornull(p_map); VertexLightMap2D *map = map_owner.getornull(p_map);
ERR_FAIL_COND_V(map == NULL, Color()); ERR_FAIL_COND_V(map == NULL, Color());
return map->sample_light(p_position, p_item_cull_mask, p_layer); return map->sample_light(p_position, p_item_cull_mask, p_layer, p_z_index);
} }
// Rest // Rest
@ -432,9 +432,9 @@ void VertexLights2DServer::_bind_methods() {
// Sampling // Sampling
ClassDB::bind_method(D_METHOD("sample_light", "map", "position", "item_cull_mask", "layer"), &VertexLights2DServer::sample_light, DEFVAL(1), DEFVAL(0)); ClassDB::bind_method(D_METHOD("sample_light", "map", "position", "item_cull_mask", "layer", "z_index"), &VertexLights2DServer::sample_light, DEFVAL(1), DEFVAL(0), DEFVAL(0));
// Rest // Rest, DEFVAL(0)
ClassDB::bind_method(D_METHOD("free", "rid"), &VertexLights2DServer::free); ClassDB::bind_method(D_METHOD("free", "rid"), &VertexLights2DServer::free);

View File

@ -108,7 +108,7 @@ public:
// Sampling // Sampling
Color sample_light(RID p_map, const Vector2 &p_position, const int p_item_cull_mask = 1, const int p_layer = 0); Color sample_light(RID p_map, const Vector2 &p_position, const int p_item_cull_mask = 1, const int p_layer = 0, const int p_z_index = 0);
// Rest // Rest
@ -175,7 +175,7 @@ protected:
void get_lights(List<VertexLightData2D *> *p_lights); void get_lights(List<VertexLightData2D *> *p_lights);
Color sample_light(const Color &p_current_color, const Vector2 &p_local_position, const int p_item_cull_mask, const int p_layer); Color sample_light(const Color &p_current_color, const Vector2 &p_local_position, const int p_item_cull_mask, const int p_layer, const int p_z_index);
VertexLightQuadrant2D() { VertexLightQuadrant2D() {
map = NULL; map = NULL;
@ -203,7 +203,7 @@ protected:
void clear(); void clear();
Color sample_light(const Vector2 &p_position, const int p_item_cull_mask = 1, const int p_layer = 0); Color sample_light(const Vector2 &p_position, const int p_item_cull_mask = 1, const int p_layer = 0, const int p_z_index = 0);
_FORCE_INLINE_ Vector2i to_quadrant_position(const Vector2 &p_position) { _FORCE_INLINE_ Vector2i to_quadrant_position(const Vector2 &p_position) {
return Vector2i(p_position.x / quadrant_size.x, p_position.y / quadrant_size.y); return Vector2i(p_position.x / quadrant_size.x, p_position.y / quadrant_size.y);