diff options
author | reduz <reduzio@gmail.com> | 2020-11-26 09:50:21 -0300 |
---|---|---|
committer | reduz <reduzio@gmail.com> | 2020-11-26 10:49:50 -0300 |
commit | 1bcf3c305bc3d7b0eb293247c08a1c3917eee9b2 (patch) | |
tree | 629b00592dcdc22de5e18afd412ad9cfa60ea7c2 /scene/2d | |
parent | 4e5625ce30364855075c4ac6b7f12575b2964122 (diff) |
Implement signed distance fields for 2D shaders
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/light_occluder_2d.cpp | 14 | ||||
-rw-r--r-- | scene/2d/light_occluder_2d.h | 5 |
2 files changed, 18 insertions, 1 deletions
diff --git a/scene/2d/light_occluder_2d.cpp b/scene/2d/light_occluder_2d.cpp index 0531762ed8..6908fbeada 100644 --- a/scene/2d/light_occluder_2d.cpp +++ b/scene/2d/light_occluder_2d.cpp @@ -265,6 +265,14 @@ String LightOccluder2D::get_configuration_warning() const { return warning; } +void LightOccluder2D::set_as_sdf_collision(bool p_enable) { + sdf_collision = p_enable; + RS::get_singleton()->canvas_light_occluder_set_as_sdf_collision(occluder, sdf_collision); +} +bool LightOccluder2D::is_set_as_sdf_collision() const { + return sdf_collision; +} + void LightOccluder2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_occluder_polygon", "polygon"), &LightOccluder2D::set_occluder_polygon); ClassDB::bind_method(D_METHOD("get_occluder_polygon"), &LightOccluder2D::get_occluder_polygon); @@ -272,14 +280,20 @@ void LightOccluder2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_occluder_light_mask", "mask"), &LightOccluder2D::set_occluder_light_mask); ClassDB::bind_method(D_METHOD("get_occluder_light_mask"), &LightOccluder2D::get_occluder_light_mask); + ClassDB::bind_method(D_METHOD("set_as_sdf_collision", "enable"), &LightOccluder2D::set_as_sdf_collision); + ClassDB::bind_method(D_METHOD("is_set_as_sdf_collision"), &LightOccluder2D::is_set_as_sdf_collision); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "occluder", PROPERTY_HINT_RESOURCE_TYPE, "OccluderPolygon2D"), "set_occluder_polygon", "get_occluder_polygon"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sdf_collision"), "set_as_sdf_collision", "is_set_as_sdf_collision"); ADD_PROPERTY(PropertyInfo(Variant::INT, "light_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_occluder_light_mask", "get_occluder_light_mask"); } LightOccluder2D::LightOccluder2D() { occluder = RS::get_singleton()->canvas_light_occluder_create(); mask = 1; + set_notify_transform(true); + set_as_sdf_collision(true); } LightOccluder2D::~LightOccluder2D() { diff --git a/scene/2d/light_occluder_2d.h b/scene/2d/light_occluder_2d.h index 694097f985..97574af542 100644 --- a/scene/2d/light_occluder_2d.h +++ b/scene/2d/light_occluder_2d.h @@ -84,7 +84,7 @@ class LightOccluder2D : public Node2D { bool enabled; int mask; Ref<OccluderPolygon2D> occluder_polygon; - + bool sdf_collision; void _poly_changed(); protected: @@ -103,6 +103,9 @@ public: void set_occluder_light_mask(int p_mask); int get_occluder_light_mask() const; + void set_as_sdf_collision(bool p_enable); + bool is_set_as_sdf_collision() const; + String get_configuration_warning() const override; LightOccluder2D(); |