Merge pull request #39169 from lawnjelly/light2d_layer_fix

3.2 Make Light2D respect CanvasLayer layer_min and layer_max
This commit is contained in:
Rémi Verschelde 2020-06-10 13:35:37 +02:00 committed by GitHub
commit c9a8309e73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 11 deletions

View File

@ -204,10 +204,7 @@ void VisualServerCanvas::_render_canvas_item(Item *p_canvas_item, const Transfor
} }
} }
void VisualServerCanvas::_light_mask_canvas_items(int p_z, RasterizerCanvas::Item *p_canvas_item, RasterizerCanvas::Light *p_masked_lights) { void VisualServerCanvas::_light_mask_canvas_items(int p_z, RasterizerCanvas::Item *p_canvas_item, RasterizerCanvas::Light *p_masked_lights, int p_canvas_layer_id) {
if (!p_masked_lights)
return;
RasterizerCanvas::Item *ci = p_canvas_item; RasterizerCanvas::Item *ci = p_canvas_item;
@ -216,7 +213,7 @@ void VisualServerCanvas::_light_mask_canvas_items(int p_z, RasterizerCanvas::Ite
RasterizerCanvas::Light *light = p_masked_lights; RasterizerCanvas::Light *light = p_masked_lights;
while (light) { while (light) {
if (ci->light_mask & light->item_mask && p_z >= light->z_min && p_z <= light->z_max && ci->global_rect_cache.intersects_transformed(light->xform_cache, light->rect_cache)) { if ((p_canvas_layer_id >= light->layer_min) && (p_canvas_layer_id <= light->layer_max) && (ci->light_mask & light->item_mask) && (p_z >= light->z_min) && (p_z <= light->z_max) && (ci->global_rect_cache.intersects_transformed(light->xform_cache, light->rect_cache))) {
ci->light_masked = true; ci->light_masked = true;
} }
@ -227,7 +224,7 @@ void VisualServerCanvas::_light_mask_canvas_items(int p_z, RasterizerCanvas::Ite
} }
} }
void VisualServerCanvas::render_canvas(Canvas *p_canvas, const Transform2D &p_transform, RasterizerCanvas::Light *p_lights, RasterizerCanvas::Light *p_masked_lights, const Rect2 &p_clip_rect) { void VisualServerCanvas::render_canvas(Canvas *p_canvas, const Transform2D &p_transform, RasterizerCanvas::Light *p_lights, RasterizerCanvas::Light *p_masked_lights, const Rect2 &p_clip_rect, int p_canvas_layer_id) {
VSG::canvas_render->canvas_begin(); VSG::canvas_render->canvas_begin();
@ -267,7 +264,7 @@ void VisualServerCanvas::render_canvas(Canvas *p_canvas, const Transform2D &p_tr
continue; continue;
if (p_masked_lights) { if (p_masked_lights) {
_light_mask_canvas_items(VS::CANVAS_ITEM_Z_MIN + i, z_list[i], p_masked_lights); _light_mask_canvas_items(VS::CANVAS_ITEM_Z_MIN + i, z_list[i], p_masked_lights, p_canvas_layer_id);
} }
VSG::canvas_render->canvas_render_items(z_list[i], VS::CANVAS_ITEM_Z_MIN + i, p_canvas->modulate, p_lights, p_transform); VSG::canvas_render->canvas_render_items(z_list[i], VS::CANVAS_ITEM_Z_MIN + i, p_canvas->modulate, p_lights, p_transform);

View File

@ -159,13 +159,13 @@ public:
private: private:
void _render_canvas_item_tree(Item *p_canvas_item, const Transform2D &p_transform, const Rect2 &p_clip_rect, const Color &p_modulate, RasterizerCanvas::Light *p_lights); void _render_canvas_item_tree(Item *p_canvas_item, const Transform2D &p_transform, const Rect2 &p_clip_rect, const Color &p_modulate, RasterizerCanvas::Light *p_lights);
void _render_canvas_item(Item *p_canvas_item, const Transform2D &p_transform, const Rect2 &p_clip_rect, const Color &p_modulate, int p_z, RasterizerCanvas::Item **z_list, RasterizerCanvas::Item **z_last_list, Item *p_canvas_clip, Item *p_material_owner); void _render_canvas_item(Item *p_canvas_item, const Transform2D &p_transform, const Rect2 &p_clip_rect, const Color &p_modulate, int p_z, RasterizerCanvas::Item **z_list, RasterizerCanvas::Item **z_last_list, Item *p_canvas_clip, Item *p_material_owner);
void _light_mask_canvas_items(int p_z, RasterizerCanvas::Item *p_canvas_item, RasterizerCanvas::Light *p_masked_lights); void _light_mask_canvas_items(int p_z, RasterizerCanvas::Item *p_canvas_item, RasterizerCanvas::Light *p_masked_lights, int p_canvas_layer_id);
RasterizerCanvas::Item **z_list; RasterizerCanvas::Item **z_list;
RasterizerCanvas::Item **z_last_list; RasterizerCanvas::Item **z_last_list;
public: public:
void render_canvas(Canvas *p_canvas, const Transform2D &p_transform, RasterizerCanvas::Light *p_lights, RasterizerCanvas::Light *p_masked_lights, const Rect2 &p_clip_rect); void render_canvas(Canvas *p_canvas, const Transform2D &p_transform, RasterizerCanvas::Light *p_lights, RasterizerCanvas::Light *p_masked_lights, const Rect2 &p_clip_rect, int p_canvas_layer_id);
RID canvas_create(); RID canvas_create();
void canvas_set_item_mirroring(RID p_canvas, RID p_item, const Point2 &p_mirroring); void canvas_set_item_mirroring(RID p_canvas, RID p_item, const Point2 &p_mirroring);

View File

@ -229,15 +229,16 @@ void VisualServerViewport::_draw_viewport(Viewport *p_viewport, ARVRInterface::E
RasterizerCanvas::Light *canvas_lights = NULL; RasterizerCanvas::Light *canvas_lights = NULL;
RasterizerCanvas::Light *ptr = lights; RasterizerCanvas::Light *ptr = lights;
int canvas_layer_id = E->get()->layer;
while (ptr) { while (ptr) {
if (E->get()->layer >= ptr->layer_min && E->get()->layer <= ptr->layer_max) { if (canvas_layer_id >= ptr->layer_min && canvas_layer_id <= ptr->layer_max) {
ptr->next_ptr = canvas_lights; ptr->next_ptr = canvas_lights;
canvas_lights = ptr; canvas_lights = ptr;
} }
ptr = ptr->filter_next_ptr; ptr = ptr->filter_next_ptr;
} }
VSG::canvas->render_canvas(canvas, xform, canvas_lights, lights_with_mask, clip_rect); VSG::canvas->render_canvas(canvas, xform, canvas_lights, lights_with_mask, clip_rect, canvas_layer_id);
i++; i++;
if (scenario_draw_canvas_bg && E->key().get_layer() >= scenario_canvas_max_layer) { if (scenario_draw_canvas_bg && E->key().get_layer() >= scenario_canvas_max_layer) {