Added attenuation and range properties to vertex light 2ds.

This commit is contained in:
Relintai 2024-03-25 21:55:27 +01:00
parent d7a54d702d
commit 42171f1fa2
4 changed files with 84 additions and 3 deletions

View File

@ -44,6 +44,24 @@ void VertexLight2D::set_enabled(const bool p_enabled) {
_update_light_visibility();
}
Vector2i VertexLight2D::get_range() {
return _range;
}
void VertexLight2D::set_range(const Vector2i &p_range) {
_range = p_range;
VertexLights2DServer::get_singleton()->light_set_z_range(_vertex_light, _range);
}
real_t VertexLight2D::get_attenuation() {
return _attenuation;
}
void VertexLight2D::set_attenuation(const real_t p_attenuation) {
_attenuation = p_attenuation;
VertexLights2DServer::get_singleton()->light_set_attenuation(_vertex_light, _attenuation);
}
Color VertexLight2D::get_color() {
return _color;
}
@ -93,6 +111,8 @@ VertexLight2D::VertexLight2D() {
_vertex_light = RID_PRIME(VertexLights2DServer::get_singleton()->light_create());
_enabled = true;
_range = Vector2i(32, 32);
_attenuation = 1;
_color = Color(1, 1, 1, 1);
_item_cull_mask = 1;
_z_range = Vector2i(-1024, 1024);
@ -142,13 +162,22 @@ void VertexLight2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &VertexLight2D::set_enabled);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "get_is_enabled");
ClassDB::bind_method(D_METHOD("get_range"), &VertexLight2D::get_range);
ClassDB::bind_method(D_METHOD("set_range", "range"), &VertexLight2D::set_range);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "range"), "set_range", "get_range");
ClassDB::bind_method(D_METHOD("get_attenuation"), &VertexLight2D::get_attenuation);
ClassDB::bind_method(D_METHOD("set_attenuation", "attenuation"), &VertexLight2D::set_attenuation);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "attenuation", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_attenuation", "get_attenuation");
ClassDB::bind_method(D_METHOD("get_color"), &VertexLight2D::get_color);
ClassDB::bind_method(D_METHOD("set_color", "color"), &VertexLight2D::set_color);
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
ClassDB::bind_method(D_METHOD("get_mode"), &VertexLight2D::get_mode);
ClassDB::bind_method(D_METHOD("set_mode", "mode"), &VertexLight2D::set_mode);
ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Add,Sub,Mix,Mask"), "set_mode", "get_mode");
//,Mask
ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Add,Sub,Mix"), "set_mode", "get_mode");
ClassDB::bind_method(D_METHOD("get_z_range"), &VertexLight2D::get_z_range);
ClassDB::bind_method(D_METHOD("set_z_range", "z_range"), &VertexLight2D::set_z_range);

View File

@ -55,6 +55,12 @@ public:
bool get_is_enabled();
void set_enabled(const bool p_enabled);
Vector2i get_range();
void set_range(const Vector2i &p_range);
real_t get_attenuation();
void set_attenuation(const real_t p_attenuation);
Color get_color();
void set_color(const Color &p_color);
@ -83,6 +89,8 @@ protected:
RID _vertex_light;
bool _enabled;
Vector2i _range;
real_t _attenuation;
Color _color;
VertexLight2DMode _mode;
Vector2i _z_range;

View File

@ -154,6 +154,32 @@ void VertexLights2DServer::light_set_position(RID p_light, const Vector2 &p_posi
light->position = p_position;
}
Vector2i VertexLights2DServer::light_get_range(RID p_light) {
const VertexLightData2D *light = light_owner.getornull(p_light);
ERR_FAIL_COND_V(light == NULL, Vector2i());
return light->range;
}
void VertexLights2DServer::light_set_range(RID p_light, const Vector2i &p_range) {
VertexLightData2D *light = light_owner.getornull(p_light);
ERR_FAIL_COND(light == NULL);
light->range = p_range;
}
real_t VertexLights2DServer::light_get_attenuation(RID p_light) {
const VertexLightData2D *light = light_owner.getornull(p_light);
ERR_FAIL_COND_V(light == NULL, 0);
return light->attenuation;
}
void VertexLights2DServer::light_set_attenuation(RID p_light, const real_t p_attenuation) {
VertexLightData2D *light = light_owner.getornull(p_light);
ERR_FAIL_COND(light == NULL);
light->attenuation = p_attenuation;
}
Color VertexLights2DServer::light_get_color(RID p_light) {
const VertexLightData2D *light = light_owner.getornull(p_light);
ERR_FAIL_COND_V(light == NULL, Color());
@ -291,6 +317,12 @@ void VertexLights2DServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("light_get_position", "light"), &VertexLights2DServer::light_get_position);
ClassDB::bind_method(D_METHOD("light_set_position", "light", "position"), &VertexLights2DServer::light_set_position);
ClassDB::bind_method(D_METHOD("light_get_range", "light"), &VertexLights2DServer::light_get_range);
ClassDB::bind_method(D_METHOD("light_set_range", "light", "range"), &VertexLights2DServer::light_set_range);
ClassDB::bind_method(D_METHOD("light_get_attenuation", "light"), &VertexLights2DServer::light_get_attenuation);
ClassDB::bind_method(D_METHOD("light_set_attenuation", "light", "attenuation"), &VertexLights2DServer::light_set_attenuation);
ClassDB::bind_method(D_METHOD("light_get_color", "light"), &VertexLights2DServer::light_get_color);
ClassDB::bind_method(D_METHOD("light_set_color", "light", "color"), &VertexLights2DServer::light_set_color);

View File

@ -81,6 +81,12 @@ public:
Vector2 light_get_position(RID p_light);
void light_set_position(RID p_light, const Vector2 &p_position);
Vector2i light_get_range(RID p_light);
void light_set_range(RID p_light, const Vector2i &p_range);
real_t light_get_attenuation(RID p_light);
void light_set_attenuation(RID p_light, const real_t p_attenuation);
Color light_get_color(RID p_light);
void light_set_color(RID p_light, const Color &p_color);
@ -96,6 +102,8 @@ public:
int light_get_item_cull_mask(RID p_light);
void light_set_item_cull_mask(RID p_light, const int p_item_cull_mask);
// Sampling
// Rest
void free(RID p_rid);
@ -118,6 +126,8 @@ protected:
public:
bool enabled;
Vector2 position;
Vector2i range;
real_t attenuation;
Color color;
VertexLights2DServer::VertexLight2DMode mode;
Vector2i z_range;
@ -134,6 +144,8 @@ protected:
quadrant = NULL;
enabled = true;
range = Vector2i(32, 32);
attenuation = 1;
color = Color(1, 1, 1, 1);
item_cull_mask = 1;
z_range = Vector2i(-1024, 1024);