diff options
-rw-r--r-- | scene/2d/light_2d.cpp | 17 | ||||
-rw-r--r-- | scene/2d/light_2d.h | 1 | ||||
-rw-r--r-- | scene/2d/light_occluder_2d.cpp | 5 | ||||
-rw-r--r-- | servers/visual/visual_server_raster.cpp | 2 |
4 files changed, 24 insertions, 1 deletions
diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index a2112c7d37..9715afeaa4 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -34,10 +34,19 @@ Rect2 Light2D::get_item_rect() const { } +void Light2D::_update_light_visibility() { + + if (!is_inside_tree()) + return; + + VS::get_singleton()->canvas_light_set_enabled(canvas_light,enabled && is_visible()); +} + void Light2D::set_enabled( bool p_enabled) { - VS::get_singleton()->canvas_light_set_enabled(canvas_light,p_enabled); + enabled=p_enabled; + _update_light_visibility(); } bool Light2D::is_enabled() const { @@ -253,16 +262,22 @@ void Light2D::_notification(int p_what) { if (p_what==NOTIFICATION_ENTER_TREE) { VS::get_singleton()->canvas_light_attach_to_canvas( canvas_light, get_canvas() ); + _update_light_visibility(); } if (p_what==NOTIFICATION_TRANSFORM_CHANGED) { VS::get_singleton()->canvas_light_set_transform( canvas_light, get_global_transform()); } + if (p_what==NOTIFICATION_VISIBILITY_CHANGED) { + + _update_light_visibility(); + } if (p_what==NOTIFICATION_EXIT_TREE) { VS::get_singleton()->canvas_light_attach_to_canvas( canvas_light, RID() ); + _update_light_visibility(); } } diff --git a/scene/2d/light_2d.h b/scene/2d/light_2d.h index 0828d9ac33..ca437769e7 100644 --- a/scene/2d/light_2d.h +++ b/scene/2d/light_2d.h @@ -35,6 +35,7 @@ private: Ref<Texture> texture; Vector2 texture_offset; + void _update_light_visibility(); protected: void _notification(int p_what); diff --git a/scene/2d/light_occluder_2d.cpp b/scene/2d/light_occluder_2d.cpp index 6ebd499f71..d98bed0ea3 100644 --- a/scene/2d/light_occluder_2d.cpp +++ b/scene/2d/light_occluder_2d.cpp @@ -93,12 +93,17 @@ void LightOccluder2D::_notification(int p_what) { VS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder,get_canvas()); VS::get_singleton()->canvas_light_occluder_set_transform(occluder,get_global_transform()); + VS::get_singleton()->canvas_light_occluder_set_enabled(occluder,is_visible()); } if (p_what==NOTIFICATION_TRANSFORM_CHANGED) { VS::get_singleton()->canvas_light_occluder_set_transform(occluder,get_global_transform()); } + if (p_what==NOTIFICATION_VISIBILITY_CHANGED) { + + VS::get_singleton()->canvas_light_occluder_set_enabled(occluder,is_visible()); + } if (p_what==NOTIFICATION_DRAW) { diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index 79911121f5..3be272461d 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -7182,6 +7182,8 @@ void VisualServerRaster::_draw_viewport(Viewport *p_viewport,int p_ofs_x, int p_ for(Set<Rasterizer::CanvasLightOccluderInstance*>::Element *F=E->get().canvas->occluders.front();F;F=F->next()) { + if (!F->get()->enabled) + continue; F->get()->xform_cache = xf * F->get()->xform; if (shadow_rect.intersects_transformed(F->get()->xform_cache,F->get()->aabb_cache)) { |