From 13b7b2c3fc52bcd6c5e388c2d7ee6c5c236165c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 20 Jul 2022 20:03:13 +0000 Subject: [PATCH] don't cull ui nodes that have a rotation (#5389) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective - Fixes #5293 - UI nodes with a rotation that made the top left corner lower than the top right corner (z rotations greater than π/4) were culled ## Solution - Do not cull nodes with a rotation, but don't do proper culling in this case As a reminder, changing rotation and scale of UI nodes is not recommended as it won't impact layout. This is a quick fix but doesn't handle properly rotations and scale in clipping/culling. This would need a lot more work as mentioned here: https://github.com/bevyengine/bevy/blob/c2b332f98a0bcab7390e4b184099202cfb4fbbe1/crates/bevy_ui/src/render/mod.rs#L404-L405 --- crates/bevy_ui/src/render/mod.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index e26d91ae23ac4e..c336bbe0eaac51 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -435,11 +435,19 @@ pub fn prepare_uinodes( let transformed_rect_size = extracted_uinode.transform.transform_vector3(rect_size); - // Cull nodes that are completely clipped - if positions_diff[0].x - positions_diff[1].x >= transformed_rect_size.x - || positions_diff[1].y - positions_diff[2].y >= transformed_rect_size.y - { - continue; + // Don't try to cull nodes that have a rotation + // In a rotation around the Z-axis, this value is 0.0 for an angle of 0.0 or π + // In those two cases, the culling check can proceed normally as corners will be on + // horizontal / vertical lines + // For all other angles, bypass the culling check + // This does not properly handles all rotations on all axis + if extracted_uinode.transform.x_axis[1] == 0.0 { + // Cull nodes that are completely clipped + if positions_diff[0].x - positions_diff[1].x >= transformed_rect_size.x + || positions_diff[1].y - positions_diff[2].y >= transformed_rect_size.y + { + continue; + } } // Clip UVs (Note: y is reversed in UV space)