Make both lights and occluders stop working if hidden, fixes #2437

This commit is contained in:
Juan Linietsky 2016-01-01 10:45:24 -03:00
parent b78c1e52c2
commit 7879efc50b
4 changed files with 24 additions and 1 deletions

View file

@ -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();
}
}

View file

@ -35,6 +35,7 @@ private:
Ref<Texture> texture;
Vector2 texture_offset;
void _update_light_visibility();
protected:
void _notification(int p_what);

View file

@ -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) {

View file

@ -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)) {