You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Properly transform light rect and occluder rect to perform light2d culling in canvas space
This commit is contained in:
@@ -857,7 +857,7 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend
|
|||||||
Light *light = p_lights;
|
Light *light = p_lights;
|
||||||
|
|
||||||
while (light) {
|
while (light) {
|
||||||
if (light->render_index_cache >= 0 && p_item->light_mask & light->item_mask && p_item->z_final >= light->z_min && p_item->z_final <= light->z_max && p_item->global_rect_cache.intersects_transformed(light->xform_cache, light->rect_cache)) {
|
if (light->render_index_cache >= 0 && p_item->light_mask & light->item_mask && p_item->z_final >= light->z_min && p_item->z_final <= light->z_max && p_item->global_rect_cache.intersects(light->rect_cache)) {
|
||||||
uint32_t light_index = light->render_index_cache;
|
uint32_t light_index = light->render_index_cache;
|
||||||
lights[light_count >> 2] |= light_index << ((light_count & 3) * 8);
|
lights[light_count >> 2] |= light_index << ((light_count & 3) * 8);
|
||||||
|
|
||||||
|
|||||||
@@ -1035,14 +1035,14 @@ void RendererCanvasRenderRD::light_update_shadow(RID p_rid, int p_shadow_index,
|
|||||||
while (instance) {
|
while (instance) {
|
||||||
OccluderPolygon *co = occluder_polygon_owner.get_or_null(instance->occluder);
|
OccluderPolygon *co = occluder_polygon_owner.get_or_null(instance->occluder);
|
||||||
|
|
||||||
|
occluder_count++;
|
||||||
|
|
||||||
if (!co || co->index_array.is_null()) {
|
if (!co || co->index_array.is_null()) {
|
||||||
instance = instance->next;
|
instance = instance->next;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
occluder_count++;
|
if (!(p_light_mask & instance->light_mask) || !p_light_rect.intersects_transformed(instance->xform_cache, instance->aabb_cache)) {
|
||||||
|
|
||||||
if (!(p_light_mask & instance->light_mask) || !p_light_rect.intersects(instance->aabb_cache)) {
|
|
||||||
instance = instance->next;
|
instance = instance->next;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -2353,7 +2353,7 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar
|
|||||||
Light *light = p_lights;
|
Light *light = p_lights;
|
||||||
|
|
||||||
while (light) {
|
while (light) {
|
||||||
if (light->render_index_cache >= 0 && p_item->light_mask & light->item_mask && p_item->z_final >= light->z_min && p_item->z_final <= light->z_max && p_item->global_rect_cache.intersects_transformed(light->xform_cache, light->rect_cache)) {
|
if (light->render_index_cache >= 0 && p_item->light_mask & light->item_mask && p_item->z_final >= light->z_min && p_item->z_final <= light->z_max && p_item->global_rect_cache.intersects(light->rect_cache)) {
|
||||||
uint32_t light_index = light->render_index_cache;
|
uint32_t light_index = light->render_index_cache;
|
||||||
lights[light_count >> 2] |= light_index << ((light_count & 3) * 8);
|
lights[light_count >> 2] |= light_index << ((light_count & 3) * 8);
|
||||||
|
|
||||||
|
|||||||
@@ -413,7 +413,9 @@ void RendererViewport::_draw_viewport(Viewport *p_viewport) {
|
|||||||
cl->xform_cache = xf * cl->xform_cache;
|
cl->xform_cache = xf * cl->xform_cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clip_rect.intersects_transformed(cl->xform_cache, cl->rect_cache)) {
|
Rect2 temp_rect = cl->xform_cache.xform(cl->rect_cache);
|
||||||
|
|
||||||
|
if (clip_rect.intersects(temp_rect)) {
|
||||||
cl->filter_next_ptr = lights;
|
cl->filter_next_ptr = lights;
|
||||||
lights = cl;
|
lights = cl;
|
||||||
Transform2D scale;
|
Transform2D scale;
|
||||||
@@ -423,12 +425,13 @@ void RendererViewport::_draw_viewport(Viewport *p_viewport) {
|
|||||||
if (cl->use_shadow) {
|
if (cl->use_shadow) {
|
||||||
cl->shadows_next_ptr = lights_with_shadow;
|
cl->shadows_next_ptr = lights_with_shadow;
|
||||||
if (lights_with_shadow == nullptr) {
|
if (lights_with_shadow == nullptr) {
|
||||||
shadow_rect = cl->xform_cache.xform(cl->rect_cache);
|
shadow_rect = temp_rect;
|
||||||
} else {
|
} else {
|
||||||
shadow_rect = shadow_rect.merge(cl->xform_cache.xform(cl->rect_cache));
|
shadow_rect = shadow_rect.merge(temp_rect);
|
||||||
}
|
}
|
||||||
lights_with_shadow = cl;
|
lights_with_shadow = cl;
|
||||||
cl->radius_cache = cl->rect_cache.size.length();
|
cl->radius_cache = cl->rect_cache.size.length();
|
||||||
|
cl->rect_cache = temp_rect;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user