Brandon DeRosier 1cc55b8a1c [Impeller] Transform geometry to safe depth ranges instead of forcing discrete depth values. (flutter/engine#51673)
Resolves https://github.com/flutter/flutter/issues/144333. (Specifically, this [follow-up issue](https://github.com/flutter/flutter/issues/144333#issuecomment-2002399870))

When drawing objects with a perspective transform, the rasterizer applies perspective correction for interpolated vertex attributes. By absorbing W and replacing Z with a discrete value, we were essentially removing all perspective information and disabling perspective correction.

Instead, we can manipulate the Entity transform to remap the output Z range to fit within the small depth slices that each Entity is allotted.

The golden draws a clip sandwich:
1. Draw and restore a difference clip _before_ drawing the airplane image. This clip will get drawn to the depth buffer behind the airplane image.
2. Draw an oval clip that applies to the airplane image. This clip will get drawn in front of the airplane image on the depth buffer.
3. Draw the airplane image with a 3D rotation and perspective transform.
4. Draw a semi-translucent blue circle atop all previous draws.

Before:

https://github.com/flutter/engine/assets/919017/c2a7d012-714e-4234-83ac-61c792172f30

After:

https://github.com/flutter/engine/assets/919017/de3b78ff-00bf-4bc9-8821-8e86b9a9e6bf
2024-03-27 17:25:07 +00:00
..